Conversation
Add `.to_pydantic_ai()` method to all language models, enabling seamless integration with Pydantic AI agents. Features: - New EsperantoPydanticModel adapter implementing Pydantic AI's Model interface - Full support for tool calling, streaming, and structured output - Provider flexibility: switch between 15+ providers without code changes - EsperantoStreamedResponse for streaming support Provider-specific fixes: - Google: Clean JSON schemas (remove unsupported additionalProperties) - Google: Ensure tool responses are always dict/Struct - Ollama: Return Tool objects instead of dicts for tool conversion Testing: - 32 unit tests for adapter functionality - 11 integration tests with mocked responses - Manual testing: OpenAI, Anthropic, Google, Groq, Mistral, Azure, xAI, Ollama, DeepSeek Documentation: - Full usage guide at docs/advanced/pydantic-ai-integration.md - Example with 6 use cases at examples/pydantic_ai_example.py - Updated README with installation and usage - Updated CHANGELOG
1. Add run_context parameter to request_stream() to match new pydantic-ai API signature (fixes streaming across all providers) 2. Add _dereference_schema() helper to inline $defs/$ref values for Google provider which doesn't support JSON schema references (fixes structured output with nested Pydantic models)
Release includes: - Pydantic AI integration with full streaming, tool calling, and structured output support - Fix for streaming (new run_context parameter) - Fix for Google structured output (JSON schema dereferencing)
Code ReviewFound 2 CLAUDE.md compliance issues that need to be addressed: Issue 1: Missing
|
Summary
.to_pydantic_ai()method to all language models for seamless Pydantic AI agent integrationEsperantoPydanticModeladapter supporting tool calling, streaming, and structured outputChanges
New Files
src/esperanto/integrations/pydantic_ai.py- Core adapter implementationsrc/esperanto/integrations/__init__.py- Module exportsdocs/advanced/pydantic-ai-integration.md- Full usage documentationexamples/pydantic_ai_example.py- 6 example use casestests/unit/test_pydantic_ai_adapter.py- 32 unit teststests/integration/test_pydantic_ai_integration.py- 11 integration testsModified Files
src/esperanto/providers/llm/base.py- Addedto_pydantic_ai()methodsrc/esperanto/providers/llm/google.py- Schema cleaning and tool response fixespyproject.toml- Addedpydantic-aioptional dependencyREADME.md- Added feature mention and usage exampleCHANGELOG.md- Added release notesProvider-Specific Fixes
additionalPropertiesfrom JSON schemas (not supported)Toolobjects instead of dicts for tool conversionTesting
Usage
Test plan
uv run pytest tests/unit/test_pydantic_ai_adapter.py -v)uv run pytest tests/integration/test_pydantic_ai_integration.py -v)