Using legacy
@mariozechner/pi-ai? Use the
PI AI integration.@earendil-works/pi-agent-core and @earendil-works/pi-ai. Each Pi Models
collection owns its providers. Pass that collection to Catalyst so each model
turn emits an OpenInference LLM span.
This guide is tested with @earendil-works/[email protected] and
@earendil-works/[email protected].
Pi Agent is available for TypeScript. There is no Python equivalent for this
integration.
What Is Captured
- One LLM span per model turn, named like
pi-agent.<provider>.turn - Calls through
stream,streamSimple,complete, andcompleteSimple - System prompts, input messages, assistant output, model name, and provider
- Tool call IDs, names, and JSON arguments from assistant messages
- Token usage, prompt cache read/write counts, finish reason, and total cost
- Errors, aborts, and exception details
- Active
agentSpan()identity, includingagent.id,agent.name,agent.role, andsession.id
Install
TypeScript
Configure Export
Set the Catalyst endpoint and token before your app starts. Generate a token at API Keys.Initialize Tracing
Create the PiModels collection before tracing setup. Pass the collection as
piAgent. You can add providers before or after setup.
TypeScript
TypeScript
Run An Agent
Passmodels.streamSimple.bind(models) to the current Pi Agent. Wrap the run
in agentSpan() to group all model turns under one stable agent identity.
The following example uses an Anthropic model. It assumes you ran the setup
block above.
TypeScript
pi-support-agent.runAGENT span- One or more
pi-agent.anthropic.turnLLM child spans
Trace Tool Execution
Pi returns model tool calls in assistant messages and executesAgentTool
functions locally. Catalyst records the requested tool name, ID, and arguments
on the LLM span. Wrap local execution with manualSpan() when you also want a
TOOL span for the work.
TypeScript
lookupOrder to initialState.tools. A tool round trip then produces:
- A
pi-agent.<provider>.turnLLM span with the requested tool call - A
lookup_orderTOOL span for local execution - Another
pi-agent.<provider>.turnLLM span for the final answer
Verify In Catalyst
Filter traces by yourservice.name, for example pi-agent. A successful run
shows the AGENT span with nested Pi Agent LLM spans. Each LLM span includes
input/output, model metadata, usage, finish reason, and tool call attributes.
If no Pi Agent spans appear:
- Pass the
Modelscollection asmodules: { piAgent: models }. - Instrument the collection before the agent makes its first model call.
- Add providers through the instrumented collection’s
setProvider()method. - Consume streaming results or await
agent.prompt()before shutdown. - Call
await tracing.shutdown()before a short-lived process exits.