Skip to main content

Agent Observability

Observability is what turns opaque, stochastic agent behavior into a well-lit engineering system. An AI agent is not a deterministic API endpoint. It reasons over ambiguous instructions, selects and invokes tools, updates internal memory, and may coordinate with other agents across network boundaries. A single user request can fan out into dozens of LLM calls, tool executions, and state mutations. When something goes wrong—a hallucination, a planning loop, a tool returning unexpected data—you cannot simply check a return code. You must reconstruct the entire causal chain.

Traditional application monitoring is insufficient because it focuses on infrastructure health (CPU, memory, error rates) and treats the application as a black box. Agent observability requires deep instrumentation of the reasoning process: what the model saw, what it decided, what tools it called, what each tool returned, and how the final answer was assembled. This article establishes the pillars, telemetry signals, and production architecture needed to achieve true observability for AI agent systems.

What Is Agent Observability?

Observability is a property of a system that allows you to understand its internal state from its external outputs. In practice, it is the combination of logs, metrics, and traces—the three pillars—that together enable you to ask arbitrary questions about system behavior without having to ship new code.

Monitoring vs. Logging vs. Tracing vs. Metrics vs. Observability

DisciplineDefinitionPurpose
LoggingTimestamped, structured records of discrete eventsDebugging specific events, audit trails
MetricsNumerical time-series data (gauges, counters, histograms)Aggregated health checks, SLOs, trend analysis
TracingDistributed, parent-child relationships between requests and their sub-operationsUnderstanding causal chains, latency attribution
MonitoringCollection, aggregation, and alerting on known failure modesDetecting when something is wrong
ObservabilityThe emergent capability from integrating logs, metrics, and tracesExplaining why something is wrong

Monitoring tells you something failed. Observability explains why.

In an agent system, monitoring might alert that task success rate has dropped below 95%. Observability lets you drill into a specific failing trace, see that the planner chose an incorrect tool because the tool description in the prompt was outdated, and discover that the retriever returned an empty result set due to a stale embedding cache.

Pillars of Agent Observability

Logs

Agent logs must capture the full lifecycle of every request in a structured, machine-readable format (JSON). Essential log events include:

  • Prompts – The rendered system and user prompts sent to each LLM call, including the tool schemas injected.
  • Responses – The raw and parsed output from the model, including finish reason.
  • Tool calls – The tool name, arguments, response, status code, and duration.
  • Errors – Full stack traces, HTTP status codes, and model error codes.
  • Retries – Each retry attempt with backoff duration and reason.
  • Model selection – Which model was routed to and why (classification decision, fallback).

Best practices:

  • Use correlation IDs (trace ID, span ID) in every log line.
  • Avoid logging raw user data or PII; mask sensitive fields before emission.
  • Maintain a consistent schema across services to enable cross-component queries.

Metrics

Metrics provide aggregated signals for dashboards and alerting. Key metrics for agent systems:

Metric CategoryMetric NameDescription
LatencyEnd-to-end response timeWall-clock time from user request to final response
Time to first tokenStreaming responsiveness
Reasoning durationTime spent in planning/reflection before acting
ThroughputRequests per minuteLoad on the agent service
Tokens per minuteRate of token consumption
SuccessTask success ratePercentage of requests achieving user goal
Tool call success ratePercentage of tool invocations returning valid result
ResourceToken usageTotal prompt + completion tokens per request
CostMonetary cost per request, per user, per day
ReliabilityRetry countNumber of tool/LLM retries before success or failure
Tool failuresCount of tool errors by type

These metrics should be tagged with dimensions like model version, prompt version, agent ID, and tenant.

Traces

Tracing is the backbone of agent observability. A single user request creates a root span, which then spawns child spans for each sub-operation: planning, tool invocation, memory retrieval, response generation. Spans carry attributes (model name, token count, tool name, status) and events (exception, retry).

The causal relationship between spans allows you to answer questions like: “Why did the agent call the search tool three times?” or “Which tool call added 8 seconds to this request?”

Agent Execution Trace

A realistic execution trace exposes the nested, asynchronous nature of agent work.

