feat(pydantic-ai): expose AgentFlow-managed tools - #50
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
There are small but concrete correctness/maintainability issues in the new tests and documentation that should be addressed to avoid flaky behavior and misleading setup guidance.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR adds a bridge that exposes AgentFlow-managed tools (builtin registry + MCP-resolved) to PydanticAI as a per-run toolset, while delegating actual execution back through AgentFlow’s standardized AdapterToolSurface and suppressing duplicate PydanticAI tool events.
Changes:
- Introduces
AgentFlowToolsetand apydantic_tool_name()sanitizer to present provider-safe tool names while executing/auditing with original AgentFlow names. - Updates the PydanticAI adapter to optionally open an
AdapterToolSurface, register the toolset for the run, and avoid emitting duplicate tool call/result events. - Expands integration tests and updates README documentation to cover managed-tool injection and coexistence with factory-native tools.
File summaries
| File | Description |
|---|---|
| integrations/pydantic-ai/tests/test_adapter.py | Adds coverage for bridged tool injection, mixed tool execution, and single-emission failure handling. |
| integrations/pydantic-ai/src/agentflow_pydantic_ai/toolset.py | New per-run toolset that maps AgentFlow tool definitions into PydanticAI tool definitions with provider-safe names. |
| integrations/pydantic-ai/src/agentflow_pydantic_ai/adapter.py | Opens a managed tool surface when requested, passes toolsets into PydanticAI runs, and suppresses duplicate tool events. |
| integrations/pydantic-ai/src/agentflow_pydantic_ai/init.py | Exposes AgentFlowToolset as part of the integration’s public API. |
| integrations/pydantic-ai/README.md | Documents configuration behavior for tools/MCP integration and updates plugin scope statements. |
Review details
- Files reviewed: 5/5 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| async def fail(_arguments: dict[str, Any]) -> dict[str, Any]: | ||
| raise RuntimeError("bridge exploded") | ||
|
|
||
| register_tool("bridge_failure", fail, overwrite=True) |
| Install the MCP client extra when the factory uses `MCPToolset` or the config | ||
| supplies `mcp_servers`: |
|
@copilot Fix the code for all comments in this review thread. When a review comment includes a suggested change, apply the suggestion exactly. Do not make changes beyond what is described in the linked review thread. |
Summary
tools,mcp_servers, andmcp_auto_registerthrough the sharedAdapterToolSurfaceValidation
pytest -q integrations/pydantic-ai/tests— 7 passedruff check integrations/pydantic-ai— passedruff format --check integrations/pydantic-ai— passedmypy src— passedExisting test issue
An expanded local backend subset produced 26 passes and 4 failures because the existing
backend/tests/fixtures/mcp_echo_server.pyreferencesServerandstdio_serverwithout importing them under the local MCP 2.x environment. This PR does not modify that fixture ordocs/plan.md.