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.6.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.6.0
File Size Uploaded Provenance Actions
trace_agent_pydantic_ai-0.6.0.tar.gz 17.2 kB Without provenance Details for trace_agent_pydantic_ai-0.6.0.tar.gz

Built distribution (wheel)

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

Total release size: 26.0 kB

Release files / trace_agent_pydantic_ai-0.6.0.tar.gz

Download URL trace_agent_pydantic_ai-0.6.0.tar.gz
Size 17.2 kB
Tags Source
SHA-256 checksum
How to use checksums
1e98323a2033b5879ac07bfccb1523acd93199ad2217aa074b9adaf439303c1c
BLAKE2b-256 checksum
How to use checksums
9f41d3ff0e36c00b0d069dcda5e12af288b46f06c97801c5e8d8319560d9f98b
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.6.0-py3-none-any.whl

Download URL trace_agent_pydantic_ai-0.6.0-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0406e9386313e640a4a83b678167f93eddb6046364f04bd53a872e438343d9da
BLAKE2b-256 checksum
How to use checksums
c456345e2cfa1a6a4b95fdcf0ffdf704dcea505b2d81970472970d8048655f39
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.6.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