From cd7c68372b313ba3a86d599fb89fc61b18c9a2e7 Mon Sep 17 00:00:00 2001 From: mathislucka Date: Tue, 18 Feb 2025 11:23:26 +0100 Subject: [PATCH] fix: ComponentTool description should not be truncated (#8870) * fix: description should not be truncated * chore: add release note --- haystack/tools/component_tool.py | 4 +--- .../fix-tool-description-truncation-011e8275fea4ccb0.yaml | 4 ++++ test/tools/test_component_tool.py | 6 ++++++ 3 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 releasenotes/notes/fix-tool-description-truncation-011e8275fea4ccb0.yaml diff --git a/haystack/tools/component_tool.py b/haystack/tools/component_tool.py index cc77ceca0..93e384c37 100644 --- a/haystack/tools/component_tool.py +++ b/haystack/tools/component_tool.py @@ -152,9 +152,7 @@ class ComponentTool(Tool): ] ).lstrip("_") - # Generate a description for the tool if not provided and truncate to 512 characters - # as most LLMs have a limit for the description length - description = (description or component.__doc__ or name)[:512] + description = description or component.__doc__ or name # Create the Tool instance with the component invoker as the function to be called and the schema super().__init__(name, description, tool_schema, component_invoker) diff --git a/releasenotes/notes/fix-tool-description-truncation-011e8275fea4ccb0.yaml b/releasenotes/notes/fix-tool-description-truncation-011e8275fea4ccb0.yaml new file mode 100644 index 000000000..7e09c17c2 --- /dev/null +++ b/releasenotes/notes/fix-tool-description-truncation-011e8275fea4ccb0.yaml @@ -0,0 +1,4 @@ +--- +fixes: + - | + ComponentTool does not truncate 'description' anymore. diff --git a/test/tools/test_component_tool.py b/test/tools/test_component_tool.py index 38f4e2046..4c0033e04 100644 --- a/test/tools/test_component_tool.py +++ b/test/tools/test_component_tool.py @@ -142,6 +142,12 @@ class TestToolComponent: assert "reply" in result assert result["reply"] == "Hello, world!" + def test_from_component_long_description(self): + component = SimpleComponent() + tool = ComponentTool(component=component, description="".join(["A"] * 1024)) + + assert len(tool.description) == 1024 + def test_from_component_with_dataclass(self): component = UserGreeter()