StepComponentSpan IDParent SpanDuration (ms)Attributes
1Orchestratorroot-2300request_id, user_id
2Plannersp1root150plan_steps=3
3Retrieversp2root200docs_retrieved=5
4LLM (reasoning)sp3root800model=gpt-4o, tokens=1200
5Tool: searchsp4root600tool=web_search, result_count=10
6LLM (synthesis)sp5root400model=gpt-4o, tokens=800
7Evaluatorsp6root100score=0.95

Parent-child relationships create a directed acyclic graph. Asynchronous execution means spans may overlap; the trace context ensures they are still correctly attributed to the root request.

LLM-Specific Telemetry

Each LLM call must emit a rich set of attributes to make cost, quality, and behavior transparent.

AttributeTypeDescription
modelstringModel ID (e.g., gpt-4o, claude-3.5-sonnet)
providerstringAPI provider (OpenAI, Anthropic, Azure)
prompt_template_idstringVersioned identifier for the prompt template
temperaturefloatSampling temperature
top_pfloatNucleus sampling parameter
max_tokensintMaximum completion tokens set
input_tokensintNumber of prompt tokens (including cache hits)
output_tokensintNumber of completion tokens
reasoning_tokensintTokens consumed by internal reasoning (e.g., o1 models)
cache_read_tokensintTokens fetched from prompt cache
costfloatMonetary cost calculated from token counts and model pricing
latency_msintTime from request to completion (or to first token)
finish_reasonstringstop, length, tool_calls, content_filter
confidencefloatModel-provided log-probability or external scorer (optional)
hallucination_indicatorsarrayIndicators like output-faithfulness, contradiction signals
safety_filtersarrayBlocked categories or content moderation flags
tool_calls_requestedarrayList of tool names and arguments generated

This telemetry enables cost attribution, quality monitoring, and automated evaluation.

Tool Call Observability

Tool execution must be instrumented as thoroughly as LLM calls. A tool call span typically contains:

  • Tool name and version
  • Arguments (masked if containing PII)
  • Execution duration
  • HTTP status code (for API-based tools)
  • Response size and structure
  • Error code and message if failed
  • Retry attempts with backoff details
  • Fallback triggered (boolean)
  • Response quality – could be a simple success flag or a confidence score

A typical tool call lifecycle:

[Agent decides to call tool]
-> Tool Call Span (parent: agent reasoning span)
-> Argument validation sub-span
-> API/Function execution sub-span
-> Retry sub-span (if needed)
-> Response parsing sub-span
-> Tool Call Span ends with status and metadata

Observing this lifecycle reveals whether failures are due to bad arguments (planning error), external API outages, timeout misconfigurations, or malformed responses.

Memory Observability

Agent memory is often a black box—a collection of vector embeddings, summaries, or key-value stores that evolves over time. Observability into memory answers:

  • What memories were retrieved for this request?
  • Why were these memories selected (similarity score, recency)?
  • When were memories created or updated?
  • Are there conflicting or outdated memories?
  • How fresh is the knowledge (timestamp of ingestion)?

Key attributes to track per memory operation:

  • memory_type (short-term chat history, long-term vector store, entity store)
  • operation (read, write, update, delete, expire)
  • retrieved_count and top_k
  • similarity_scores for each retrieved item
  • latency_ms of the retrieval call
  • memory_id and knowledge_source

Debugging memory issues—like the agent citing outdated company policy or forgetting user preferences—requires the ability to replay a request with the memory state at that point in time. Memory observability also helps detect “memory poisoning” where incorrect facts get repeatedly stored and reinforced.

Multi-Agent Observability

When multiple agents collaborate, observability must extend across agent boundaries. A root trace may start in the Orchestrator and branch into sub-traces for specialist agents, each of which may call tools, update memory, and invoke further sub-agents.

Key considerations for multi-agent observability:

  • Handoffs: clearly mark boundaries where control passes from one agent to another.
  • Parallel execution: overlapping spans may belong to the same parent trace.
  • Coordination: capture the protocol used (A2A, custom events) and payload size.
  • Aggregation: the root trace must collect final status from all sub-agents.

Without this cross-agent tracing, debugging a multi-agent failure becomes guesswork.

OpenTelemetry for AI Agents

