Repository navigation
fix(responses): keep the namespace == name shape for deferred top-level tools - #50106
homenshum-cheiron wants to merge 2 commits into
Conversation
…el tools The OpenAI Agents SDK matches a call to a deferred top-level function (defer_loading=True) only when the function_call carries namespace == name, the shape it reserves for deferred top-level tools. The Responses bridge returned no namespace, so after a native tool search the SDK failed with "Tool <name> not found". A client that adds namespace == name then hit the echo path, which joined it into "<name>__<name>" for the provider. - namespace_tool_name_map maps deferred top-level functions to (name, name), so non-streaming and streaming replies carry namespace == name - the function_call echo does not qualify a name whose namespace equals it Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…hares its namespace's name A namespace "search" with a member "search" is advertised as the chat tool "search__search" and comes back as name == namespace == "search". The echo rule from the previous commit skipped the join for every namespace == name, so that replay reached the provider as "search", a tool it was never given. The bare-name echo now applies only to the request's deferred top-level tools (deferred_top_level_names), and the reply map uses the same set. A deferred top-level name that a self-named namespace member also uses is left out of both directions, so the namespace member keeps its round trip. The lookup reads defer_loading is True instead of validating it, so callers that only read the input (token counting under drop_params) do not raise on a malformed flag. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@BugBot run |
[Medium impact] The change reaches deferred-tool calls through LiteLLM’s Responses endpoint. Fix stored-response replay and satisfy the repository's live-proof and readability requirements before merging Findings
SummaryDeferred top-level function calls now return with Stored-response replay still lacks the tool definitions needed to preserve those names. Required live proof and comprehension-rule compliance also need attention
Reviews (1) · Last reviewed commit: "fix(responses): keep the qualified name ..." · Reviewed by Greptile |
| deferred_top_level_names=LiteLLMCompletionResponsesConfig.deferred_top_level_names( | ||
| responses_api_request.get("tools") | ||
| ), |
There was a problem hiding this comment.
When users continue through previous_response_id, stored responses are rebuilt with responses_api_request={}. The new deferred-name lookup is therefore empty, so a newly marked call named search becomes search__search, although the provider tool is named search. Pass the stored tool definitions when rebuilding history to preserve the original name
| deferred_top_level_entries: Final = tuple( | ||
| (name, (name, name)) for name in LiteLLMCompletionResponsesConfig.deferred_top_level_names(tools) | ||
| ) | ||
| return MappingProxyType(dict(qualified_entries + unambiguous_entries + deferred_top_level_entries)) |
There was a problem hiding this comment.
Required live proof is missing
The repository requires reproducible live proxy runs showing this bug failing before and succeeding after. The supplied before run uses a stub, and the after run combines three PRs without commands or a run hash. Provide the required real-provider proof for c6ab757c248ec160024ea439b5faa5cecde2d3a2 before merging
Rule Used: Apply this rule only to PRs that fix LLM translation bugs or add LLM translation features. LLM translation means converting requests, responses, streaming events, tool calls, and errors between the API a caller uses on LiteLLM (any endpoint or SDK fu... (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| self_named_namespace_members: Final = frozenset( | ||
| str(tool.get("name") or "") | ||
| for tool in tools or () | ||
| if tool.get("type") == "namespace" | ||
| for namespace_tools in (tool.get("tools"),) | ||
| if isinstance(namespace_tools, Sequence) and not isinstance(namespace_tools, (str, bytes)) | ||
| for namespace_tool in namespace_tools | ||
| if isinstance(namespace_tool, Mapping) | ||
| and namespace_tool.get("type") == "function" | ||
| and namespace_tool.get("name") == tool.get("name") |
There was a problem hiding this comment.
Comprehensions exceed the clause limit
Both new comprehensions in deferred_top_level_names exceed the AGENTS.md limit of one for and one if. Split them into named steps or helpers to satisfy this readability requirement before merging
Context Used: AGENTS.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit c6ab757. Configure here.
Merging this PR will not alter performance1 warning
Comparing |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Superseded by #50602, which carries these commits plus the stored-replay and client-side search fixes, now merged. Thanks for the fix. |
Handwritten 1-3 sentence description
<make-me-human-readable>Agents built with the OpenAI Agents SDK can now use deferred tools with Claude's tool search through the Responses endpoint. Before, the agent crashed right after Claude found the tool, because the reply did not mark that tool the way the SDK expects.
</make-me-human-readable>Details
TLDR
Problem this solves:
namespace == namemark the SDK needsname__nameto the provider insteadHow it solves it:
namespaceequal tonameUser Flow
Before: an Agents SDK app on Claude crashes after its first tool search
defer_loading: trueand{"type": "tool_search"}, modelclaude-opus-5(Bedrock Invoke)tool_search_call, then afunction_callnamedget_reporting_categorieswith nonamespaceModelBehaviorError: Tool get_reporting_categories not found in agent iaAfter: the same app finishes the turn
function_callnow carries"namespace": "get_reporting_categories"get_reporting_categories, and Claude answersRelevant issues
Part of #50104 (item 1).
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or moreScreenshots / Proof of Fix
Shared setup: Agents SDK 0.24.0,
OpenAIResponsesModelpointed at the proxy's/v1/responses, 6 deferred function tools plusToolSearchTool(), no client-side namespace handling, two user turns. Proxy config as in #50104, with a callback that records each request body sent to Bedrock.Before (fd4cef2)
ModelBehaviorError: Tool get_reporting_categories not found in agent ia. Same on v1.108.0 and v1.109.0rc1. This step ran against a local Bedrock stubAfter (tested on a build of this PR plus the other two PRs for #50104)
tool_usein the recorded Bedrock request bodies is namedget_reporting_categoriesFocused checks on this PR's tip:
test_transform_chat_completion_response_deferred_top_level_tool_call_has_namespace_equal_to_name,test_function_call_echo_with_namespace_equal_to_name_keeps_bare_name,test_function_call_echo_from_namespace_with_member_of_same_name_keeps_qualified_name,test_deferred_top_level_name_shared_with_self_named_namespace_member_stays_qualified. Each fails with the source change reverted.test_claude_count_request_drops_a_malformed_tool_flag_under_drop_params_like_inferenceguards the lookup: it readsdefer_loading is Trueand does not raise, because token counting underdrop_paramsonly reads the input.uv run pytest tests/unit/responses/ tests/unit/llms/bedrock/messages/: 2151 passed. The only failures aretest_reasoning_effort_grid_wire_shapes[*-vertex-ai](needs the Google Cloud SDK) andtest_every_openai_sdk_response_error_code_has_explicit_status_mapping; both fail the same way onmain.Type
🐛 Bug Fix
Caveats (if any)
Low
searchbeside a namespacesearchholdingsearchstays ambiguousmainnamespace == namefor a namespace member eitherFinal Attestation
🤖 Generated with Claude Code
Note
Medium Risk
Changes tool name/namespace mapping on the Responses bridge, which affects multi-turn Agents SDK + deferred tool flows; scope is limited to defer_loading top-level tools with explicit collision handling.
Overview
Fixes Responses ↔ chat-completion bridging for deferred top-level tools (
defer_loading: true) used with the OpenAI Agents SDK and native tool search.Outbound (Responses → provider): Adds
deferred_top_level_names()and threads it through input conversion. When a replayedfunction_callhasnamespace == namefor one of those tools, the chattool_callkeeps the bare name instead ofname__name.Inbound (provider → Responses): Extends
namespace_tool_name_map()so those same tools are restored withnamespaceequal toname, which the Agents SDK needs to resolve the tool after search.Ambiguous cases (e.g. a namespace and a deferred top-level tool both named
searchwith a membersearch) still use qualified names; new unit tests cover the happy path and edge cases.Reviewed by Cursor Bugbot for commit c6ab757. Bugbot is set up for automated code reviews on this repo. Configure here.