Skip to main content
AgentBasis supports Pydantic AI with built-in OpenTelemetry instrumentation.

Global Instrumentation

The easiest way to track Pydantic AI agents is to enable global instrumentation at the start of your application.
from agentbasis.frameworks.pydanticai import instrument
from pydantic_ai import Agent

# Enable global instrumentation
instrument()

# Your agents are now automatically traced
agent = Agent("openai:gpt-4")
result = agent.run_sync("Hello!")

Context-Aware Agents

If you need to associate traces with specific users or sessions, use the create_traced_agent helper or manually set context before running the agent.
from agentbasis.frameworks.pydanticai import create_traced_agent
import agentbasis

# Create an agent pre-configured with tracing
agent = create_traced_agent(
    "openai:gpt-4",
    system_prompt="You are a helpful assistant."
)

# Set user context - it will be included in traces
agentbasis.set_user("user-123")

result = agent.run_sync("Hello!")