Skip to main content

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. 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.
Install the skill once in your coding-agent environment:
Run the framework-specific prompt below from the application root. Review the resulting diff before deploying it.

Manual setup: Agnost AI SDK

Wrap each network.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 through fetch, 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 a NodeSDK 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 in traceTool(), and call the network through runNetwork():
Each turn becomes an 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. Load instrumentation.ts in the process that serves your functions:
Inngest runs the function handler again after each step, and AgentKit makes each model call a step. Only the final pass finishes the turn span, so each turn is recorded once, but its latency covers only that final pass. AgentKit calls tool handlers outside steps, so a tool can run again on a later pass. Each run is recorded, and 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 userId you pass to runNetwork().
  • 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 same threadId. 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.ts before AgentKit, and confirm AGNOST_ORG_ID is set in that process. Short scripts must await otel.shutdown() before exiting so the last batch is sent.
  • Each turn is its own conversation: pass the same threadId to runNetwork() on every turn.
  • Tool calls missing: wrap every createTool handler in traceTool(). 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

Next steps

  • Conversations: review each AgentKit thread turn by turn.
  • Events: inspect turns and tool calls.
  • Patterns: organize production conversations by what users wanted.