OpenTelemetry (OTel) is the industry-standard framework for generating, collecting, and exporting telemetry data. It provides SDKs for most languages and a specification for spans, metrics, and logs.

Core Concepts for AI Agents

  • Span: A unit of work (e.g., a single LLM call, a tool execution).
  • Trace: A tree of spans representing one end-to-end request.
  • Trace ID: Globally unique identifier propagated across all services.
  • Context Propagation: Passing trace ID and span ID via HTTP headers (W3C TraceContext) or message queues.
  • Attributes: Key-value pairs attached to spans (model name, token count, tool name).
  • Events: Time-stamped annotations within a span (exception, cache hit).
  • Metrics: Counters and histograms exported via OTLP.

AI Extensions

The OpenTelemetry community has been developing semantic conventions for LLM and GenAI workloads. These conventions standardize attribute names like gen_ai.system, gen_ai.request.model, gen_ai.usage.input_tokens, and gen_ai.response.finish_reason. Adopting these ensures that tracing backends (Jaeger, Grafana, Datadog) can interpret AI telemetry uniformly.

Architecture

Agent Service (OTel SDK)

OTel Collector (process, filter, batch)

Exporters: OTLP → Jaeger | Prometheus | Loki

Agents should be instrumented with the OTel SDK, either manually or via auto-instrumentation libraries that wrap LLM clients (e.g., openinference-instrumentation-openai). The collector can enrich spans (adding cost attributes) and redact PII before export.

AI Observability Platforms

A comparison of platforms that specialize in AI agent observability:

PlatformTracingPrompt LoggingEvaluationDatasetsSelf-HostedOpen SourceProduction ReadyEnterprise
LangSmithYesYesYesYesNoNoYesYes
LangfuseYesYesYesYesYesYesYesYes
Arize PhoenixYesYesYesYesYesYesYesYes
OpenLLMetryYesLimitedNoNoYesYesPrototypeNo
Arize AIYesYesYesYesNoNoYesYes
HeliconeYesYesNoNoNoYes (part)YesYes
Weights & BiasesYesYesYesYesNoNoYesYes
MLflowLimitedLimitedNoNoYesYesYesNo
  • Choose LangSmith if you are deep in the LangChain ecosystem and want a tightly integrated evaluation and annotation workflow.
  • Choose Langfuse for an open-source, self-hostable solution with excellent LLM cost tracking and prompt management.
  • Choose Arize Phoenix if you need open-source, OpenTelemetry-native tracing with strong embedding drift analysis.
  • Choose Helicone for an API-level gateway that adds observability without code changes, plus caching and rate limiting.
  • Choose W&B if your team is research-heavy and wants experiment tracking alongside prompt regression testing.

In many production stacks, a combination is used: OTel-based tracing to a platform like Phoenix for infrastructure teams, and Langfuse for LLM-specific prompt and evaluation dashboards.

Dashboards for Production

A well-designed observability stack surfaces the right information to the right team.

Latency Dashboard

  • P50/P95/P99 end-to-end latency over time
  • Latency breakdown by component (planning, retrieval, LLM, tool execution)
  • Time-to-first-token histogram

Cost Dashboard

  • Cost per request (average, max)
  • Daily/weekly/monthly spend by model and by agent
  • Token consumption trend (input vs output)
  • Cache hit rate and estimated savings

Quality Dashboard

  • Task success rate (from human feedback or LLM-as-Judge)
  • Tool success rate per tool
  • Hallucination rate trend
  • User satisfaction score

Operational Dashboard

  • Request throughput
  • Error rate by status code (4xx, 5xx) and by provider
  • Queue length (if using async processing)
  • Retry rate and retry success rate

Model Performance

  • Side-by-side latency and cost per model version
  • Prompt template version performance

All dashboards should allow filtering by time range, agent version, model, and tenant.

Detecting AI Failures

Observability exposes the subtle failures that traditional monitoring misses.

