Agent Tracing

Agent tracing records every step an AI agent takes (each LLM call, tool call, retrieval, and handoff) as a structured, nested trace with inputs, outputs, latency, and token usage. MLflow Tracing is an open-source way to do this. It captures agent runs automatically for popular agent frameworks with a single line of code, and supports manual instrumentation for custom agents.

An agent decides what to do next at run time, so the same request can take a different path every time. When an answer is wrong, the final output rarely shows why. A trace shows the whole run: which tools the agent picked, what each one returned, and which step went off track.

Last updated: November 26, 2026

In short: call mlflow.<framework>.autolog() once, run your agent, and open the trace in the MLflow UI. Every agent run appears as a tree of spans you can search, debug, and evaluate. MLflow is Apache 2.0 licensed, a Linux Foundation project, and you can self-host it.

MLflow trace view of a multi-step agent run: a chat_agent root span with LLM calls and tool calls such as search_traces and analyze_retrieval_quality, with latency, token counts, and cost per span

A multi-step agent trace in the MLflow UI (generated with mlflow demo): the span tree on the left, the selected span's inputs and outputs on the right.

Quick Navigation:

What Is Agent Tracing?

Agent tracing is the practice of capturing an AI agent's full execution as a trace: a tree of timed steps called spans. The root span is the agent run. Its children are the model calls, tool calls, retrievals, and sub-agent calls the agent made along the way, nested in the order they happened.

This is the main difference from plain LLM tracing. An LLM trace usually records one request and one response. An agent trace records a loop of reasoning and actions, where each model call decides the next tool call. Seeing that loop is what lets you debug it.

LLM call tracingAgent tracing
What is recordedOne prompt and one responseThe whole run: every model call, tool call, retrieval, and handoff
Shape of the traceUsually a single spanA tree of nested spans, with an agent span at the root
Typical questionWas this response good, and what did it cost?Why did the agent pick this tool, and where did the run go wrong?
Failures you can findBad prompt, slow model, high token useWrong tool choice, bad tool arguments, loops, redundant calls, lost context between steps

What Does an Agent Trace Capture?

Every span in an MLflow trace has a type, so the UI and the search API can tell a model call from a tool call. The span types that matter most for agents are:

Span typeWhat it represents in an agent
AGENTAn agent run or a sub-agent, usually the root of the trace
LLM / CHAT_MODELA call to a language model, with prompt, response, and token usage
TOOLA tool or function the agent called, with its arguments and result
RETRIEVERA search over a vector store or knowledge base
CHAINA step that wires other steps together
GUARDRAILA safety or policy check on an input or output

On each span MLflow records the inputs and outputs, start time and duration, status and any exception, and custom attributes. For model calls it also records token counts, and the UI shows the cost estimate for each call and for the whole trace. Traces can also carry tags, user and session IDs, and human or automated feedback attached to the trace or to a single span.

How Do You Trace an Agent in One Line?

For supported frameworks, you enable tracing by calling that framework's autolog() function before you run the agent. This example uses LangGraph, but every framework in the next section works the same way.

python
import mlflow
mlflow.set_tracking_uri("http://localhost:5000")
mlflow.set_experiment("my-agent")
# One line: every graph step, model call, and tool call becomes a span
mlflow.langchain.autolog()
# Run your compiled LangGraph agent as usual
result = agent.invoke(
{"messages": [{"role": "user", "content": "What's the weather in San Francisco?"}]}
)

Start a local MLflow server with mlflow server, run the script, and open the experiment's Traces tab. Each run shows up as a trace you can expand span by span. The tracing quickstart walks through the full setup.

Which Agent Frameworks Does MLflow Trace?

MLflow has one-line autologging for the ten agent frameworks below, plus model SDKs such as OpenAI and Anthropic. Each framework has a dedicated integration:

FrameworkEnable tracingGuide
LangGraphmlflow.langchain.autolog()LangGraph tracing
OpenAI Agents SDKmlflow.openai.autolog()OpenAI Agents tracing
CrewAImlflow.crewai.autolog()CrewAI tracing
AutoGenmlflow.autogen.autolog()AutoGen tracing
AG2mlflow.ag2.autolog()AG2 tracing
Pydantic AImlflow.pydantic_ai.autolog()Pydantic AI tracing
Strands Agentsmlflow.strands.autolog()Strands tracing
smolagentsmlflow.smolagents.autolog()smolagents tracing
Agnomlflow.agno.autolog()Agno tracing
Claude Agent SDK (Python)mlflow.anthropic.autolog()Claude Agent SDK tracing

