Skip to content

Conversation

@vblagoje
Copy link
Member

@vblagoje vblagoje commented Oct 22, 2025

Why:

Adopts Haystack's ToolsType to enable flexible tool composition, developers can now mix individual Tool objects and Toolset instances in a single list

part of:

What:

  • Updated tools parameter from Union[List[Tool], Toolset] to ToolsType in constructor and all methods
  • Replaced manual isinstance(tools, Toolset) checks with flatten_tools_or_toolsets() utility
  • Haystack dependency to 2.19.0 for ToolsType support
  • Added tests for mixed tool collection initialization and request parameter formatting

How can it be used:

from haystack.tools import Tool, Toolset
from haystack_integrations.components.generators.ollama.chat import OllamaChatGenerator

weather_tool = Tool(name="weather", ...)
population_toolset = Toolset([...])

# NEW: Mix Tool and Toolset freely
generator = OllamaChatGenerator(tools=[weather_tool, population_toolset])

How did you test it:

  • Unit tests verify mixed tool initialization and correct Ollama tools formatting
  • Backward compatibility validated for existing patterns (list of tools, single toolset)
  • Integration test test_live_run_with_mixed_tools() demonstrates end-to-end LLM tool invocation from mixed collections

Notes for the reviewer:

  • Centralizes tool normalization logic with flatten_tools_or_toolsets()—eliminates duplicate handling code
  • Fully backward compatible; no migration needed
  • Ollama-specific: Tools are properly serialized to Ollama's expected format with {"type": "function", "function": {**tool.tool_spec}}
  • Added comprehensive test coverage for mixed tool scenarios including both unit and integration tests

@vblagoje vblagoje requested a review from a team as a code owner October 22, 2025 09:46
@vblagoje vblagoje requested review from mpangrazzi and removed request for a team October 22, 2025 09:46
@github-actions github-actions bot added integration:ollama type:documentation Improvements or additions to documentation labels Oct 22, 2025
@vblagoje vblagoje requested a review from anakin87 October 22, 2025 12:21
@vblagoje
Copy link
Member Author

@anakin87 can you also please look at these files?

@vblagoje vblagoje removed the request for review from mpangrazzi October 22, 2025 12:21
@anakin87
Copy link
Member

@anakin87 can you also please look at these files?

Which files?

@vblagoje
Copy link
Member Author

@anakin87 can you also please look at these files?

Which files?

Sorry I meant this PR 🤦

Copy link
Member

@anakin87 anakin87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@vblagoje vblagoje merged commit e4ee1c8 into main Oct 22, 2025
8 of 9 checks passed
@vblagoje vblagoje deleted the ollama-toolstype branch October 22, 2025 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration:ollama type:documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants