Skip to content

Python: Added explicit schema handling to @tool decorator#3734

Merged
dmytrostruk merged 4 commits intomicrosoft:mainfrom
dmytrostruk:tool-schema-parameter
Feb 9, 2026
Merged

Python: Added explicit schema handling to @tool decorator#3734
dmytrostruk merged 4 commits intomicrosoft:mainfrom
dmytrostruk:tool-schema-parameter

Conversation

@dmytrostruk
Copy link
Member

Motivation and Context

Resolves: #3579

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

@dmytrostruk dmytrostruk self-assigned this Feb 6, 2026
Copilot AI review requested due to automatic review settings February 6, 2026 19:09
@markwallace-microsoft markwallace-microsoft added the documentation Improvements or additions to documentation label Feb 6, 2026
@markwallace-microsoft
Copy link
Member

markwallace-microsoft commented Feb 6, 2026

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/core/agent_framework
   _tools.py7898589%232, 278, 329, 331, 359, 529, 564–565, 667, 669, 689, 707, 721, 733, 738, 740, 747, 780, 851–853, 894, 916–944, 979, 987, 1228, 1462, 1519, 1523, 1602–1606, 1624, 1626–1627, 1732, 1736, 1786, 1788, 1804, 1806, 1870, 1897, 1950, 2018, 2197–2198, 2225, 2233, 2246, 2256–2257, 2292, 2348, 2380
TOTAL16592205987% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
3925 225 💤 0 ❌ 0 🔥 1m 11s ⏱️

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

Adds first-class support for supplying an explicit input schema to the Python @tool decorator, enabling callers to bypass signature-based schema inference (per issue #3579).

Changes:

  • Added a schema parameter to agent_framework.tool() that is forwarded to FunctionTool(input_model=...).
  • Added unit tests covering explicit schema usage via both Pydantic models and JSON-schema-like dicts.
  • Added a new getting-started sample and updated the tools README to document explicit schema usage.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
python/packages/core/agent_framework/_tools.py Extends @tool to accept an explicit schema and updates docstring/docs.
python/packages/core/tests/core/test_tools.py Adds coverage for @tool(schema=...) with Pydantic, dict schema, and schema=None.
python/samples/getting_started/tools/function_tool_with_explicit_schema.py New sample demonstrating explicit schema usage.
python/samples/getting_started/tools/README.md Documents the new explicit-schema capability and links the new sample.
Comments suppressed due to low confidence (1)

python/samples/getting_started/tools/function_tool_with_explicit_schema.py:60

  • The schema above declares a default for timezone (making it effectively optional), but get_current_time() requires timezone with no default in the function signature. Consider either adding a default in the signature (e.g., timezone="UTC") or marking it as required in the schema to keep behavior consistent.
def get_current_time(timezone: str) -> str:
    """Get the current time."""

@dmytrostruk dmytrostruk added this pull request to the merge queue Feb 6, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 6, 2026
@dmytrostruk dmytrostruk enabled auto-merge February 9, 2026 17:06
@dmytrostruk dmytrostruk added this pull request to the merge queue Feb 9, 2026
Merged via the queue into microsoft:main with commit 80cb6ed Feb 9, 2026
26 of 43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: tools: Add explicit schema handling to @tool decorator

5 participants