Skip to content

fix(generators): merge tools from generation_kwargs with component tools - #12838

Closed
Rainmemery wants to merge 1 commit into
deepset-ai:mainfrom
Rainmemery:fix/merge-tools-from-generation-kwargs
Closed

Rainmemery wants to merge 1 commit into
deepset-ai:mainfrom
Rainmemery:fix/merge-tools-from-generation-kwargs

Conversation

@Rainmemery

Copy link
Copy Markdown
Contributor

Fixes #12832.

Problem

OpenAIChatGenerator._prepare_api_call and OpenAIResponsesChatGenerator assemble the request payload as {**openai_tools, **generation_kwargs}. Because generation_kwargs is spliced last, a tools key in it replaces the definitions built from the component's own tools instead 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 as tools are 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_kwargs wins, mirroring how every other generation_kwargs key already takes precedence.

Applies to:

  • OpenAIChatGenerator
  • OpenAIResponsesChatGenerator
  • AzureOpenAIChatGenerator / AzureOpenAIResponsesChatGenerator (inherited)

Testing

  • New regression tests in test/components/generators/chat/test_openai.py and test/components/generators/chat/test_openai_responses.py:
    • tools in generation_kwargs merge with the component's own tools;
    • on name collision the generation_kwargs spec wins.
  • Full chat generator suites pass (101 passed).

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
Rainmemery requested a review from a team as a code owner September 21, 2026 10:34
@Rainmemery
Rainmemery requested review from julian-risch and removed request for a team September 21, 2026 10:34
@vercel

vercel Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

@Rainmemery is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

Copy link
Copy Markdown
Contributor

Hi @Rainmemery, thanks for your interest in contributing to Haystack! 🙏

⚠️ You currently have 3 open pull requests in this repository (#12837, #12733 and this one). Our review capacity is limited, so please hold off opening more PRs until we've had a chance to review your first 2 open PRs. This helps us give each contribution the attention it deserves. Thank you!

This is an automated message to help us keep the review queue healthy.

@github-actions github-actions Bot added topic:tests type:documentation Improvements on the docs labels Sep 21, 2026
@sjrl

sjrl commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Hey @Rainmemery we appreciate the contribution! However, this is something we want to handle internally so I'll be closing this PR.

@sjrl sjrl closed this Sep 21, 2026
@Rainmemery

Copy link
Copy Markdown
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic:tests type:documentation Improvements on the docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenAIChatGenerator: tools in generation_kwargs silently drop the component's own tools

2 participants