Skip to main content

Grafana Agent Observability Python Framework Module: Pydantic AI

agento11y-pydantic-ai provides an AbstractCapability implementation that maps Pydantic AI lifecycle hooks into agento11y generation recorder lifecycles.

Installation

pip install agento11y agento11y-pydantic-ai
pip install pydantic-ai

Quickstart

from pydantic_ai import Agent
from agento11y import Client
from agento11y_pydantic_ai import create_agento11y_pydantic_ai_capability

client = Client()
capability = create_agento11y_pydantic_ai_capability(client=client, provider_resolver="auto")

agent = Agent("openai:gpt-4o", capabilities=[capability])
result = agent.run_sync("What is the weather?")
print(result.output)

client.shutdown()

End-to-end example (run + run_stream)

from pydantic_ai import Agent
from agento11y import Client
from agento11y_pydantic_ai import with_agento11y_pydantic_ai_capability

client = Client()
capabilities = with_agento11y_pydantic_ai_capability(
    None,
    client=client,
    provider_resolver="auto",
    agent_name="pydantic-ai-example",
    agent_version="1.0.0",
)

agent = Agent("openai:gpt-4o-mini", capabilities=capabilities)

# Non-stream call -> SYNC generation mode.
result = agent.run_sync("Summarize why retry budgets matter.")
print(result.output)

# Stream call -> STREAM generation mode + TTFT tracking.
async def stream_example() -> None:
    async with agent.run_stream("Give me three short reliability tips.") as stream:
        async for chunk in stream.stream_text():
            print(chunk, end="", flush=True)
        print()

import asyncio
asyncio.run(stream_example())

client.shutdown()

Conversation mapping

Primary mapping is Pydantic AI run identity:

  1. conversation_id / session_id from ctx.deps or ctx.metadata
  2. thread_id from ctx.deps or ctx.metadata
  3. fallback agento11y:framework:pydantic-ai:<run_id>

Metadata and lineage

  • Required: agento11y.framework.run_type
  • Optional: agento11y.framework.run_id, agento11y.framework.parent_run_id, agento11y.framework.thread_id, agento11y.framework.event_id, agento11y.framework.component_name, agento11y.framework.retry_attempt

Provider resolver

Resolver order: explicit provider option -> callback payload -> model prefix inference -> custom.

Troubleshooting

  • Provide stable conversation_id via ctx.deps or ctx.metadata to avoid fragmented conversations.
  • If model aliases are custom, set explicit provider on the handler.
  • Always call client.shutdown() during teardown to flush buffered telemetry.

Metadata

Release files for agento11y-pydantic-ai 0.19.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 agento11y-pydantic-ai 0.19.0
File Size Uploaded
agento11y_pydantic_ai-0.19.0.tar.gz 13.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for agento11y-pydantic-ai 0.19.0
File Interpreter ABI Platform
agento11y_pydantic_ai-0.19.0-py3-none-any.whl Python 3 none any Details

Total release size: 22.0 kB

Release files / agento11y_pydantic_ai-0.19.0.tar.gz

Download URL agento11y_pydantic_ai-0.19.0.tar.gz
Size 13.0 kB
Tags Source
SHA-256 checksum
How to use checksums
dbf1da9c285c0491e096667cfb371ba5b3ffd904c0607a7860a2667f8d24e7a4
BLAKE2b-256 checksum
How to use checksums
c4e29a9ddc168388aba19082f038212a4f3aa8b8c75a7b3173dae1ccb5200ad5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Release files / agento11y_pydantic_ai-0.19.0-py3-none-any.whl

Download URL agento11y_pydantic_ai-0.19.0-py3-none-any.whl
Size 9.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0b1d9668a7c84b0cdcf53068ef0eebd7d5a0645cffa7e2b2a770061ed3bd8e95
BLAKE2b-256 checksum
How to use checksums
69a1d9060d4ffaef27f20be812f78f8d6c32e3fe4f8a644fe6557e5d5508d2b8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.19.0 This release

2 release files

0.18.0

2 release files

0.17.0

2 release files

0.16.0

2 release files

0.15.0

2 release files

0.14.0

2 release files

0.12.0

2 release files

0.10.0

2 release files

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