Failure ModeObservable Signal
HallucinationsLLM output fidelity score drop, tool returning “no results” but agent claims data
Infinite loopsSpan depth grows monotonically, no tool calls with side effects, latency exceeds max
Repeated reasoningIdentical LLM span attributes (prompt hash) repeated N times
Tool failuresTool span status = error, retry count spike
Context overflowinput_tokens near model limit, summary events fired
Prompt injectionSafety filter flagged, tool called with suspicious args
Latency spikesP95 latency > SLO, break down by component to isolate
Memory corruptionRetrieved memories with low similarity scores, mismatched entities
Runaway costsToken per request trend spike, cost alert triggered
Model degradationDrift in output token length, confidence drop, success rate decline

Observability enables you to move from “the agent seems dumber today” to “the latest prompt version increased planning verbosity by 40%, causing a token cost spike and a 5% increase in timeouts due to context overflow.”

Debugging AI Agents

A systematic debugging workflow using observability data:

  1. User Report: “Agent gave wrong answer and took 20 seconds.”
  2. Find Trace: Search by user ID, timestamp, or correlation ID to locate the exact trace.
  3. Inspect Prompt: Examine the rendered system and user prompts. Was the instruction ambiguous? Were tool descriptions stale?
  4. Inspect Retrieval: Check what context was fetched from the vector store. Were the documents relevant and up to date?
  5. Inspect Tool Calls: Review each tool call—arguments, response, status. Did a tool return an empty list unexpectedly? Did an API time out after 10 seconds?
  6. Inspect Memory: Look at the conversation history and long-term memory. Did the agent forget a critical user instruction given earlier?
  7. Replay Execution: Use a testing framework (like LangSmith datasets) to replay the exact prompt and tool responses to see if the behavior is reproducible.
  8. Root Cause: Correlate findings. Perhaps the retriever returned a deprecated policy document, the LLM faithfully followed it, and the tool that checked policy compliance was never invoked because it wasn’t in the prompt. Root cause: stale documents in vector DB and incomplete tool description.

This workflow turns a vague bug report into a precise engineering fix.

Best Practices

  • Structured logging: Emit JSON logs with a consistent schema across all agent services.
  • Correlation IDs: Pass a trace-id through every service, queue, and tool call; inject it into logs.
  • Adopt OpenTelemetry: Use the OTel SDK and standard semantic conventions to avoid vendor lock-in.
  • Centralized tracing backend: Aggregate spans from all services into a single queryable store.
  • Prompt versioning: Tag every LLM span with a unique prompt template ID. This makes regression attribution trivial.
  • Model version tracking: Include model ID and provider in spans; compare performance across model upgrades.
  • Sampling: For high-throughput agents, use probabilistic sampling (e.g., 10% of traces) to control telemetry cost, but always sample traces with errors.
  • Sensitive data masking: Implement a processor in your OTel collector to redact PII, API keys, and secrets from attributes before storage.
  • Cost monitoring: Enrich spans with cost data (using token counts × model pricing) and export as metric.
  • Replay support: Store raw prompts and tool responses so you can replay a failing request deterministically.
  • Evaluation integration: Feed production traces into your offline evaluation pipeline to continuously benchmark quality.
  • Continuous observability: Treat observability instrumentation as part of the agent’s Definition of Done; no PR merges without instrumentation.

Common Mistakes

  • Only collecting logs: Logs without traces make it impossible to understand causal chains.
  • Ignoring traces: Metrics tell you that latency is up; traces tell you which tool call is the bottleneck.
  • No prompt versioning: Without it, you cannot tell if a behavior change is due to a prompt update or a model change.
  • No token metrics: You cannot manage cost without token and spend telemetry.
  • No cost visibility: Engineering decisions become decoupled from financial impact.
  • No replay capability: You lose the ability to reproduce and fix production issues.
  • Missing correlation IDs: Traces from different services cannot be stitched together.
  • Logging secrets: Credentials and PII in logs create security and compliance risks.
  • Too much logging: Verbose, unstructured logs create noise and storage cost without aiding debugging.
  • Ignoring tool telemetry: Tool performance issues (slow third-party API, rate limiting) are often the root cause of agent latency and failures.

Production Architecture

A complete observability architecture for a multi-agent production system:

Telemetry flows from every component—agents, LLM proxies, tools, vector databases—into a collector, then to specialized backends. Dashboards provide a unified view, and alerting ensures timely response.