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 incorrect exception reference for `json.dumps()` (#24329)

Yongtao Huang1d09708eb7e8
diff --git a/api/core/agent/cot_agent_runner.py b/api/core/agent/cot_agent_runner.py
index 565fb424788..6cb1077126a 100644
--- a/api/core/agent/cot_agent_runner.py
+++ b/api/core/agent/cot_agent_runner.py
@@ -197,7 +197,7 @@ class CotAgentRunner(BaseAgentRunner, ABC):
final_answer = scratchpad.action.action_input
else:
final_answer = f"{scratchpad.action.action_input}"
- except json.JSONDecodeError:
+ except TypeError:
final_answer = f"{scratchpad.action.action_input}"
else:
function_call_state = True
diff --git a/api/core/agent/fc_agent_runner.py b/api/core/agent/fc_agent_runner.py
index 4e6fe60e576..9eb853aa746 100644
--- a/api/core/agent/fc_agent_runner.py
+++ b/api/core/agent/fc_agent_runner.py
@@ -126,8 +126,8 @@ class FunctionCallAgentRunner(BaseAgentRunner):
tool_call_inputs = json.dumps(
{tool_call[1]: tool_call[2] for tool_call in tool_calls}, ensure_ascii=False
)
- except json.JSONDecodeError:
- # ensure ascii to avoid encoding error
+ except TypeError:
+ # fallback: force ASCII to handle non-serializable objects
tool_call_inputs = json.dumps({tool_call[1]: tool_call[2] for tool_call in tool_calls})
if chunk.delta.message and chunk.delta.message.content:
@@ -153,8 +153,8 @@ class FunctionCallAgentRunner(BaseAgentRunner):
tool_call_inputs = json.dumps(
{tool_call[1]: tool_call[2] for tool_call in tool_calls}, ensure_ascii=False
)
- except json.JSONDecodeError:
- # ensure ascii to avoid encoding error
+ except TypeError:
+ # fallback: force ASCII to handle non-serializable objects
tool_call_inputs = json.dumps({tool_call[1]: tool_call[2] for tool_call in tool_calls})
if result.usage: