mirror of
https://github.com/langgenius/dify-official-plugins.git
synced 2026-07-22 01:55:27 -04:00
agent functioncalling JSONDecodeError #160
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @planwk on GitHub (Apr 1, 2025).
Self Checks
Dify version
1.1.3
Cloud or Self Hosted
Self Hosted (Docker)
Steps to reproduce
I created an agent with the strategy of function calling. This strategy often appears before calling the tool and reports the following error:
Run failed: Failed to transform agent message: PluginInvokeError: {"args":{},"error_type":"JSONDecodeError","message":"Expecting ':' delimiter: line 1 column 5 (char 4)"}
The JSON format is not compliant as specified by prompts. How to solve this problem? If one wants to track more detailed information, how to set it up?
✔️ Expected Behavior
No response
❌ Actual Behavior
No response
@dosubot[bot] commented on GitHub (Apr 1, 2025):
Hello @planwk! I'm here to help you with bugs, questions, and becoming a contributor. Feel free to ask anything you need assistance with while waiting for a human maintainer.
To solve the
JSONDecodeErroryou're encountering with the function calling strategy in your self-hosted Dify agent, ensure that the JSON data being processed is correctly formatted. This error typically occurs when the JSON data is not properly structured. You can add logging to capture the problematic JSON data before attempting to decode it, which will help you track more detailed information about the error.Here's how you can modify your code to include logging for debugging purposes:
Additionally, ensure that when converting tool calls to JSON, you handle potential encoding issues by using
ensure_ascii=Falseinjson.dumps:By adding these logging statements and ensuring proper JSON encoding, you can capture the exact JSON data causing the
JSONDecodeError, which will help you diagnose and fix the issue [1][2].To continue talking to Dosu, mention @dosu.
Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other
@planwk commented on GitHub (Apr 1, 2025):
Where should I add these codes? I'm deploying with Docker.
@planwk commented on GitHub (Apr 2, 2025):
@dosu Where should I add these codes? I'm deploying with Docker.Where to add the agent node in dify
@leslie2046 commented on GitHub (Apr 2, 2025):
@planwk Which model and provider do you use?Can you take a screenshot ?
@junjiem commented on GitHub (Apr 2, 2025):
@leslie2046 qwen-max series will have this problem
dify 1.1.3
tongyi plugin 0.0.14
@planwk commented on GitHub (Apr 2, 2025):
The qwen-plus also has this problem. But why is the agent function calling not supported by qwen2.5-72b-instruct? I can use Langchain and it is supported. Also, how can I add detailed logs for viewing in the agent?
@leslie2046 commented on GitHub (Apr 2, 2025):
Sometime entercounted in siliconflow qwen2.5 series.
2025-04-03 02:38:42,976 ERROR [app_generator.py:257] c4e8655810 Error when generating
Traceback (most recent call last):
File "/home/leslie/chatgpt/dify/api/core/app/apps/agent_chat/app_generator.py", line 240, in _generate_worker
runner.run(
File "/home/leslie/chatgpt/dify/api/core/app/apps/agent_chat/app_runner.py", line 245, in run
self._handle_invoke_result(
File "/home/leslie/chatgpt/dify/api/core/app/apps/base_app_runner.py", line 278, in _handle_invoke_result
self._handle_invoke_result_stream(invoke_result=invoke_result, queue_manager=queue_manager, agent=agent)
File "/home/leslie/chatgpt/dify/api/core/app/apps/base_app_runner.py", line 313, in _handle_invoke_result_stream
for result in invoke_result:
^^^^^^^^^^^^^
File "/home/leslie/chatgpt/dify/api/core/agent/fc_agent_runner.py", line 123, in run
tool_calls.extend(self.extract_tool_calls(chunk) or [])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/leslie/chatgpt/dify/api/core/agent/fc_agent_runner.py", line 344, in extract_tool_calls
args = json.loads(prompt_message.function.arguments)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/leslie/anaconda3/envs/dify/lib/python3.12/json/__init__.py", line 346, in loads
return _default_decoder.decode(s)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/leslie/anaconda3/envs/dify/lib/python3.12/json/decoder.py", line 341, in decode
raise JSONDecodeError("Extra data", s, end)
json.decoder.JSONDecodeError: Extra data: line 1 column 4 (char 3)
2025-04-03 02:38:42,978 DEBUG [based_generate_task_pipeline.py:45] ed092e634b error: Extra data: line 1 column 4 (char 3)
@planwk commented on GitHub (Apr 2, 2025):
Here, we cannot obtain the online version of qwen2.5-72b-instruct. We can only choose qwen-plus or qwen-max, and both of them have this problem.
@planwk commented on GitHub (Apr 2, 2025):
It's 72b.
@leslie2046 commented on GitHub (Apr 2, 2025):
https://github.com/langgenius/dify-official-plugins/blob/main/models/tongyi/models/llm/qwen2.5-72b-instruct.yaml#L7
@planwk should add 2 features
@junjiem commented on GitHub (Apr 2, 2025):
my env, no problem with qwen2.5-72b, only qwen-max has problem
@planwk commented on GitHub (Apr 2, 2025):
How should I proceed with the modification? Should I re-download the plugin and install it offline, or modify the configuration?
@planwk commented on GitHub (Apr 2, 2025):
Is that so?Still not working.
@planwk commented on GitHub (Apr 2, 2025):
@leslie2046 Still not working.
@leslie2046 commented on GitHub (Apr 3, 2025):
@planwk commented on GitHub (Apr 3, 2025):
Later on, I made some changes, but it still doesn't show up.
@planwk commented on GitHub (Apr 3, 2025):
@leslie2046
@planwk commented on GitHub (Apr 3, 2025):
@junjiem Could you please tell me how to select Qwen2.5-72b for the agent in Chatflow? I'm deploying it via Docker.
@junjiem commented on GitHub (Apr 3, 2025):
your tongyi plugin version?
@planwk commented on GitHub (Apr 3, 2025):
0.0.14
@junjiem commented on GitHub (Apr 3, 2025):
That's strange. Have you changed the source code?
@planwk commented on GitHub (Apr 3, 2025):
@junjiem commented on GitHub (Apr 3, 2025):
Just released 0.0.15, I upgraded and found the problem disappeared.
It should be that the dependency version is too old, and the only relevant thing in 0.0.15 is that the dependency package is upgraded here.
@junjiem commented on GitHub (Apr 3, 2025):
I'm aware of your problem. Chatflow Agent You have selected the Function Calling strategy so Qwen2.5-72b cannot be selected. Qwen2.5-72b does not support Function Calling.
@planwk commented on GitHub (Apr 3, 2025):
Qwen2.5-72b I'm using Langchain and it supports Function Calling. Moreover, tools can also be invoked within the agent application.
The above contains screenshots based on the Qwen2.5-72b agent
@junjiem commented on GitHub (Apr 3, 2025):
I may not have described the problem correctly. but Qwen2.5-72b does not support Function Calling. Agent application qwen2.5-72b is use ReAct.
@planwk commented on GitHub (Apr 3, 2025):
This should also be a function call, right?
@junjiem commented on GitHub (Apr 3, 2025):
You need to learn the differences and similarities between ReAct and Function Calling. I put together a picture for you to look at
@planwk commented on GitHub (Apr 3, 2025):
OK. Thank you.But I can do it with the function calling feature of the Langchain framework.
@ChronosLiu commented on GitHub (Apr 4, 2025):
When using the tool call, the incremental_output is always set to false. However, when processing the response results, the function name and parameters are repeatedly concatenated.
Refer to the log details in the issue I mentioned
https://github.com/langgenius/dify-official-plugins/issues/616
@Korayem commented on GitHub (Jul 14, 2025):
@junjiem
How can i change an Agent Strategy? I notice it defaults to Function Calling and UI doesnt allow me to change it to ReAct