Summary
Add an optional integration module (mirroring the existing LangChain/LlamaIndex bridges) that wraps registered ChainWeaver flows as a Pydantic-AI toolset, so Pydantic-AI agents can call governed, compiled flows as ordinary tools.
Why this matters
Pydantic-AI shares ChainWeaver's foundation (Pydantic v2, typed schemas) and has an explicit toolset abstraction for wrapping external tools, making it a natural, low-friction integration. ChainWeaver currently ships bridges for LangChain, LlamaIndex, LangGraph, and OpenAI Agents; adding Pydantic-AI broadens ecosystem reach to a fast-growing, type-first audience with minimal impedance mismatch.
Current evidence
External context
Pydantic-AI exposes an AbstractToolset / toolset model for wrapping external tools; both libraries build on Pydantic v2, so schema translation is direct.
Proposed implementation
- Add
chainweaver/integrations/pydantic_ai.py exposing a function/class that turns a FlowExecutor + flow name (or a whole registry) into Pydantic-AI tool(s), translating input/output schemas.
- Add a
pydantic-ai optional extra in pyproject.toml with a lower-bound-only specifier (per the dependency-constraint policy), and a lazy import guard.
- Add a runnable, offline example (
examples/integrations/) and a cookbook page mirroring the LangGraph/OpenAI recipes.
- Decide async handling: MCP-adapted async flows must route through
execute_flow_async — document the sync/async tool variants.
AI-agent execution notes
Inspect chainweaver/integrations/langchain.py and llamaindex.py for the established adapter shape, chainweaver/export/_schema.py for schema translation helpers, pyproject.toml extras, docs/cookbook/. Keep the import lazy and the recipe offline (no API key). Preserve the rule that integrations are optional extras never imported by core. Add tests under tests/ guarded by an import skip when the extra is absent.
Acceptance criteria
- A flow can be registered as a Pydantic-AI tool and invoked, producing the flow's validated output.
- The integration imports lazily and is absent-tolerant when the extra is not installed.
- A runnable offline example and cookbook page exist.
Test plan
Skip-if-missing integration tests (sync and async flow), schema-translation unit test, example smoke test in the notebook/integration CI lane.
Documentation plan
New cookbook page, README ## Integrations table, pyproject.toml extras comment, CHANGELOG.
Migration and compatibility notes
Not expected to require migration (new optional module + extra).
Risks and tradeoffs
Another framework dependency to track against Pydantic-version drift (mitigated by lower-bound-only specifier and the existing floor-deps CI lane). Pydantic-AI APIs are evolving — pin a tested floor and document the supported range.
Suggested labels
integrations, ecosystem, developer-experience
Summary
Add an optional integration module (mirroring the existing LangChain/LlamaIndex bridges) that wraps registered ChainWeaver flows as a Pydantic-AI toolset, so Pydantic-AI agents can call governed, compiled flows as ordinary tools.
Why this matters
Pydantic-AI shares ChainWeaver's foundation (Pydantic v2, typed schemas) and has an explicit toolset abstraction for wrapping external tools, making it a natural, low-friction integration. ChainWeaver currently ships bridges for LangChain, LlamaIndex, LangGraph, and OpenAI Agents; adding Pydantic-AI broadens ecosystem reach to a fast-growing, type-first audience with minimal impedance mismatch.
Current evidence
chainweaver/integrations/containslangchain.py,llamaindex.py, plus LangGraph/OpenAI-Agents recipes (perpyproject.tomlextraslanggraph,openai-agents) — nopydantic_ai.py.pyproject.tomlalready models per-framework optional extras with offline-by-default recipes, so the pattern and packaging convention exist.External context
Pydantic-AI exposes an
AbstractToolset/ toolset model for wrapping external tools; both libraries build on Pydantic v2, so schema translation is direct.Proposed implementation
chainweaver/integrations/pydantic_ai.pyexposing a function/class that turns aFlowExecutor+ flow name (or a whole registry) into Pydantic-AI tool(s), translating input/output schemas.pydantic-aioptional extra inpyproject.tomlwith a lower-bound-only specifier (per the dependency-constraint policy), and a lazy import guard.examples/integrations/) and a cookbook page mirroring the LangGraph/OpenAI recipes.execute_flow_async— document the sync/async tool variants.AI-agent execution notes
Inspect
chainweaver/integrations/langchain.pyandllamaindex.pyfor the established adapter shape,chainweaver/export/_schema.pyfor schema translation helpers,pyproject.tomlextras,docs/cookbook/. Keep the import lazy and the recipe offline (no API key). Preserve the rule that integrations are optional extras never imported by core. Add tests undertests/guarded by an import skip when the extra is absent.Acceptance criteria
Test plan
Skip-if-missing integration tests (sync and async flow), schema-translation unit test, example smoke test in the notebook/integration CI lane.
Documentation plan
New cookbook page, README
## Integrationstable,pyproject.tomlextras comment, CHANGELOG.Migration and compatibility notes
Not expected to require migration (new optional module + extra).
Risks and tradeoffs
Another framework dependency to track against Pydantic-version drift (mitigated by lower-bound-only specifier and the existing floor-deps CI lane). Pydantic-AI APIs are evolving — pin a tested floor and document the supported range.
Suggested labels
integrations, ecosystem, developer-experience