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.7.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.7.0
File Size Uploaded Provenance Actions
trace_agent_pydantic_ai-0.7.0.tar.gz 17.7 kB Without provenance Details for trace_agent_pydantic_ai-0.7.0.tar.gz

Built distribution (wheel)

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

Total release size: 26.6 kB

Release files / trace_agent_pydantic_ai-0.7.0.tar.gz

Download URL trace_agent_pydantic_ai-0.7.0.tar.gz
Size 17.7 kB
Tags Source
SHA-256 checksum
How to use checksums
8a00b486cdfce81a9aca1612c1ce7a6b4819812c61adb415d32d4fc2b17ccb23
BLAKE2b-256 checksum
How to use checksums
3638077253ea11331023d3b869e7a2e592f22f4c82608ecfd95b28b55c7593af
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.7.0-py3-none-any.whl

Download URL trace_agent_pydantic_ai-0.7.0-py3-none-any.whl
Size 8.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c8241af549f2f4cfafdec172ae6bad2dabf83695dedf15bd2add4a4a6ab94be5
BLAKE2b-256 checksum
How to use checksums
7c7f8cf8a9a33722c67a45228be43ec3c02ed2b39aa8493ff41109c9c13a881d
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.7.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