Set TCC environment variables
.env.local
Instrument Pi
Use the SDK path when you create Pi sessions or event streams from your own TypeScript code. Use the Extension path when you run Pi from the command line.- SDK
- Extension
Step 1: Install dependencies
Step 2: Add instrumentation to your agent
Import theinstrumentPiSession function and call it with your Pi agent session. This subscribes to all agent events and automatically exports traces to The Context Company.agent.ts
Step 3: Instrument Pi event streams
If you’re working with Pi event streams directly instead of a session object, you can useinstrumentPiEventStream to wrap an AsyncIterable of events. This forwards each event through the telemetry listener and automatically exports traces to The Context Company.agent.ts
instrumentPiEventStream function accepts the same config options as instrumentPiSession, including metadata, sessionId, conversational, and debug.agent.ts
agent.ts
Adding custom metadata
Custom metadata allows you to add additional properties to your agent runs. This is particularly useful for tying agent runs to your own specific business logic, letting you filter and analyze agent runs by user, organization, feature, or some other dimension.- SDK
- Extension
Pass custom metadata and reserved
tcc.* metadata as key-value pairs to the metadata object in the config.agent.ts
The
tcc.* namespace is reserved. Only the reserved TCC metadata keys (tcc.runId, tcc.sessionId, tcc.conversational, tcc.agent, tcc.userId, tcc.userName, tcc.orgId, tcc.orgName) are recognized; any other tcc.* keys are ignored. None of them appear in your custom metadata.A Pi session can fire many runs, but metadata is captured once and reused for every run in that session. Do not put tcc.runId here. In SDK instrumentation, use instrumentation.setRunId(...) before each prompt to assign a per-run ID.Adding user feedback
User feedback allows you to collect score (thumbs up & thumbs down) and text feedback (up to 2000 characters) from end users on your agent runs. This is useful for tracking user satisfaction, identifying problematic responses, and filtering agent runs in the dashboard to focus on positive or negative feedback.Step 1: Generate and pass a run ID
UsesetRunId() on the instrumentation object to assign a unique run ID before each prompt. After the run completes, retrieve it with getLastRunId().
agent.ts
Programmatic feedback is only supported with SDK instrumentation. The Pi CLI extension can show the last completed run ID with
/tcc-status for debugging, but it does not provide a stable app-facing setRunId() flow for collecting feedback from users.Step 2: Submit feedback from your client
Store therunId on your client, then when the user provides feedback, submit it using the submitFeedback function.
Both score and text are optional individually, but each request must include at least one of them:
score is the thumbs rating. Use only "thumbs_up" or "thumbs_down".
text is written feedback from your user, up to 2000 characters.
feedback.ts
Tracking agent sessions
Agent sessions represent multiple agent runs that are grouped together. The most common use case is tracking entire conversations between a human user and an AI agent in chatbot interfaces. Agent sessions can be tracked by setting a session ID.- SDK
- Extension
agent.ts
sessionId should be a unique identifier for the agent session. This can be any string, but it’s generally recommended to use a UUID.
Agent sessions are automatically indexed and can be filtered directly in the dashboard.
Marking runs as conversational
A conversational run is an agent run that was initiated by a user. Marking a run as conversational tells The Context Company that this run involves direct user interaction. This is important because conversational runs are the only runs monitored for user insights, such as user confusion, frustration, or any other custom insights you want to track. Runs that are not marked as conversational (e.g. background jobs, cron tasks, or internal automations) are excluded from user insight analysis. Mark a run as conversational by settingtcc.conversational in extension metadata or conversational in SDK config.
- SDK
- Extension
agent.ts
The
conversational, sessionId, and runId options on instrumentPiSession are typed shortcuts for the reserved TCC metadata keys.Identifying the agent
If your product ships more than one named agent, set the reservedtcc.agent metadata key to scope the session to a specific agent. The dashboard’s top-level agent selector, per-agent patterns and recaps, and the agent filter on the REST API and MCP tools all read from this key.
- SDK
- Extension
agent.ts
Agent names that collide with reserved dashboard routes (for example
runs, sessions, patterns, recaps, overview, search, failures, feedback, tools, topics, views, settings, mcp-and-api) are dropped.Identifying users and organizations
Attach the end user and their organization to a Pi session as first-class identity using the reservedtcc.userId, tcc.userName, tcc.orgId, and tcc.orgName metadata keys. This is not the same as adding a userId field to custom metadata — these keys promote user and org identity to dedicated dashboard filters and unlock native user/org search, per-user views, and per-org analytics. See User and organization identity for the full concept.
Set these whenever you have a stable identifier for the end user or their organization in your product.
- SDK
- Extension
agent.ts
tcc.userName and tcc.orgName require the corresponding ID (tcc.userId / tcc.orgId) to also be set. Names without IDs are dropped.Cleanup
TheinstrumentPiSession function returns an object with an unsubscribe method you can call to stop listening for events. This is only needed for SDK instrumentation; the Pi CLI extension manages its own lifecycle.
agent.ts
Debug mode
You can enable debug mode, which will log any events that are captured and sent. For the Pi CLI extension, setTCC_DEBUG=true before starting Pi:
debug: true:
agent.ts
