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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

agento11y_pydantic_ai-0.15.0.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agento11y_pydantic_ai-0.15.0-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file agento11y_pydantic_ai-0.15.0.tar.gz.

File metadata

  • Download URL: agento11y_pydantic_ai-0.15.0.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for agento11y_pydantic_ai-0.15.0.tar.gz
Algorithm Hash digest
SHA256 e1fe64cbc7ae5135a236210cabaaa8db535aa830281cdda2290cb47508780ca2
MD5 6160e659ccd9407c9b8a33e0da1e8dc4
BLAKE2b-256 6a68da3c709b726fe1ae682c0d80f34e62815410deaa6893eae78f4ed1a75b47

See more details on using hashes here.

Provenance

The following attestation bundles were made for agento11y_pydantic_ai-0.15.0.tar.gz:

Publisher: python-sdks-publish.yml on grafana/agento11y

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file agento11y_pydantic_ai-0.15.0-py3-none-any.whl.

File metadata

File hashes

Hashes for agento11y_pydantic_ai-0.15.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fff81ad7b5a78127e5b4638c5ab274efbdbc6ccadd1bf490be51d3cd740bf016
MD5 230353917ee745cbcf59957afdff2f5b
BLAKE2b-256 48553e71f00d6105a6a89ab735c271e8557d4f2ee6e7fba498c844f7bedb719a

See more details on using hashes here.

Provenance

The following attestation bundles were made for agento11y_pydantic_ai-0.15.0-py3-none-any.whl:

Publisher: python-sdks-publish.yml on grafana/agento11y

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page