Skip to content

Python: [BREAKING] Remove FunctionTool[Any] compatibility shim for schema passthrough (#3600)#3907

Open
eavanvalkenburg wants to merge 6 commits intomicrosoft:mainfrom
eavanvalkenburg:fix-3600-schema-passthrough
Open

Python: [BREAKING] Remove FunctionTool[Any] compatibility shim for schema passthrough (#3600)#3907
eavanvalkenburg wants to merge 6 commits intomicrosoft:mainfrom
eavanvalkenburg:fix-3600-schema-passthrough

Conversation

@eavanvalkenburg
Copy link
Member

@eavanvalkenburg eavanvalkenburg commented Feb 13, 2026

Summary

Fixes #3600

This PR simplifies FunctionTool schema handling so schema-based tools no longer rely on generated Pydantic models at runtime.

What changed

  • Removed FunctionTool generic ArgsT usage and simplified FunctionTool typing.
  • For schema-supplied tools, creation/schema/invoke now work without requiring a Pydantic model.
  • invoke() accepts mapping arguments directly and performs lightweight schema checks.
  • _auto_invoke_function() now validates schema-supplied tool arguments without model_validate.
  • MCP prompt/tool schema handling now uses plain schema dicts (no prompt-side Pydantic model creation; tool schema passed through directly).
  • Consolidated schema passthrough tests into existing core test files and removed 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.py
  • uv run --directory packages/core pyright
  • uv 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

…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
Copilot AI review requested due to automatic review settings February 13, 2026 09:37
@eavanvalkenburg eavanvalkenburg self-assigned this Feb 13, 2026
@markwallace-microsoft
Copy link
Member

markwallace-microsoft commented Feb 13, 2026

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/ag-ui/agent_framework_ag_ui
   _client.py1511788%85–86, 90–94, 98–102, 265, 295, 464–466
   _utils.py100199%74
packages/core/agent_framework
   _agents.py3123987%476, 876, 912, 989–992, 1056–1058, 1172, 1185, 1198, 1204, 1240, 1242, 1251–1256, 1261, 1263, 1269–1270, 1277, 1279–1280, 1288–1289, 1292–1294, 1302–1303, 1305, 1310, 1312
   _mcp.py4046384%102–103, 113–118, 129, 134, 180–181, 191–196, 206–207, 259, 268, 331, 339, 474, 541, 576, 578, 582–583, 585–586, 640, 655, 673, 714, 819, 832–837, 859, 905–906, 912–914, 933, 958–959, 963–967, 984–988, 1132
   _middleware.py3291695%80, 83, 88, 795, 797, 799, 920, 947, 949, 974, 1055, 1059, 1183, 1187, 1248, 1322
   _tools.py81711386%172–173, 310, 312, 330–332, 339, 357, 371, 378, 385, 401, 403, 410, 447, 472, 476, 493–495, 544–546, 609, 631, 655–681, 716, 727–738, 760–762, 767, 771, 785–787, 826, 895, 905, 915, 971, 1002, 1021, 1283, 1340, 1344, 1360, 1431–1435, 1453, 1455–1456, 1568, 1572, 1622, 1624, 1640, 1642, 1706, 1733, 1790, 1858, 2037–2038, 2065, 2073, 2086, 2096–2097, 2132, 2188, 2220
   observability.py6188486%335, 337–339, 342–344, 349–350, 356–357, 363–364, 371, 373–375, 378–380, 385–386, 392–393, 399–400, 407, 676, 679, 687–688, 691–694, 696, 699–701, 704–705, 733, 735, 746–748, 750–753, 757, 765, 866, 868, 1017, 1019, 1023–1028, 1030, 1033–1037, 1039, 1151–1152, 1154, 1211–1212, 1347, 1401–1402, 1518–1520, 1579, 1749, 1903, 1905
packages/orchestrations/agent_framework_orchestrations
   _handoff.py3265682%104–105, 107, 136–137, 159–169, 171, 173, 175, 180, 278, 331, 356, 384, 392–393, 407, 458–459, 491, 531–533, 538–540, 656, 659, 666, 671, 733, 738, 745, 755, 757, 776, 778, 860–861, 893–894, 976, 983, 1055–1056, 1058
TOTAL20532327584% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
3923 225 💤 0 ❌ 0 🔥 1m 12s ⏱️

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 FunctionTool to store JSON schemas as-is and skip Pydantic conversion when schemas are supplied
  • Updated _get_input_model_from_mcp_tool and _get_input_model_from_mcp_prompt to 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

@markwallace-microsoft markwallace-microsoft added the lab Agent Framework Lab label Feb 13, 2026
@eavanvalkenburg eavanvalkenburg changed the title Python: Fix #3600: Pass JSON schemas through without Pydantic conversion [BREAKING] Remove FunctionTool[Any] compatibility shim for schema passthrough (#3600) Feb 13, 2026
@eavanvalkenburg eavanvalkenburg changed the title [BREAKING] Remove FunctionTool[Any] compatibility shim for schema passthrough (#3600) Python: [BREAKING] Remove FunctionTool[Any] compatibility shim for schema passthrough (#3600) Feb 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lab Agent Framework Lab python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: tools: Skip pydantic model build step in FunctionTool

3 participants