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 - usage.cache_write_input_tokens
)
return (
Decimal(uncached_input) * Decimal("0.000002")
+ Decimal(usage.cached_input_tokens) * Decimal("0.0000002")
+ Decimal(usage.cache_write_input_tokens) * Decimal("0.0000025")
+ 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.
Links
Licensed under Apache-2.0.
Metadata
Release files for kitaru-pydantic-ai 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| kitaru_pydantic_ai-0.5.0.tar.gz | 17.5 kB | With provenance | Details for kitaru_pydantic_ai-0.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| kitaru_pydantic_ai-0.5.0-py3-none-any.whl | Python 3 | none | any | Details for kitaru_pydantic_ai-0.5.0-py3-none-any.whl |
Total release size: 33.8 kB
Release files / kitaru_pydantic_ai-0.5.0.tar.gz
| Download URL | kitaru_pydantic_ai-0.5.0.tar.gz |
|---|---|
| Size | 17.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6aaf6bc672711ad292b267bed7884e9358d5e0c06e56f2f6eff4e721dd8e6644
|
|
BLAKE2b-256 checksum How to use checksums |
27806eca6780f5f654edc82edcbf74f963eeb94dce370744c9ed8ee62d93b27d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 25, 2026.
Transparency logRelease files / kitaru_pydantic_ai-0.5.0-py3-none-any.whl
| Download URL | kitaru_pydantic_ai-0.5.0-py3-none-any.whl |
|---|---|
| Size | 16.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3ab2224044205e9c02fbad9d7d8778a19faba1833047ae12c4bf67bd1aca2c49
|
|
BLAKE2b-256 checksum How to use checksums |
67af823d3d6c8adf361ea0b096f997ae8d887f2e17237a1b8503582032ca87cc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 25, 2026.
Transparency logSecurity for kitaru-pydantic-ai 0.5.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.
Attestation for kitaru_pydantic_ai-0.5.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 Nov 25, 2026.
Transparency logA 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.