Skip to content

fix(responses): keep the namespace == name shape for deferred top-level tools - #50106

Closed
homenshum-cheiron wants to merge 2 commits into
BerriAI:mainfrom
homenshum-cheiron:fix/responses-deferred-tool-namespace
Closed

homenshum-cheiron wants to merge 2 commits into
BerriAI:mainfrom
homenshum-cheiron:fix/responses-deferred-tool-namespace

Conversation

@homenshum-cheiron

@homenshum-cheiron homenshum-cheiron commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • Agents SDK runs crash after Claude's tool search finds a deferred tool
  • The bridge omits the namespace == name mark the SDK needs
  • A client workaround sends name__name to the provider instead

How it solves it:

  • Deferred top-level tools come back with namespace equal to name
  • Streaming and non-streaming replies both carry it
  • Replayed calls with that mark keep the bare tool name
  • Other namespaces are still joined, as before

User Flow

Before: an Agents SDK app on Claude crashes after its first tool search

  1. The app sends POST https://litellm-domain/v1/responses with 6 function tools marked defer_loading: true and {"type": "tool_search"}, model claude-opus-5 (Bedrock Invoke)
  2. The reply holds a tool_search_call, then a function_call named get_reporting_categories with no namespace
  3. The SDK stops: ModelBehaviorError: Tool get_reporting_categories not found in agent ia

After: the same app finishes the turn

  1. The app sends the same POST
  2. The function_call now carries "namespace": "get_reporting_categories"
  3. The SDK runs the tool and sends its output back; the call reaches Bedrock named get_reporting_categories, and Claude answers

Relevant issues

Part of #50104 (item 1).

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. 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 more
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review

Screenshots / Proof of Fix

Shared setup: Agents SDK 0.24.0, OpenAIResponsesModel pointed at the proxy's /v1/responses, 6 deferred function tools plus ToolSearchTool(), 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)

  1. Run the agent. It stops after the first model call: 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 stub

After (tested on a build of this PR plus the other two PRs for #50104)

  1. Run the same agent, live: 4 Bedrock calls, both user turns answered
  2. Every tool_use in the recorded Bedrock request bodies is named get_reporting_categories

Focused checks on this PR's tip:

  • New tests: 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.
  • The existing test_claude_count_request_drops_a_malformed_tool_flag_under_drop_params_like_inference guards the lookup: it reads defer_loading is True and does not raise, because token counting under drop_params only reads the input.
  • uv run pytest tests/unit/responses/ tests/unit/llms/bedrock/messages/: 2151 passed. The only failures are test_reasoning_effort_grid_wire_shapes[*-vertex-ai] (needs the Google Cloud SDK) and test_every_openai_sdk_response_error_code_has_explicit_status_mapping; both fail the same way on main.

Type

🐛 Bug Fix

Caveats (if any)

Low

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

🤖 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 replayed function_call has namespace == name for one of those tools, the chat tool_call keeps the bare name instead of name__name.

Inbound (provider → Responses): Extends namespace_tool_name_map() so those same tools are restored with namespace equal to name, 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 search with a member search) 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.

homenshum-cheiron and others added 2 commits November 4, 2026 13:01
…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>
@CLAassistant

CLAassistant commented Nov 5, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@kerry-berri

Copy link
Copy Markdown
Contributor

@BugBot run

@kerry-berri

Copy link
Copy Markdown
Contributor

@greptileai

@greptile-apps

greptile-apps Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[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

  1. P1 Stored tool names change ▶
  2. P2 Required live proof is missing ▶
  3. P2 Comprehensions exceed the clause limit ▶

Summary

Deferred top-level function calls now return with namespace equal to name. Directly replayed calls keep their bare provider names, while real namespace members remain qualified

Stored-response replay still lacks the tool definitions needed to preserve those names. Required live proof and comprehension-rule compliance also need attention

homenshum-cheiron acknowledges that a deferred top-level search beside namespace search containing search remains ambiguous and retains the old behavior. This known limitation is not a separate finding

  • Deferred top-level calls carry their name as a namespace.
  • Echoed deferred calls keep the provider’s bare tool name.

Reviews (1) · Last reviewed commit: "fix(responses): keep the qualified name ..." · Reviewed by Greptile

Comment on lines +1404 to +1406
deferred_top_level_names=LiteLLMCompletionResponsesConfig.deferred_top_level_names(
responses_api_request.get("tools")
),

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.

P1 Stored tool names change

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

Comment on lines +3104 to +3107
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))

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.

P2 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!

Comment on lines +3054 to +3063
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")

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.

P2 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!

@cursor cursor Bot 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.

✅ 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.

@codspeed

codspeed Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

1 warning

⚠️ 1 benchmark is dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 43 untouched benchmarks


Comparing homenshum-cheiron:fix/responses-deferred-tool-namespace (c6ab757) with main (de85f59)

Open in CodSpeed

@codecov

codecov Bot commented Nov 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@kerry-berri

Copy link
Copy Markdown
Contributor

Superseded by #50602, which carries these commits plus the stored-replay and client-side search fixes, now merged. Thanks for the fix.

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.

3 participants