add-component-tool-ffe9f9911ea055a6.yaml
1 --- 2 highlights: | 3 Introduced ComponentTool, a powerful addition to the Haystack tooling architecture that enables any Haystack component to be used as a tool by LLMs. 4 ComponentTool bridges the gap between Haystack's component ecosystem and LLM tool/function calling capabilities, allowing LLMs to 5 directly interact with components like web search, document processing, or any custom user component. ComponentTool handles 6 all the complexity of schema generation and type conversion, making it easy to expose component functionality to LLMs. 7 8 features: 9 - | 10 Introduced the ComponentTool, a new tool that wraps Haystack components allowing them to be utilized as tools for LLMs (various ChatGenerators). 11 This ComponentTool supports automatic tool schema generation, input type conversion, and offering support for components with run methods that have input types: 12 - Basic types (str, int, float, bool, dict) 13 - Dataclasses (both simple and nested structures) 14 - Lists of basic types (e.g., List[str]) 15 - Lists of dataclasses (e.g., List[Document]) 16 - Parameters with mixed types (e.g., List[Document], str etc.) 17 18 Example usage: 19 ```python 20 from haystack.components.websearch import SerperDevWebSearch 21 from haystack.tools import ComponentTool 22 from haystack.utils import Secret 23 24 # Create a SerperDev search component 25 search = SerperDevWebSearch( 26 api_key=Secret.from_token("your-api-key"), 27 top_k=3 28 ) 29 30 # Create a tool from the component 31 tool = ComponentTool( 32 component=search, 33 name="web_search", # Optional: defaults to "serper_dev_web_search" 34 description="Search the web for current information" # Optional: defaults to component docstring 35 ) 36 37 # You can now use the tool now in a pipeline, see docs for more examples 38 ```