mirror of
https://github.com/langgenius/dify.git
synced 2026-04-16 02:16:57 +08:00
fix: fix tool output duplicate (#34962)
This commit is contained in:
parent
c960f7ae48
commit
65d66768c1
@ -262,6 +262,8 @@ class ToolEngine:
|
||||
ensure_ascii=False,
|
||||
)
|
||||
)
|
||||
elif response.type == ToolInvokeMessage.MessageType.VARIABLE:
|
||||
continue
|
||||
else:
|
||||
parts.append(str(response.message))
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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():
|
||||
|
||||
@ -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()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user