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.3.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.3.0
File Size Uploaded Provenance Actions
trace_agent_pydantic_ai-0.3.0.tar.gz 14.3 kB Without provenance Details for trace_agent_pydantic_ai-0.3.0.tar.gz

Built distribution (wheel)

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

Total release size: 21.3 kB

Release files / trace_agent_pydantic_ai-0.3.0.tar.gz

Download URL trace_agent_pydantic_ai-0.3.0.tar.gz
Size 14.3 kB
Tags Source
SHA-256 checksum
How to use checksums
5f53a9c746b36e6585251e016db658e494b0a5512e84ef979d62d8e231ee40de
BLAKE2b-256 checksum
How to use checksums
7ad15b445e8eae55b708130e1118aa0a414099d489525593a1ada0a881dddc4a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","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.3.0-py3-none-any.whl

Download URL trace_agent_pydantic_ai-0.3.0-py3-none-any.whl
Size 7.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1e777e75f2f6d64aad8575da67460288387927eaf35369bf10e72585c7fab96e
BLAKE2b-256 checksum
How to use checksums
844ea49550dee3e9dad422ab8524dd4d11904f1eb5c4025e1001a740f7928c71
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","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.3.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