createOtelExtension integration, which conforms to the GenAI semantic conventions. This page shows you how to enable Weave tracing in a Pi application so you can observe agent behavior, debug runs, and analyze token usage and cost.
Prerequisites
Pi is a TypeScript and Node.js framework with no Python equivalent. Pi requires the ESM module system. Your project must use
"type": "module" in package.json, or compile TypeScript to ESM output. CommonJS projects error. For more information about setting up an ESM project, see TypeScript SDK integration.Install packages
Install Weave, Pi, and Node type definitions as local project dependencies:Trace a Pi prompt and response
The following example shows the minimum setup needed to trace a single Pi prompt and response. Callweave.init() before you create your agent session, then pass createOtelExtension() as an extension factory. Weave traces the full agent lifecycle: the conversation, each prompt-and-response cycle (invoke_agent), individual LLM calls (chat), and tool executions (execute_tool). SessionManager.inMemory() generates the session ID automatically.
tsx, replacing [FILENAME] with the name of your TypeScript file:
https://wandb.ai/[YOUR-TEAM]/[YOUR-PROJECT]/weave/agents. Weave captures Pi sessions, LLM calls, and tool executions for every run of your application.
Next steps
To turn this example into a multi-turn conversation, add more prompts. Weave traces each call tosession.prompt() as a separate invoke_agent span, all nested under a single root span. The agent retains context across prompts automatically.
After running the code, the Agents tab shows the full multi-turn timeline with nested LLM calls, tool executions, token usage, and cost.