fix(generators): merge tools from generation_kwargs with component tools - #12838
Rainmemery wants to merge 1 commit into
Conversation
OpenAIChatGenerator._prepare_api_call and OpenAIResponsesChatGenerator splice the
payload as {**openai_tools, **generation_kwargs}. A "tools" key in generation_kwargs
therefore replaces the definitions built from the component's own tools instead of
being added to them, silently dropping the component's tools.
Merge the two instead: for a tool name present in both, the spec given in
generation_kwargs wins, mirroring how every other generation_kwargs key takes
precedence. Applies to OpenAIChatGenerator, OpenAIResponsesChatGenerator and their
Azure subclasses.
Adds regression tests for both generators covering the merge and the name-collision
precedence.
|
@Rainmemery is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
|
Hi @Rainmemery, thanks for your interest in contributing to Haystack! 🙏 This is an automated message to help us keep the review queue healthy. |
|
Hey @Rainmemery we appreciate the contribution! However, this is something we want to handle internally so I'll be closing this PR. |
|
Understood, thanks for letting me know @sjrl! I will close this PR. The fix itself (merging tools from generation_kwargs with the component tools) is also reproducible independently in OpenAIResponsesChatGenerator, so happy to leave it to the team. Thanks for taking a look. |
Fixes #12832.
Problem
OpenAIChatGenerator._prepare_api_callandOpenAIResponsesChatGeneratorassemble the request payload as{**openai_tools, **generation_kwargs}. Becausegeneration_kwargsis spliced last, atoolskey in it replaces the definitions built from the component's owntoolsinstead of being added to them. A caller who passes extra OpenAI tool specs alongside Haystack tools ends up advertising only the former, and the tools it passed astoolsare silently dropped.Fix
Merge the two instead of letting one override the other. For a tool name present in both, the spec given in
generation_kwargswins, mirroring how every othergeneration_kwargskey already takes precedence.Applies to:
OpenAIChatGeneratorOpenAIResponsesChatGeneratorAzureOpenAIChatGenerator/AzureOpenAIResponsesChatGenerator(inherited)Testing
test/components/generators/chat/test_openai.pyandtest/components/generators/chat/test_openai_responses.py:generation_kwargsmerge with the component's own tools;generation_kwargsspec wins.