Frameworks without a dedicated integration, and agents written in other languages, can send traces through OpenTelemetry. The full integrations list also covers model SDKs such as OpenAI, Anthropic, Gemini, and Bedrock, which appear as LLM spans inside an agent trace.

How Do You Trace a Custom Agent?

If you wrote your own agent loop, add the @mlflow.trace decorator to the functions you care about and set a span type. Calls made inside a traced function are nested under it automatically. For a block of code that is not its own function, use mlflow.start_span.

python
import mlflow
from mlflow.entities import SpanType
@mlflow.trace(span_type=SpanType.TOOL)
def search_docs(query: str) -> list[str]:
return vector_store.search(query) # your retrieval code
@mlflow.trace(span_type=SpanType.AGENT)
def run_agent(question: str) -> str:
docs = search_docs(question)
with mlflow.start_span(name="draft_answer", span_type=SpanType.LLM) as span:
span.set_inputs({"question": question, "docs": docs})
answer = call_llm(question, docs) # your model call
span.set_outputs({"answer": answer})
return answer

You can mix both styles. Turn on autologging for the model SDK or framework you use, and decorate your own tools and orchestration code, so the trace shows the full run in one tree. See the manual tracing guide for more options.

How Do You Trace Multi-Agent Systems and Sessions?

A sub-agent run is recorded as child spans of the agent that called it, so one trace shows the whole multi-agent system. In a multi-agent system, a supervisor agent calls other agents as tools or hands work off to them. Because spans nest, a sub-agent run appears as a child of the agent that called it, so you can see who did what and where time and tokens went. When agents run in separate services, MLflow supports distributed tracing to stitch their spans into one trace.

Agents are often conversational. Attach a user ID and a session ID to each trace and MLflow groups the turns of one conversation, so you can follow a multi-turn session from the first message to the failure.

python
import mlflow
from mlflow.entities import SpanType
@mlflow.trace(span_type=SpanType.AGENT)
def chat(message: str, session_id: str, user_id: str) -> str:
mlflow.update_current_trace(session_id=session_id, user=user_id)
return agent_reply(message) # your agent logic

The user and session tracking guide covers the details. The session_id and user parameters need MLflow 3.11 or later; on older versions, set the mlflow.trace.session and mlflow.trace.user metadata keys instead.

How Do You Debug and Evaluate Agents with Traces?

Open a failing trace in the MLflow UI to step through its spans, search traces to find similar runs, and run scorers over traces to measure quality.

Once traces are in MLflow, three workflows build on them. First, you debug in the UI: open a bad run, step through the spans, and find the tool call with the wrong arguments or the model call that lost context. Second, you search: filter traces by status, span type, tags, or text to find the runs that matter. Third, you evaluate: run LLM judges and code-based scorers over the traces to measure quality, tool use, and efficiency, and track it over time as part of agent evaluation.

python
import mlflow
from mlflow.genai.scorers import ToolCallEfficiency
# Find runs that failed
failed = mlflow.search_traces(filter_string="trace.status = 'ERROR'", max_results=50)
# Score the tool-call trajectory of recent agent runs, no re-run needed
traces = mlflow.search_traces(max_results=100)
results = mlflow.genai.evaluate(data=traces, scorers=[ToolCallEfficiency()])

Scorers read the whole trace, so they can judge the trajectory (for example, redundant tool calls) and not only the final answer. The guide on evaluating traces shows the complete flow.

Does Agent Tracing Work in Production?

Yes, the same tracing code works in development and in production. For production services, install the lightweight mlflow-tracing package, which has a smaller footprint than the full MLflow install, and point it at a shared tracking server. Traces can be tagged with environment, version, and user information so you can slice production runs the way you slice any other telemetry. See tracing in production for deployment guidance, and LLM tracing for the broader picture.

Because MLflow is open source, you choose where traces live. You can self-host the tracking server, run it on a managed platform, and export or re-route data through OpenTelemetry. There are no per-trace fees from MLflow itself, and your agent data stays in infrastructure you control.

Frequently Asked Questions

Agent tracing records everything an AI agent does during a run as a structured trace: each LLM call, tool call, retrieval, and handoff to another agent, with inputs, outputs, timing, and token usage. The steps are nested as a tree of spans, so you can see the order of decisions the agent made and where a run went wrong. MLflow Tracing provides agent tracing as open source.

Related Resources