@earendil-works/pi-coding-agent) is a TypeScript SDK for running pi coding agents programmatically. Braintrust traces AgentSession.prompt() calls, Anthropic LLM calls, and tool invocations.
This page documents the
@earendil-works/pi-coding-agent SDK. To trace interactive pi sessions with the Braintrust pi extension instead, see pi.Setup
Install Braintrust alongside the Pi Coding Agent SDK, then set your API keys. Requires@earendil-works/pi-coding-agent v0.79.0 or later.1
Install packages
2
Set environment variables
.env
Auto-instrumentation
To trace Pi Coding Agent SDK runs without wrapping the SDK module yourself, initialize Braintrust normally, then run your app with Braintrust’s import hook to patch the SDK at runtime.1
Initialize Braintrust and run a prompt
2
Run with the import hook
node --import can run the file directly. The Braintrust APIs work the same in TypeScript projects. Compile your TypeScript to JavaScript and run the compiled file with the import hook, or run TypeScript directly with a TypeScript loader.If you’re using a bundler, see Trace LLM calls for plugin and loader setup.
@braintrust/auto-instrumentations, keep the Pi Coding Agent integration enabled.Manual instrumentation
To trace the Pi Coding Agent SDK manually, wrap the imported module yourself withwrapPiCodingAgentSDK() before creating sessions.What Braintrust traces
Braintrust patchesAgentSession.prompt() and captures:- Task spans for each
AgentSession.prompt()call. - LLM spans nested under the prompt span, including input messages with the system prompt and later system prompt updates, declared tool schemas in
toolsmetadata, model metadata, stop reasons, and token metrics. Token metrics appear only on LLM spans, so trace totals count each provider call once. - Tool spans for tool invocations, including
bashcalls, tool names, inputs, outputs, and tool call IDs. A tool span recordsmetadata.tool_approvalasapprovedwhen the tool runs, so you can filter for tools that were allowed to run. Spans that your code creates while a tool runs nest under that tool’s span. - Pi Coding Agent metadata under keys such as
pi_coding_agent.operation,pi_coding_agent.api,pi_coding_agent.model,pi_coding_agent.source,pi_coding_agent.stop_reason, andpi_coding_agent.tool.name. - OpenTelemetry GenAI tool metadata, including
gen_ai.tool.nameandgen_ai.tool.call.id. - Errors captured on task, LLM, and tool spans.