Python examples
Common patterns with the Kitaru Python SDK. For complete signatures, see the Python SDK reference. For the TypeScript client, see How to use the SDK. For supported frameworks, see the adapter overview.
Record an agent's runs
Wrap an existing PydanticAI agent and every run is recorded as a session: each model call and tool call becomes a node. Each adapter ships as its own distribution, installed alongside kitaru. Here, install it with uv add kitaru-pydantic-ai:
import os
import uuid
from pydantic_ai import Agent
from kitaru_pydantic_ai import KitaruAgent
base_agent = Agent("openai:gpt-5.4", system_prompt="You resolve support tickets.")
agent = KitaruAgent(base_agent, agent_id=uuid.UUID(os.environ["KITARU_AGENT_ID"]))
result = agent.run_sync("Refund order #4821; the card reader was double-charged.")Inspect sessions
import asyncio
from kitaru.client import KitaruAPIClient
from kitaru.api_models.v1.session import SessionListParams
from kitaru.api_models.v1.session_node import SessionNodeListParams
async def main() -> None:
async with KitaruAPIClient() as client:
sessions = await client.sessions.list(SessionListParams(size=5))
if not sessions.items:
return
baseline_session_id = sessions.items[0].id
nodes = await client.sessions.list_nodes(
baseline_session_id, SessionNodeListParams(include_payloads=True)
)
print(baseline_session_id, len(nodes.items))
asyncio.run(main())Replay with one thing changed
Answer tool calls from the recorded session, swap the model, and run the same evaluator on both sides:
The full walkthrough, from recording through replaying cohorts and experiments, is the Kitaru quickstart.
Last updated
Was this helpful?