fix: treat hallucinated tool names as client-side function calls - #5043
Merged
Conversation
When the LLM called a tool name that was not registered as a function tool, a built-in (web_search/knowledge_search), or an MCP tool, the server raised a ValueError from _coordinate_tool_execution which propagated as a 500 InternalServerError. The classification in _separate_tool_calls was implicitly routing any unrecognised name into non_function_tool_calls, which _coordinate_tool_ execution had no branch for and therefore crashed on. Fix by adding an elif in _separate_tool_calls: if a tool call name is not a known server-side built-in and not an MCP tool, it is classified as a function_call and returned to the client as a completed output item. This matches OpenAI's behaviour and lets the caller inspect or ignore the hallucinated call without the response failing. Also introduce _SERVER_SIDE_BUILTIN_TOOL_NAMES to centralise the set of names the server executes itself, replacing an inline list literal at the one other membership-test site.
mattf
marked this pull request as ready for review
March 4, 2026 16:29
mattf
requested review from
ashwinb,
bbrowning,
cdoern,
ehhuang,
franciscojavierarceo,
leseb and
raghotham
as code owners
March 4, 2026 16:29
franciscojavierarceo
approved these changes
Mar 5, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Mar 5, 2026
Collaborator
Author
skamenan7
approved these changes
Mar 5, 2026
skamenan7
left a comment
Collaborator
There was a problem hiding this comment.
LGTM apart a nit, thanks!
| logger = get_logger(name=__name__, category="agents::meta_reference") | ||
| tracer = trace.get_tracer(__name__) | ||
|
|
||
| # Built-in tool names that the server knows how to execute itself. |
Collaborator
There was a problem hiding this comment.
nit: is there a single place where built-in tools are registered that we could derive this from, rather than keeping a hardcoded set? if someone adds a new built-in later and misses updating this, it will silently get treated as a hallucinated call. even a comment pointing to where web_search / knowledge_search are registered would help future-proof it.
Collaborator
Author
There was a problem hiding this comment.
that would be a useful refactor. the way we go from built-in to the backend tool is complex too.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When the LLM called a tool name that was not registered as a function tool, a built-in (web_search/knowledge_search), or an MCP tool, the server raised a ValueError from _coordinate_tool_execution which propagated as a 500 InternalServerError.
The classification in _separate_tool_calls was implicitly routing any unrecognised name into non_function_tool_calls, which coordinate_tool execution had no branch for and therefore crashed on.
Fix by adding an elif in _separate_tool_calls: if a tool call name is not a known server-side built-in and not an MCP tool, it is classified as a function_call and returned to the client as a completed output item. This matches OpenAI's behaviour and lets the caller inspect or ignore the hallucinated call without the response failing.
Also introduce _SERVER_SIDE_BUILTIN_TOOL_NAMES to centralise the set of names the server executes itself, replacing an inline list literal at the one other membership-test site.
closes #4781