Skip to content

fix(tools): preserve caller-owned schema titles - #3644

Open
xuilen wants to merge 1 commit into
ag2ai:mainfrom
xuilen:fix/preserve-input-tool-schema
Open

xuilen wants to merge 1 commit into
ag2ai:mainfrom
xuilen:fix/preserve-input-tool-schema

Conversation

@xuilen

@xuilen xuilen commented Nov 12, 2026

Copy link
Copy Markdown

Why are these changes needed?

Passing a dictionary to @tool(schema=...) removes its top-level title: FunctionDefinition.__post_init__ pops the key from the same dictionary supplied by the caller. Reusing that dictionary then loses its original metadata.

Copy the parameter mapping before removing the top-level title. The generated tool schema still omits that title and retains nested property titles. A public-decorator regression test checks both the caller's original dictionary and the generated schema. The copy is shallow because this normalization changes only the top-level mapping.

Validation on Windows / Python 3.13.14:

  • The new regression fails on unmodified main and passes with this change.
  • uv run --no-sync --frozen pytest test/tools/test_naming.py test/tools/test_agent_tools.py test/tools/test_client_tool.py test/tools/test_execution.py test/tools/test_public_exports.py -q -p no:cacheprovider: 57 passed, 1 existing xfail.
  • Targeted Ruff lint/format and the repository license-header check pass.
  • Mypy 2.4.0 passes for the production module. The test module has five existing Tool.schema attribute diagnostics; checking the unmodified main test file produces the same five messages. They are not suppressed by this PR.

The full suite, live-provider calls, and other operating systems were not run. Remote CI has not run for this branch.

Related issue number

No existing issue; found by tracing the public tool(schema=...) path on current main. Open PR titles and changed files were checked for overlap before preparing this fix.

Checks

AI assistance

Codex assisted with source review, the patch, regression reproduction, local test execution, and this description. I reviewed the diff and recorded test evidence before authorizing submission; the reported commands were executed by Codex, not rerun personally. I take responsibility for the contribution and can discuss it with reviewers.

  • I understand the changes in this PR and can explain them in my own words.
  • I have verified that the PR description accurately reflects the actual diff.
  • If AI assistance was used, I reviewed, tested, and validated the generated code/text before submitting.

@CLAassistant

CLAassistant commented Nov 12, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions Bot added the area:tools Tool system, builtin tools, subagents (ag2/tools) label Nov 12, 2026
@codecov

codecov Bot commented Nov 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
ag2/tools/final/function_tool.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@xuilen
xuilen force-pushed the fix/preserve-input-tool-schema branch from b1dd0f0 to c160a4f Compare November 27, 2026 04:09

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:tools Tool system, builtin tools, subagents (ag2/tools)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants