PydanticAI Integration
Lucidic makes it easy to automatically track PydanticAI agent completions as part of your agent’s behavior — no code changes required.How It Works
When you set:- Instrument PydanticAI’s model classes using OpenTelemetry
- Automatically create events for each agent call - no manual event creation needed
- Attach the call to the currently active Step (or auto-create one if none exists)
- Support all PydanticAI model types (OpenAI, Anthropic, Gemini, Groq, etc.)
- You don’t need to call
create_event()
orend_event()
manually - You get full observability into prompts, model, cost, result, and more — out of the box
- Even if you forget to create a step, Lucidic handles it automatically
What Gets Captured
Each PydanticAI call is tracked with:description
: formatted messages sent to the modelmodel
: the underlying model name (e.g.claude-3-5-sonnet-20241022
,gpt-4
)cost
: calculated based on token usageresult
: truncated summary of the response
Why This Matters
PydanticAI agent calls are a core part of most AI workflows — but without visibility, it’s impossible to debug or optimize:- Which call caused the failure?
- Which step was it part of?
- How much did it cost?
- What was the actual response?
Example
Streaming Example
Explicit Step Management
Notes
- All PydanticAI model types are instrumented (OpenAI, Anthropic, Gemini, Groq, etc.)
- Both sync and async agent runs are supported
- If no step exists when an agent call is made, Lucidic automatically creates one
- Streaming responses are tracked automatically
- You can always add custom events using
create_event()
for additional context