Skip to main content
Version: v2.0

Agent traces and usage

Every invocation can return trace context in headers, response fields, and stream events.

LocationValue
Headerx-ag-trace-id and x-ag-span-id
JSON responsetrace_id and span_id
Agenta streamdone.data.traceId
Vercel streamfinish.messageMetadata.traceId

Store trace_id with your application's session or job record. The session ID groups turns; the trace ID identifies one invocation.

Fetch a trace

curl \
"$AGENTA_HOST/api/traces/019d952f000000000000000000000003" \
-H "Authorization: ApiKey $AGENTA_API_KEY"

The response contains a nested span tree. Span names can repeat, so sibling values can be arrays. See Tracing for complete query and response schemas.

Agent spans

ag.type.spanWork recorded
workflowRoot invoke operation
agentHarness loop
llm, chat, completionModel request
toolTool execution

Inspect errors on the narrowest failed span before the root summary. Tool spans can distinguish a permission denial, client pause, remote integration error, and sandbox execution failure.

Usage

Streaming runs can emit a usage event with input, output, total, and cost. Vercel output places usage in finish.messageMetadata.usage. Provider reporting varies, so fields can be absent even when the run succeeds.

Use trace links when one workflow invokes another. A reference-tool child has its own execution context while preserving correlation to the parent.