Skip to content

feat(pydantic-ai): expose AgentFlow-managed tools - #50

Merged
Emiyaaaaa merged 2 commits into
Emiyaaaaa:mainfrom
huangshaocanh-sys:feat/pydantic-ai-tool-surface
Aug 23, 2026
Merged

feat(pydantic-ai): expose AgentFlow-managed tools#50
Emiyaaaaa merged 2 commits into
Emiyaaaaa:mainfrom
huangshaocanh-sys:feat/pydantic-ai-tool-surface

Conversation

@huangshaocanh-sys

Copy link
Copy Markdown
Contributor

Summary

  • resolve tools, mcp_servers, and mcp_auto_register through the shared AdapterToolSurface
  • expose resolved definitions as a per-run PydanticAI toolset with provider-safe names while retaining original AgentFlow names for execution and audit events
  • delegate managed tool calls back to AgentFlow, suppress duplicate PydanticAI tool events, and preserve factory-native tools
  • document the configuration and cover injection, native-tool coexistence, safe MCP names, and failure event handling

Validation

  • pytest -q integrations/pydantic-ai/tests — 7 passed
  • ruff check integrations/pydantic-ai — passed
  • ruff format --check integrations/pydantic-ai — passed
  • mypy src — passed

Existing test issue

An expanded local backend subset produced 26 passes and 4 failures because the existing backend/tests/fixtures/mcp_echo_server.py references Server and stdio_server without importing them under the local MCP 2.x environment. This PR does not modify that fixture or docs/plan.md.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 AgentFlowToolset and a pydantic_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)
Comment thread integrations/pydantic-ai/README.md Outdated
Comment on lines +47 to +48
Install the MCP client extra when the factory uses `MCPToolset` or the config
supplies `mcp_servers`:
@Emiyaaaaa

Copy link
Copy Markdown
Owner

@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.

@Emiyaaaaa
Emiyaaaaa merged commit b000ed9 into Emiyaaaaa:main Aug 23, 2026
10 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants