Skip to main content

Kitaru PydanticAI adapter

Record and replay PydanticAI agent runs with Kitaru.

Install

uv add "kitaru-pydantic-ai[openai]"

Install kitaru-pydantic-ai without the extra when your project provides another PydanticAI model implementation.

Use

import uuid

from pydantic_ai import Agent

from kitaru_pydantic_ai import KitaruAgent

agent = KitaruAgent(
    Agent("openai:gpt-5-nano"),
    agent_id=uuid.UUID("018f0000-0000-7000-8000-000000000100"),
)
result = agent.run_sync("Hello")
print(result.output)

The adapter accepts the same run arguments as the wrapped PydanticAI agent. Kitaru workers provide task, replay, and authentication context through the standard task environment.

Keep a simulator's prompt

By default, task inputs from KITARU_TASK_INPUTS or the task spec replace the run's prompt and supply recorded message history. If a benchmark task ID is an input to your simulator rather than a model prompt, disable that substitution:

agent = KitaruAgent(pydantic_agent, use_task_inputs_as_prompt=False)
result = await agent.run(simulator_prompt, message_history=simulator_history)

The adapter preserves the caller's prompt and message history while recording task inputs as the session inputs and root node inputs. An explicit replay.override.prompt still takes precedence, and model overrides and tool policies continue to apply.

Attach grades after a run

The adapter completes the session before the run returns, so later updates to its outputs or metadata return HTTP 409. Use client.sessions.create_evaluations(session_id, request) to attach a manual benchmark grade to a completed session, including from its own agent task before the process exits. Manual evaluations do not contribute to experiment aggregates. For experiment metrics, include the grade in the final output through an output_validator, then read it with a registered evaluator. See the adapter guide for the request example and evaluator details.

Model costs

The adapter estimates each completed LLM call's USD cost from its resolved model, provider, token usage, and request time. Pricing comes from the bundled genai-prices catalog. Unsupported models and providers leave the cost unset without failing the agent run. The recorded node attributes describe whether pricing was estimated or unavailable.

Supply cost_calculator for private models, negotiated rates, or provider billing rules. The callback receives a PydanticAIUsageSummary and returns a non-negative USD amount. A supplied callback takes priority over the bundled catalog.

from decimal import Decimal

from kitaru_pydantic_ai import KitaruAgent, PydanticAIUsageSummary


def calculate_cost(usage: PydanticAIUsageSummary) -> Decimal:
    uncached_input = usage.input_tokens - usage.cached_input_tokens
    return (
        Decimal(uncached_input) * Decimal("0.000002")
        + Decimal(usage.cached_input_tokens) * Decimal("0.0000002")
        + Decimal(usage.output_tokens) * Decimal("0.000008")
    )


agent = KitaruAgent(pydantic_agent, cost_calculator=calculate_cost)

Set estimate_costs=False when cost estimation should be disabled. This does not disable a supplied cost_calculator.

See the PydanticAI adapter guide for the recording lifecycle, replay overrides, tool policies, payload handling, and failure behavior.

Licensed under Apache-2.0.

Metadata

Release files for kitaru-pydantic-ai 0.4.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 kitaru-pydantic-ai 0.4.0
File Size Uploaded Provenance Actions
kitaru_pydantic_ai-0.4.0.tar.gz 17.0 kB With provenance Details for kitaru_pydantic_ai-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for kitaru-pydantic-ai 0.4.0
File Interpreter ABI Platform Actions
kitaru_pydantic_ai-0.4.0-py3-none-any.whl Python 3 none any Details for kitaru_pydantic_ai-0.4.0-py3-none-any.whl

Total release size: 32.8 kB

Release files / kitaru_pydantic_ai-0.4.0.tar.gz

Download URL kitaru_pydantic_ai-0.4.0.tar.gz
Size 17.0 kB
Tags Source
SHA-256 checksum
How to use checksums
100689b6d8ee63d0b84930d035430442ca15142b4543b07c10f8a7d2f0dbc2d5
BLAKE2b-256 checksum
How to use checksums
b0a132d6bab3df4ae416cdbf9c717995e5cfe1f403e583e7785dd7c5cc8e1fd9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 30, 2026.

Transparency log

Release files / kitaru_pydantic_ai-0.4.0-py3-none-any.whl

Download URL kitaru_pydantic_ai-0.4.0-py3-none-any.whl
Size 15.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
09dbeba024b267622695b2c6fe59abc396ff8f742d105b9a7b73a38271262c17
BLAKE2b-256 checksum
How to use checksums
605b215498868bcf3d744698c1bcaef490b85f370fff3725b76726fbd2280639
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 30, 2026.

Transparency log

Security for kitaru-pydantic-ai 0.4.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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for kitaru_pydantic_ai-0.4.0.tar.gz

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 30, 2026.

Transparency log

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