Skip to content

Commit 1358705

Browse files
sjrlmpangrazzi
authored andcommitted
fix: Fix parameter schema generation in ComponentTool when using inputs_from_state (#9795)
* Fix for removing parameters from the parameters schema when using inputs_from_state * Add reno
1 parent a2a0df3 commit 1358705

3 files changed

Lines changed: 15 additions & 1 deletion

File tree

haystack/tools/component_tool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ def _create_tool_parameters_schema(self, component: Component, inputs_from_state
278278
fields: dict[str, Any] = {}
279279

280280
for input_name, socket in component.__haystack_input__._sockets_dict.items(): # type: ignore[attr-defined]
281-
if inputs_from_state is not None and input_name in inputs_from_state:
281+
if inputs_from_state is not None and input_name in list(inputs_from_state.values()):
282282
continue
283283
input_type = socket.type
284284
description = param_descriptions.get(input_name, f"Input '{input_name}' for the component.")
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
fixes:
3+
- |
4+
Fixed parameter schema generation in `ComponentTool` when using `inputs_from_state`. Previously, parameters were only removed from the schema if the state key and parameter name matched exactly. For example, `inputs_from_state={"text": "text"}` removed `text` as expected, but `inputs_from_state={"state_text": "text"}` did not. This is now resolved, and such cases work as intended.

test/tools/test_component_tool.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,16 @@ def test_from_component_with_inputs_from_state(self):
184184
"description": "A simple component that generates text.",
185185
}
186186

187+
def test_from_component_with_inputs_from_state_different_names(self):
188+
tool = ComponentTool(component=SimpleComponent(), inputs_from_state={"state_text": "text"})
189+
assert tool.inputs_from_state == {"state_text": "text"}
190+
# Inputs should be excluded from schema generation
191+
assert tool.parameters == {
192+
"type": "object",
193+
"properties": {},
194+
"description": "A simple component that generates text.",
195+
}
196+
187197
def test_from_component_with_outputs_to_state(self):
188198
tool = ComponentTool(component=SimpleComponent(), outputs_to_state={"replies": {"source": "reply"}})
189199
assert tool.outputs_to_state == {"replies": {"source": "reply"}}

0 commit comments

Comments
 (0)