Skip to main content
Automatically capture agent runs, LLM calls, and tool invocations within the Pydantic AI framework via its native OpenTelemetry instrumentation.

Setup

import traceroot
from traceroot import Integration

traceroot.initialize(integrations=[Integration.PYDANTIC_AI])

Usage

Once initialized, all Pydantic AI agent runs and tool invocations are captured automatically:
import traceroot
from traceroot import Integration
from pydantic_ai import Agent

traceroot.initialize(integrations=[Integration.PYDANTIC_AI])

agent = Agent(
    "openai:gpt-4o-mini",
    system_prompt="You are a helpful assistant.",
)

result = agent.run_sync("What is the capital of France?")
print(result.output)

traceroot.flush()

What Gets Captured

AttributeDescription
Agent runsEach agent.run() / agent.run_sync() / agent.run_stream() invocation
Tool callsEach tool invocation with input arguments and results
LLM callsRaw completion requests with input messages, output messages, and model name
Tokens & CostInput and output token counts per LLM call; cost calculated from model pricing
Cache tokensCache read and write token counts when reported by the provider
LatencyDuration per agent run and per span

Run the example

Clone the repo and run a complete agent end-to-end.

Python

Run the Python example