Choose a setup method
Start with one method for a call path. Combining SDK tracking with framework
OpenTelemetry on the same call can create duplicate interactions.
Recommended: Agnost AI skill
Recommended. Choose this path when you want your coding agent to inspect the
project, select a supported transport, make the smallest instrumentation change,
send a test event, and verify that it reached Agnost AI.
Manual setup: Agnost AI SDK
Wrap eachnetwork.run() call with begin() / end(). Use AgentKit’s threadId as the conversation ID so every turn of a chat lands in one conversation.
network.run() returns a NetworkRun. Its state.results holds one AgentResult per agent call, and finalText() reads the last assistant message from them. The SDK records one event per turn. To also record each tool call as its own event, use the OpenTelemetry setup below.
Call await agnost.shutdown() once when the application exits, not after each request.
Manual setup: OpenTelemetry
AgentKit doesn’t emit OpenTelemetry spans of its own, and its model calls go throughfetch, so provider instrumentations don’t see them. Add two small spans instead: one around network.run() for the turn, and one around each tool handler. They use the OpenTelemetry GenAI attributes that Agnost AI reads.
Install
Already have an OTel SDK and the OTLP exporter installed? Skip. No OTel yet?Setup
1. Export spans to Agnost AI
Already have aNodeSDK or tracer provider? OpenTelemetry JS 2.x can’t add processors after construction. Add this exporter to your existing spanProcessors (inside a BatchSpanProcessor) where the provider is created.
No OTel yet? Load this file before anything else in your app:
2. Add the span helpers
3. Use them in your network
Wrap each tool handler intraceTool(), and call the network through runNetwork():
invoke_agent span with the user’s message in input.value and the reply in output.value. gen_ai.conversation.id groups turns by threadId, and enduser.id sets the user. The turn span starts a new trace, so it is a top-level event even when a web framework or Inngest already has a span open. Tool spans run inside the turn span, so each tool call appears under its turn.
4. Inside an Inngest function
The same helpers work when the network runs inside an Inngest function. Loadinstrumentation.ts in the process that serves your functions:
traceTool() tags it with the threadId so it stays in the right conversation. To run a tool once, put its work inside step.run() as the AgentKit multi-step tools guide shows.
What appears in Agnost AI
- Conversations grouped by
threadId. - User-level analytics grouped by the
userIdyou pass torunNetwork(). - Events for each turn (input and reply) and each traced tool call (arguments and result).
Verify
Send one message that makes the agent call a tool, then a second message with the samethreadId. Open Conversations in Agnost AI. Confirm both turns are in one conversation with your user ID, each turn shows the message and the reply, and the tool event sits under the first turn with its arguments and result.
Troubleshooting
- Nothing arrives: import
instrumentation.tsbefore AgentKit, and confirmAGNOST_ORG_IDis set in that process. Short scripts mustawait otel.shutdown()before exiting so the last batch is sent. - Each turn is its own conversation: pass the same
threadIdtorunNetwork()on every turn. - Tool calls missing: wrap every
createToolhandler intraceTool(). MCP tools aren’t covered by the wrapper. - Tool calls appear as separate conversations: call the network through
runNetwork(), so tool spans run inside the turn span. - Empty reply: if the network stops after a tool call, the last result has no text. Route back to the agent after tool calls, as the router above does.
References
- AgentKit networks
- AgentKit routers
- AgentKit tools
- AgentKit createState
- OpenTelemetry GenAI spans
- Agnost AI OpenTelemetry endpoint
Next steps
- Conversations: review each AgentKit thread turn by turn.
- Events: inspect turns and tool calls.
- Patterns: organize production conversations by what users wanted.