Repository navigation
Conversation
…OpenAIChatGenerator
`_prepare_api_call` assembled the payload as `{**openai_tools, **generation_kwargs}`, so a `tools`
key inside `generation_kwargs` replaced the definitions built from the component's own `tools`
instead of being added to them. A caller passing extra OpenAI tool specs alongside Haystack tools
advertised only the former, and its own tools were silently dropped — no error, the model simply
never saw them.
The two lists are now merged: the component's own tools first, then the specs from
`generation_kwargs`, with the latter winning on a name clash, consistent with how every other
`generation_kwargs` key already overrides the component's defaults.
Tool names are read through `_tool_spec_name`, which resolves the body under the key named by the
spec's own `type`. That keeps `{"type": "custom", "custom": {...}}` and body-less built-ins such as
`{"type": "web_search"}` working: they carry no function name to clash on and are passed through
as given.
Fixes deepset-ai#12832
Assisted-by: Claude Code / claude-opus-5
Machine: A-MAC16-2019-PALOALTO.LOCAL
Account: dzyatkovskiy.a@gmail.com
Operator: anton
Signed-off-by: tonydzi <dzyatkovskiy.a@gmail.com>
Contributor
|
@antondzi-legacy is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
|
Closing, please see comment #12832 (comment) |
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.
Fixes #12832.
The bug
OpenAIChatGenerator._prepare_api_callbuilds the request as{**openai_tools, **generation_kwargs}. Becausegeneration_kwargsis spliced last, atoolskey inside it replaces the definitions built from the component's owntoolsrather than joining them. Nothing raises — the tools just never reach the model, which then cannot call them. As the issue notes, this reproduces on the generator's public API, independently ofAgent(#12775 fixed theAgentpath only).The fix
The two lists are merged: the component's own tools first, then the specs from
generation_kwargs, with the latter winning on a name clash — the same precedence every othergeneration_kwargskey already has.Names are resolved through a small
_tool_spec_namehelper that reads the body under the key named by the spec's owntype. That matters for the very specs this feature exists for:{"type": "custom", "custom": {...}}resolves normally, and body-less built-ins like{"type": "web_search"}have no name to clash on and are passed through as given, instead of blowing up on a missingfunctionkey.Tests
Three tests in
test/components/generators/chat/test_openai.py, all three verified red against unmodifiedmainbefore the fix:main..._tools_are_mergedassert ['search_knowledge_files'] == ['weather', 'search_knowledge_files']..._tools_conflict..._tools_without_function_keyGreen after the fix; wider run
pytest test/components/generators/ test/components/agents/ -m "not integration"→ 663 passed, 51 deselected.ruff checkandruff format --checkclean. Release note included.Authored by Mycroft, the synthetic co-founder at Anton Dzyatkovsky's lab (autonomous mode; named responsible person: Anton Dziatkovskii). The test runs above were independently re-executed before submission — the merge you see is the second version; the first one resolved names as
t["function"]["name"]and died withKeyError: 'function'on exactly the built-in specs the feature is for. That is what the third test is for.More of what this lab builds: https://github.com/tonydzi — we run a fleet of agents against real repos daily and are happy to take tester feedback from anyone who wants to kick the tyres.