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.1.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.1.0
File Size Uploaded Provenance Actions
trace_agent_pydantic_ai-0.1.0.tar.gz 14.3 kB Without provenance Details for trace_agent_pydantic_ai-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 21.3 kB

Release files / trace_agent_pydantic_ai-0.1.0.tar.gz

Download URL trace_agent_pydantic_ai-0.1.0.tar.gz
Size 14.3 kB
Tags Source
SHA-256 checksum
How to use checksums
b3227ad701a5bbe5cde5d08f694dfe6ae39ade4dada677386598143b2d7ad4b6
BLAKE2b-256 checksum
How to use checksums
b7ef3c021b2614123edb52e4f93dedd61e1f8459333f1831e69355115dd3e01e
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.1.0-py3-none-any.whl

Download URL trace_agent_pydantic_ai-0.1.0-py3-none-any.whl
Size 7.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
754b92aa32a1a236cf71b3e761e8db63789f4ae3a49b6035f4133699f1531cb7
BLAKE2b-256 checksum
How to use checksums
df996e417d804a7ae6719a1bfe7845f7ec742f8e5be5522bfce8c53e95ad8731
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.1.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