Skip to main content

TraceAgent Pydantic AI Integration

GitHub Release GitHub Stars GitHub License Tests Website

Pydantic AI capability that streams agent runs, model requests and tool calls into TraceAgent. Requires Pydantic AI 2.x.

Install

pip install trace-agent-pydantic-ai

Usage

from pydantic_ai import Agent
from trace_agent_sdk import TraceAgentClient

client = TraceAgentClient("http://localhost:8000")
run = client.start_run("my-agent", "Do something")

agent = Agent("openai:gpt-4o", capabilities=[run.as_pydantic_ai_capability()])
result = agent.run_sync("hello")

run.finish(result.output)

The capability never breaks or slows the agent. Events are delivered by a background thread; if the backend is unreachable or hangs, a one-line warning is printed, trace delivery pauses for a while, and the agent keeps running. Events produced while paused are dropped. The end of the outermost run waits a few seconds at most for pending events, so run.finish() is delivered after them.

Pydantic AI prints a startup banner suggesting Logfire while its own observability is off. It is unrelated to TraceAgent and can be silenced with PYDANTIC_AI_NO_BANNER=1.

Without any code: OpenTelemetry

Pydantic AI already emits OpenTelemetry spans, and the TraceAgent server can receive them, so an agent can be traced without this package at all: export its spans over OTLP to http://<server>/v1/traces. See the server README and examples/pydantic_ai_otel_agent.py.

Pick one route per agent. The capability above records more detail you control (redaction, node events) and works without OpenTelemetry; the OpenTelemetry route needs no change to the agent. Using both records the run twice.

Options

run.as_pydantic_ai_capability(...) accepts:

Option Default Description
record_model_events True Record each model request as an LLM call (tokens, model, requested tools)
record_tool_events True Record each tool execution (args, output summary, duration, errors)
record_node_events False Record every agent graph node
redact_fields [] Argument / output keys replaced with [redacted]
failure_cooldown 30.0 Seconds to stop sending (and drop events) after a failed delivery. 0 retries every event
flush_timeout 5.0 Maximum seconds the end of the outermost run waits for pending events

License

MIT

Metadata

Release files for trace-agent-pydantic-ai 0.8.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for trace-agent-pydantic-ai 0.8.0
File Size Uploaded Provenance Actions
trace_agent_pydantic_ai-0.8.0.tar.gz 18.1 kB Without provenance Details for trace_agent_pydantic_ai-0.8.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for trace-agent-pydantic-ai 0.8.0
File Interpreter ABI Platform Actions
trace_agent_pydantic_ai-0.8.0-py3-none-any.whl Python 3 none any Details for trace_agent_pydantic_ai-0.8.0-py3-none-any.whl

Total release size: 27.0 kB

Release files / trace_agent_pydantic_ai-0.8.0.tar.gz

Download URL trace_agent_pydantic_ai-0.8.0.tar.gz
Size 18.1 kB
Tags Source
SHA-256 checksum
How to use checksums
200e613f3c4eb2020663c2590d77595d1a912a37a8287786cf327bc0b9db1ebd
BLAKE2b-256 checksum
How to use checksums
cee23b0d85bd7c3d7236d7f8a829db413fe81e145de4dcd4891738faca377185
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / trace_agent_pydantic_ai-0.8.0-py3-none-any.whl

Download URL trace_agent_pydantic_ai-0.8.0-py3-none-any.whl
Size 8.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f6e44d3be44a6a25a200a8e968be2b8ac1465bc8575c70717662c354afaf0a6a
BLAKE2b-256 checksum
How to use checksums
6b324c150fc41f7220fd608b2e3eb83ab674af5d4d1eb9aa9e59d657f5b287c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for trace-agent-pydantic-ai 0.8.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page