Skip to content

Update Chat Generators to support mixed Tools and Toolsets #2409

@vblagoje

Description

@vblagoje

Background

In Haystack 2.19 we enhanced the tools parameter across all chat generators to accept Optional[Union[list[Union[Tool, Toolset]], Toolset]] (defined as ToolsType).

This enhancement allows users to:

  • Pass a mixed list of Tool and Toolset objects
  • Pass a single Toolset object directly
  • Combine multiple toolsets with standalone tools in the same list

Previous limitation: Components required either a list of Tool objects OR a single Toolset, but not both in the same list.

New capability: Users can now organize tools into logical Toolsets while also including standalone Tool objects, providing greater flexibility. For example:

generator = OpenAIChatGenerator(
    tools=[math_toolset, weather_toolset, standalone_tool]
)

This change is fully backward compatible and preserves structure during serialization/deserialization.

Required Changes

All chat generators in haystack-core-integrations that support tools need to be updated to use the new ToolsType format. Based on the current inventory, the following integrations need updates:

Generators with Tool Support

  • amazon-bedrock-haystack - AmazonBedrockChatGenerator
  • anthropic-haystack - AnthropicChatGenerator
  • cohere-haystack - CohereChatGenerator
  • google-genai-haystack - Chat generators
  • llama-cpp-haystack - LlamaCppChatGenerator
  • llama-stack-haystack - Chat generators
  • meta-llama-haystack - Chat generators
  • mistral-haystack - MistralChatGenerator
  • nvidia-haystack - Chat generators
  • ollama-haystack - OllamaChatGenerator
  • openrouter-haystack - Chat generators
  • [ ] stackit-haystack - Chat generators tools not supported
  • togetherai-haystack - Chat generators
  • [ ] watsonx-haystack - Chat generators tools not supported

Reference Implementation

See the Haystack core implementations for complete examples:

Testing Considerations

Each integration should add tests to verify:

  1. Accepting a list of Tool objects (existing behavior)
  2. Accepting a single Toolset object (existing behavior)
  3. Accepting a mixed list of Tool and Toolset objects (new capability)
  4. Proper serialization/deserialization of all three formats
  5. Detection of duplicate tool names across tools and toolsets

Acceptance Criteria

  • All chat generators with tool support are updated to use ToolsType
  • All affected integrations pass existing tests
  • New tests added for mixed tools/toolsets functionality
  • Documentation updated to reflect the new capability
  • No breaking changes to existing APIs

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions