Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix tool_inputs parse error in message that in CoT(ReAct) agent mode (#2949)

listengd70bd4aaa440
diff --git a/api/core/features/assistant_base_runner.py b/api/core/features/assistant_base_runner.py
index b43d1cd40ed..5feee64db1b 100644
--- a/api/core/features/assistant_base_runner.py
+++ b/api/core/features/assistant_base_runner.py
@@ -566,7 +566,11 @@ class BaseAssistantApplicationRunner(AppRunner):
tools = tools.split(';')
tool_calls: list[AssistantPromptMessage.ToolCall] = []
tool_call_response: list[ToolPromptMessage] = []
- tool_inputs = json.loads(agent_thought.tool_input)
+ try:
+ tool_inputs = json.loads(agent_thought.tool_input)
+ except Exception as e:
+ logging.warning("tool execution error: {}, tool_input: {}.".format(str(e), agent_thought.tool_input))
+ tool_inputs = { agent_thought.tool: agent_thought.tool_input }
for tool in tools:
# generate a uuid for tool call
tool_call_id = str(uuid.uuid4())
@@ -599,4 +603,4 @@ class BaseAssistantApplicationRunner(AppRunner):
db.session.close()
- return result
\ No newline at end of file
+ return result
diff --git a/api/core/features/assistant_cot_runner.py b/api/core/features/assistant_cot_runner.py
index 3762ddcf62e..6d43d846e47 100644
--- a/api/core/features/assistant_cot_runner.py
+++ b/api/core/features/assistant_cot_runner.py
@@ -182,7 +182,7 @@ class AssistantCotApplicationRunner(BaseAssistantApplicationRunner):
delta=LLMResultChunkDelta(
index=0,
message=AssistantPromptMessage(
- content=json.dumps(chunk)
+ content=json.dumps(chunk, ensure_ascii=False) # if ensure_ascii=True, the text in webui maybe garbled text
),
usage=None
)
@@ -667,4 +667,4 @@ class AssistantCotApplicationRunner(BaseAssistantApplicationRunner):
try:
return json.dumps(tools, ensure_ascii=False)
except json.JSONDecodeError:
- return json.dumps(tools)
\ No newline at end of file
+ return json.dumps(tools)