On this page

For AI agents: a documentation index is available at /docs/llms.txt. Append .md to any page URL for markdown, or send Accept: text/markdown.

Set up Agent Analytics

Agent Analytics groups your agent's messages, tool calls, and responses into sessions tied to your users, then scores each session. Setup takes four steps: pick a project, decide your session and privacy strategy, instrument with one path, and verify. For defaults with no customization, complete the Agent Analytics quickstart instead. If you're still evaluating, Analyze agent results shows what Agent Analytics produces.

How setup works

  1. Pick the Amplitude project the data flows into, and get its project API key.
  2. Decide your session ID, user ID, and privacy mode. Refer to Before you instrument.
  3. Instrument your code with one path. Refer to Choose an instrumentation path.
  4. Check your events. Refer to Verify.

Each turn of an instrumented session produces an [Agent] User Message, one [Agent] Tool Call per tool invocation, and an [Agent] AI Response. When the work ends, your code sends [Agent] Session End. After the session closes, Amplitude adds an [Agent] Session Record with the session's enrichment results. The timeline below shows this sequence. Click any event to inspect its shape.

From the SDKreal-time during sessionFrom Amplitudepost-hoc enrichmentLOADTURN 1TURN 2ENDViewedPage(browser SDK)User MessageTool CallAI ResponseUser MessageTool CallAI Response···Session EndALSO EMITTED — INSIDE A TURNSpanSession RecordEvaluator Result × N
Event type
[Agent] AI Responsefrom the SDK
Fired at
22:33:48
Identity
[Agent] Session ID4ddcc6b2-1041-432a-aa8c-ebe3eccac40b
[Agent] Agent IDsupport-chatbot
[Agent] Trace IDb4f63d43-d752-4b1f-8489-d234ddf586b2
Event-specific
$llm_message.textI can help. Your subscription renews on Aug 15…
[Agent] Model Namegpt-4o-mini
[Agent] Provideropenai
[Agent] Input Tokens1245
[Agent] Output Tokens87
[Agent] Latency Ms3420
[Agent] Cost USD0.0012
Closes the turn. Carries the eight fields the SDK doctor checks at setup: Session ID, Agent ID, Model, Provider, Latency Ms, Input/Output Tokens, Cost USD. Emitted by s.trackAiMessage(...) or a provider wrapper.

Before you instrument

Decide these before you write code. Each one is hard to change after rollout.

Choose a privacy mode

Three modes control what leaves your infrastructure. full (the default) sends message content, metadata_only sends none, and customer_enriched sends none but runs enrichment on labels you provide. Every mode sends tokens, cost, latency, model names, and session grouping. For a full comparison and how to apply each mode on your path, refer to Agent Analytics privacy modes.

Choose an instrumentation path

Pick one path. Every path produces the same [Agent] events, so sessions, enrichment, and charts work the same way.

Connect with the SDK

Install the AI SDK for Node or Python, then let your AI coding agent instrument the app or wire it in by hand. Go to Instrument your agent with the AI SDK.

Send OpenTelemetry traces directly

Point your OTLP exporter or Collector at Amplitude's endpoint and set a conversation attribute on your spans. Go to Send OpenTelemetry traces to Agent Analytics.

Send agent events without the AI SDK

Emit [Agent] events with a standard Amplitude SDK or the HTTP API when the AI SDK doesn't fit your runtime. Go to Send agent events without the AI SDK.

Verify

Send one real interaction and check nine gates on its events in Live Events, then run the production checklist before rollout. Refer to Verify your Agent Analytics instrumentation. If something's missing, refer to Troubleshoot Agent Analytics setup.

Extend your setup

These steps are optional:

Was this helpful?