Skip to content

fix(core): resolve annotations for tools wrapped across modules - #8317

Open
fhgffy wants to merge 1 commit into
microsoft:mainfrom
fhgffy:fix/wrapped-tool-annotations
Open

fhgffy wants to merge 1 commit into
microsoft:mainfrom
fhgffy:fix/wrapped-tool-annotations

Conversation

@fhgffy

@fhgffy fhgffy commented Oct 5, 2026

Copy link
Copy Markdown

Why are these changes needed?

A tool decorated with functools.wraps can raise NameError during registration when its string annotations refer to names in the original function's module. inspect.signature follows the wrapped function, but passing the wrapper's globals to typing.get_type_hints resolves those annotations in the wrong namespace.

Let get_type_hints select the defining namespace in both signature and return-type resolution. The regression tests cover undecorated functions, one wrapper, nested wrappers, schema generation, and an actual FunctionTool.run_json call with a datetime argument.

Validation:

  • The new tests against the original implementation: 8 failed, 4 passed; the failures reproduce the namespace error.
  • The new tests plus existing tool and workbench tests: 60 passed.
  • Ruff lint/format, mypy, and pyright passed using the repository's pinned versions.

Related issue number

Related to #8302, which addresses globals for partial functions. This change also covers ordinary and nested wrappers across modules, including return-type resolution.

Checks

  • I've included any doc changes needed for https://microsoft.github.io/autogen/. No documentation changes are needed for this bug fix.
  • I've added tests (if relevant) corresponding to the changes introduced in this PR.
  • I've made sure all auto checks have passed. Local checks passed; GitHub checks are pending.

@fhgffy

fhgffy commented Oct 5, 2026 •

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@fhgffy

fhgffy commented Oct 5, 2026

Copy link
Copy Markdown
Author

@microsoft-github-policy-service terminate

@fhgffy

fhgffy commented Oct 5, 2026

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant