Python: [BREAKING] Remove FunctionTool[Any] compatibility shim for schema passthrough (#3600)#3907
Open
eavanvalkenburg wants to merge 6 commits intomicrosoft:mainfrom
Open
Conversation
…sion This change optimizes FunctionTool and MCP flows by passing JSON schemas directly to providers without converting them to Pydantic models first. Key changes: - Store JSON schema as-is when supplied to FunctionTool - Skip Pydantic model_validate for schema-supplied tools in invoke() - Return MCP tool schemas directly without conversion - Add comprehensive tests for schema passthrough behavior Performance benefits: - Eliminates expensive Pydantic model creation for supplied schemas - Preserves exact schema structure (additionalProperties, custom fields, etc.) - Reduces memory overhead and initialization time Maintains backward compatibility: - Function signature inference still uses Pydantic models - Explicit Pydantic models passed as input_model work as before - All existing tests pass
Member
Contributor
There was a problem hiding this comment.
Pull request overview
This PR attempts to optimize FunctionTool and MCP integration by passing JSON schemas directly without converting them to Pydantic models. The goal is to improve performance by skipping expensive Pydantic model creation and validation. However, the implementation has a critical bug that breaks the main agent execution path.
Changes:
- Modified
FunctionToolto store JSON schemas as-is and skip Pydantic conversion when schemas are supplied - Updated
_get_input_model_from_mcp_tooland_get_input_model_from_mcp_promptto return dicts instead of Pydantic models - Added comprehensive test suite to verify schema passthrough behavior
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 11 comments.
| File | Description |
|---|---|
| python/packages/core/agent_framework/_tools.py | Added _schema_supplied flag and _input_schema field to store JSON schemas as-is; modified _resolve_input_model to return EmptyInputModel for schema-supplied tools; updated invoke() and parameters() to handle schema passthrough |
| python/packages/core/agent_framework/_mcp.py | Changed _get_input_model_from_mcp_tool to return dict instead of Pydantic model; updated _get_input_model_from_mcp_prompt to return dict for prompts with arguments; removed unused import |
| python/packages/core/tests/core/test_mcp.py | Updated tests to expect dict schemas instead of Pydantic models; simplified test assertions to verify schema passthrough |
| python/packages/core/tests/core/test_schema_passthrough.py | Added 9 new tests covering schema storage, invocation, MCP integration, and performance; tests verify that JSON schemas are preserved without Pydantic conversion |
eavanvalkenburg
commented
Feb 13, 2026
giles17
approved these changes
Feb 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #3600
This PR simplifies FunctionTool schema handling so schema-based tools no longer rely on generated Pydantic models at runtime.
What changed
FunctionToolgenericArgsTusage and simplified FunctionTool typing.invoke()accepts mapping arguments directly and performs lightweight schema checks._auto_invoke_function()now validates schema-supplied tool arguments withoutmodel_validate.test_schema_passthrough.py.Validation
uv run ruff check packages/core/agent_framework/_tools.py packages/core/agent_framework/_mcp.py packages/core/agent_framework/_middleware.py packages/core/agent_framework/_agents.py packages/core/agent_framework/observability.py packages/core/tests/core/test_tools.py packages/core/tests/core/test_mcp.pyuv run --directory packages/core pyrightuv run python -m pytest -q packages/core/tests/core/test_tools.py packages/core/tests/core/test_mcp.py packages/core/tests/core/test_function_invocation_logic.py packages/core/tests/core/test_middleware.py packages/core/tests/core/test_middleware_context_result.py