Skip to content

Python: Fix tool names and descriptions for partials and callable instances - #10135

Closed
Trainingcqy wants to merge 2 commits into
microsoft:mainfrom
Trainingcqy:fix/partial-tool-names
Closed

Trainingcqy wants to merge 2 commits into
microsoft:mainfrom
Trainingcqy:fix/partial-tool-names

Conversation

@Trainingcqy

Copy link
Copy Markdown

Motivation & Context

functools.partial objects and class instances with __call__ have no __name__, so tool() gives them all the default name unknown_function. When two such tools are passed to the same Agent, agent.run() raises a ValueError for the duplicate name. A partial's default description is the docstring of the functools.partial class itself. Reproduction: #10134.

Description & Review Guide

  • What are the major changes? Adds _get_callable_name and _get_callable_description, which unwrap each layer of partial lacking its own __name__ and its own __doc__, respectively. A callable instance without __name__ gets its class name, as _middleware.py does when naming middleware. When the class has no docstring and its __call__ is a Python function, the __call__ docstring is used. Updates the tool() docstring to match and adds the parametrized test test_tool_default_name_and_description.
  • What is the impact of these changes? Default names and descriptions of partials and callable instances change as above, and the parameter schema title changes with the name to <name>_input. Plain functions, methods, and classes are unaffected. When a plain function and its own partial, or a class and its instance, are passed together, agent.run() will raise a ValueError for the duplicate name, and they need name= to tell them apart; MontyCodeActProvider deduplicates by name and keeps only the one passed last. Function calls named unknown_function in sessions saved before the upgrade no longer match any tool.
  • What do you want reviewers to focus on? The __call__ docstring is used only for instances. The __call__ of functions and partials is built in and carries only the generic text "Call self as a function." The __call__ of a class object comes from its metaclass, and without this exclusion an Enum subclass would get the docstring of EnumType.__call__.

Related Issue

Fixes #10134

AI Assistance

  • No material AI assistance was used.
  • This is an AI-assisted contribution. I reviewed, understood, and verified all submitted content and accept responsibility for it.

AI assistance details: Completed with assistance from Claude Code and verified by me.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR links to an agreed issue with no competing open PR, or the Related Issue section documents a trivial-change or repository-automation exception.
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@agent-framework-automation agent-framework-automation Bot added the python Usage: [Issues, PRs], Target: Python label Nov 6, 2026
@Trainingcqy

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@eavanvalkenburg

Copy link
Copy Markdown
Member

Trainingcqy, thank you for the contribution. The maintainer direction on #10134 explicitly says not to add core automatic name or description inference for partials and callable instances; callers should supply name and description, with a small sample used for guidance instead. This PR implements the rejected core direction, so I am closing it. Please coordinate any sample-only follow-up in the issue before opening new work.

This branch was previously deployed

1 inactive deployment
github-app-auth — a32236e7 Deployed Nov 9, 2026 by Trainingcqy via add_label #27374
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: tool() names both functools.partial objects and callable instances unknown_function

3 participants