-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Python: fix(core): treat a single mapping tool as one tool in merge_chat_options #8732
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
94758a5
810bed7
57e9025
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4215,11 +4215,19 @@ def merge_chat_options( | |
| # Merge tools lists | ||
| base_tools = result.get("tools") | ||
| if base_tools and value: | ||
| # Add tools that aren't already present | ||
| merged_tools = list(base_tools) | ||
| for tool in value if isinstance(value, Iterable) else [value]: # type: ignore[reportUnknownVariableType] | ||
| if tool not in merged_tools: | ||
| merged_tools.append(tool) | ||
| # Add tools that aren't already present, matching by name so the same | ||
| # plain callable wrapped on both sides is not added twice. | ||
| from ._tools import _get_tool_name # pyright: ignore[reportPrivateUsage] | ||
|
|
||
| merged_tools = normalize_tools(base_tools) | ||
| names = {name for t in merged_tools if (name := _get_tool_name(t))} | ||
| for tool in normalize_tools(value): | ||
| name = _get_tool_name(tool) | ||
| if tool in merged_tools or (name is not None and name in names): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Anish Mehta (@anishmehta24) This name-only dedupe also drops a distinct override tool that happens to share the base tool’s name, silently keeping the base implementation, schema, and approval settings instead. Elsewhere |
||
| continue | ||
| merged_tools.append(tool) | ||
| if name is not None: | ||
| names.add(name) | ||
| result["tools"] = merged_tools | ||
| elif value: | ||
| result["tools"] = value if isinstance(value, list) else [value] | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anish Mehta (@anishmehta24) The callable dedupe regression you noted is material here.
normalize_tools(base_tools)andnormalize_tools(value)wrap the same undecorated function into two distinctFunctionToolobjects, sotool not in merged_toolskeeps both and providers can receive duplicate tool names. Please preserve identity across the merge or dedupe normalized tools by the repository’s tool-name rules, with a regression using the same plain callable on both sides.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, merged tools are now deduped by tool name, so the same plain function on both sides ends up once. Added a regression for it.