fix: fix tool output duplicate (#34962)

This commit is contained in:
wangxiaolei 2026-04-11 23:07:31 +08:00 committed by GitHub
parent c960f7ae48
commit 65d66768c1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 25 additions and 2 deletions

View File

@ -262,6 +262,8 @@ class ToolEngine:
ensure_ascii=False,
)
)
elif response.type == ToolInvokeMessage.MessageType.VARIABLE:
continue
else:
parts.append(str(response.message))

View File

@ -17,10 +17,8 @@ class WorkflowToolConfigurationUtils:
"""
nodes = graph.get("nodes", [])
start_node = next(filter(lambda x: x.get("data", {}).get("type") == "start", nodes), None)
if not start_node:
return []
return [VariableEntity.model_validate(variable) for variable in start_node.get("data", {}).get("variables", [])]
@classmethod

View File

@ -84,6 +84,7 @@ class WorkflowToolManageService:
try:
WorkflowToolProviderController.from_db(workflow_tool_provider)
except Exception as e:
logger.warning(e, exc_info=True)
raise ValueError(str(e))
with Session(db.engine, expire_on_commit=False) as session, session.begin():

View File

@ -260,6 +260,28 @@ def test_agent_invoke_engine_meta_error():
assert error_meta.error == "meta failure"
def test_convert_tool_response_excludes_variable_messages():
"""Regression test for issue #34723.
WorkflowTool._invoke yields VARIABLE, TEXT, and suppressed-JSON messages.
_convert_tool_response_to_str must skip VARIABLE messages so that the
returned string contains only the TEXT representation and not a
duplicated, garbled Pydantic repr of the same data.
"""
tool = _build_tool()
outputs = {"reports": "hello"}
messages = [
tool.create_variable_message(variable_name="reports", variable_value="hello"),
tool.create_text_message('{"reports": "hello"}'),
tool.create_json_message(outputs, suppress_output=True),
]
result = ToolEngine._convert_tool_response_to_str(messages)
assert result == '{"reports": "hello"}'
assert "variable_name" not in result
def test_agent_invoke_tool_invoke_error():
tool = _build_tool(with_llm_parameter=True)
callback = Mock()