Skip to main content

Pydantic AI capability for Sigil Python SDK

Project description

Grafana AI Observability Python Framework Module: Pydantic AI

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

Installation

pip install sigil-sdk sigil-sdk-pydantic-ai
pip install pydantic-ai

Quickstart

from pydantic_ai import Agent
from sigil_sdk import Client
from sigil_sdk_pydantic_ai import create_sigil_pydantic_ai_capability

client = Client()
capability = create_sigil_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 sigil_sdk import Client
from sigil_sdk_pydantic_ai import with_sigil_pydantic_ai_capability

client = Client()
capabilities = with_sigil_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 sigil:framework:pydantic-ai:<run_id>

Metadata and lineage

  • Required: sigil.framework.run_type
  • Optional: sigil.framework.run_id, sigil.framework.parent_run_id, sigil.framework.thread_id, sigil.framework.event_id, sigil.framework.component_name, sigil.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.

Project details


Download files

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

Source Distribution

sigil_sdk_pydantic_ai-0.9.0.tar.gz (12.9 kB view details)

Uploaded Source

Built Distribution

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

sigil_sdk_pydantic_ai-0.9.0-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file sigil_sdk_pydantic_ai-0.9.0.tar.gz.

File metadata

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

File hashes

Hashes for sigil_sdk_pydantic_ai-0.9.0.tar.gz
Algorithm Hash digest
SHA256 9c2ab3f15431de3378fb0eaeaccb9685b3abe40403bc7259a0641a5a287968f0
MD5 f6e9a72f79e87f01a6ea70474f9711d8
BLAKE2b-256 34dc362ce7f4f47f18cef2c12157acfd952c3cbf1f06181e9b1784dd1b419735

See more details on using hashes here.

Provenance

The following attestation bundles were made for sigil_sdk_pydantic_ai-0.9.0.tar.gz:

Publisher: python-sdks-publish.yml on grafana/sigil-sdk

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

File details

Details for the file sigil_sdk_pydantic_ai-0.9.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sigil_sdk_pydantic_ai-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bf2d0aa6ea45e7b8d3201fc3171a5a44ff065a4a6b5e93929abbc938b464ed97
MD5 4f7d14478f2409f38c9b4e996ac5b44c
BLAKE2b-256 73c396418055b0fae4fc78d481276a8b4e204ec14dc91279cd28563abbcfe0c8

See more details on using hashes here.

Provenance

The following attestation bundles were made for sigil_sdk_pydantic_ai-0.9.0-py3-none-any.whl:

Publisher: python-sdks-publish.yml on grafana/sigil-sdk

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 Pingdom Monitoring Sentry Error logging StatusPage Status page