Agent cannot correctly parse "tool_calls" in multiple rounds of conversation #4869

Closed
opened 2026-02-21 18:08:22 -05:00 by yindo · 7 comments
Owner

Originally created by @lidajiededa on GitHub (Aug 2, 2024).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.6.15

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

Model

qwen-2-72B

Problems

During the process of using agents for function calls and multiple rounds of conversations, we found that the latter few rounds of conversations would produce abnormal responses. By examining the database, we found that there is an issue with ("tool_calls" ->"function" ->"arguments") when retrieving history in multiple rounds of conversations. We let the arguments be a json list with 2 attributes -- 'action' and 'demand'. The 'tool_calls' result is rightly shown, but in the second and three rounds of conversation, agent should first get the histroy results. We found that there are '\\'s in 'arguments':

"arguments": "{\"preferences\": \"[{'action': '\\u963b\\u6b62', 'demand': '\\u65b0\\u4eac\\u62a5'}]\"}"}}

The correct one should be
`"arguments": "{"preferences": "[{'action': '\u963b\u6b62', 'demand': '\u65b0\u4eac\u62a5'}]"}"}}

This situation will lead to abnormal performance of the agent in the later rounds.

This issue may be caused by encoding problems during the reading and writing of history in multiple rounds of dialogue.

The following are the database records and the results after decoding. We can see that there are '\\'s in the 'arguments', ade there is a problem with the output of the last two rounds, as it outputs' 英阳联盟' instead of '英雄联盟'

`### Database records

round1

[{"role": "user", "text": "\u4e0d\u60f3\u770b\u65b0\u4eac\u62a5", "files": []}, {"role": "assistant", "text": "", "files": [], "tool_calls": [{"id": "call_8a7e093f-8938-4d7c-81ac-65e43aa8fa3b", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\u963b\u6b62', 'demand': '\u65b0\u4eac\u62a5'}]\"}"}}]}, {"role": "tool", "text": "{\"profile\": [{\"granularity\": \"TNAME\", \"type\": \"ALL\", \"content\": \"T1486538331796\", \"priority\": -1.0}], \"message\": \"\u5df2\u7ecf\u6839\u636e\u60a8\u7684\u5429\u5490\u8c03\u6574\u4e86\u63a8\u8350\u6a21\u5f0f\uff0c\u73b0\u5728\u60a8\u53ef\u4ee5\u53bb\u4e00\u63a2\u7a76\u7adf\u5566\uff01\"}", "files": [], "tool_calls": [{"id": "call_8a7e093f-8938-4d7c-81ac-65e43aa8fa3b", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\u963b\u6b62', 'demand': '\u65b0\u4eac\u62a5'}]\"}"}}]}]

round2

[{"role": "user", "text": "\u4e0d\u60f3\u770b\u65b0\u4eac\u62a5", "files": []}, {"role": "assistant", "text": "\u7528\u6237\u8868\u8fbe\u4e86\u4e0d\u60f3\u770b\u6765\u81ea\u201c\u65b0\u4eac\u62a5\u201d\u7684\u5185\u5bb9\uff0c\u8fd9\u6d89\u53ca\u5230\u8c03\u6574\u63a8\u8350\u5185\u5bb9\uff0c\u963b\u6b62\u7279\u5b9a\u6765\u6e90\u7684\u4fe1\u606f\u3002", "files": [], "tool_calls": [{"id": "a7455157-a8ea-4a7c-8d21-529de2fdab0b", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\\u963b\\u6b62', 'demand': '\\u65b0\\u4eac\\u62a5'}]\"}"}}]}, {"role": "tool", "text": "{\"profile\": [{\"granularity\": \"TNAME\", \"type\": \"ALL\", \"content\": \"T1486538331796\", \"priority\": -1.0}], \"message\": \"\u5df2\u7ecf\u6839\u636e\u60a8\u7684\u5429\u5490\u8c03\u6574\u4e86\u63a8\u8350\u6a21\u5f0f\uff0c\u73b0\u5728\u60a8\u53ef\u4ee5\u53bb\u4e00\u63a2\u7a76\u7adf\u5566\uff01\"}", "files": [], "tool_calls": [{"id": "a7455157-a8ea-4a7c-8d21-529de2fdab0b", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\\u963b\\u6b62', 'demand': '\\u65b0\\u4eac\\u62a5'}]\"}"}}]}, {"role": "assistant", "text": "\u6211\u5df2\u7ecf\u5e2e\u60a8\u8bbe\u7f6e\u597d\u4e86\uff0c\u60a8\u5c06\u4e0d\u518d\u770b\u5230\u65b0\u4eac\u62a5\u7684\u76f8\u5173\u4fe1\u606f\u3002", "files": []}, {"role": "user", "text": "\u60f3\u770b\u82f1\u96c4\u8054\u76df", "files": []}, {"role": "assistant", "text": "", "files": [], "tool_calls": [{"id": "call_3eb89cec-17f8-4cf6-beb3-f0883b6a1386", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\u589e\u52a0', 'demand': '\u82f1\u9633\u8054\u76df'}]\"}"}}]}, {"role": "tool", "text": "{\"message\": \"\u6536\u5230\u60a8\u7684\u5429\u5490\u4e86\uff0c\u53ef\u8fd9\u4e2a\u8981\u6c42\u597d\u96be\uff0c\u6682\u65f6\u505a\u4e0d\u5230\uff0c\u8bf7\u6362\u4e2a\u8bf4\u6cd5\u8bd5\u8bd5\uff01\"}", "files": [], "tool_calls": [{"id": "call_3eb89cec-17f8-4cf6-beb3-f0883b6a1386", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\u589e\u52a0', 'demand': '\u82f1\u9633\u8054\u76df'}]\"}"}}]}]

round3

[{"role": "user", "text": "\u4e0d\u60f3\u770b\u65b0\u4eac\u62a5", "files": []}, {"role": "assistant", "text": "\u7528\u6237\u8868\u8fbe\u4e86\u4e0d\u60f3\u770b\u6765\u81ea\u201c\u65b0\u4eac\u62a5\u201d\u7684\u5185\u5bb9\uff0c\u8fd9\u6d89\u53ca\u5230\u8c03\u6574\u63a8\u8350\u5185\u5bb9\uff0c\u963b\u6b62\u7279\u5b9a\u6765\u6e90\u7684\u4fe1\u606f\u3002", "files": [], "tool_calls": [{"id": "222fed6b-c2fc-416d-8e0a-60c2d38a0a67", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\\u963b\\u6b62', 'demand': '\\u65b0\\u4eac\\u62a5'}]\"}"}}]}, {"role": "tool", "text": "{\"profile\": [{\"granularity\": \"TNAME\", \"type\": \"ALL\", \"content\": \"T1486538331796\", \"priority\": -1.0}], \"message\": \"\u5df2\u7ecf\u6839\u636e\u60a8\u7684\u5429\u5490\u8c03\u6574\u4e86\u63a8\u8350\u6a21\u5f0f\uff0c\u73b0\u5728\u60a8\u53ef\u4ee5\u53bb\u4e00\u63a2\u7a76\u7adf\u5566\uff01\"}", "files": [], "tool_calls": [{"id": "222fed6b-c2fc-416d-8e0a-60c2d38a0a67", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\\u963b\\u6b62', 'demand': '\\u65b0\\u4eac\\u62a5'}]\"}"}}]}, {"role": "assistant", "text": "\u6211\u5df2\u7ecf\u5e2e\u60a8\u8bbe\u7f6e\u597d\u4e86\uff0c\u60a8\u5c06\u4e0d\u518d\u770b\u5230\u65b0\u4eac\u62a5\u7684\u76f8\u5173\u4fe1\u606f\u3002", "files": []}, {"role": "user", "text": "\u60f3\u770b\u82f1\u96c4\u8054\u76df", "files": []}, {"role": "assistant", "text": "I can use ai_agent_profile.", "files": [], "tool_calls": [{"id": "8613338c-5e89-4e11-b675-762011a74f7e", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\\u589e\\u52a0', 'demand': '\\u82f1\\u9633\\u8054\\u76df'}]\"}"}}]}, {"role": "tool", "text": "{\"message\": \"\u6536\u5230\u60a8\u7684\u5429\u5490\u4e86\uff0c\u53ef\u8fd9\u4e2a\u8981\u6c42\u597d\u96be\uff0c\u6682\u65f6\u505a\u4e0d\u5230\uff0c\u8bf7\u6362\u4e2a\u8bf4\u6cd5\u8bd5\u8bd5\uff01\"}", "files": [], "tool_calls": [{"id": "8613338c-5e89-4e11-b675-762011a74f7e", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\\u589e\\u52a0', 'demand': '\\u82f1\\u9633\\u8054\\u76df'}]\"}"}}]}, {"role": "assistant", "text": "\u6682\u65f6\u65e0\u6cd5\u8bc6\u522b\u201c\u82f1\u9633\u8054\u76df\u201d\uff0c\u53ef\u80fd\u662f\u60a8\u8f93\u5165\u6709\u8bef\uff0c\u6216\u8005\u7684\u80fd\u529b\u6709\u9650\uff0c\u60a8\u53ef\u4ee5\u5c1d\u8bd5\u6362\u4e2a\u8bf4\u6cd5\u3002\u6bd4\u5982\uff0c\u5982\u679c\u60a8\u60f3\u770b\u82f1\u96c4\u8054\u76df\u7684\u65b0\u95fb\u6216\u8005\u8d5b\u4e8b\u4fe1\u606f\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u8f93\u5165\u201c\u82f1\u96c4\u8054\u76df\u65b0\u95fb\u201d\u6216\u8005\u201c\u82f1\u96c4\u8054\u76df\u8d5b\u4e8b\u201d\u3002", "files": []}, {"role": "user", "text": "\u591a\u63a8\u82f1\u96c4\u8054\u76df", "files": []}, {"role": "assistant", "text": "", "files": [], "tool_calls": [{"id": "call_f640f05c-eb9f-43f0-86ed-1397fabf2c37", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\u589e\u52a0', 'demand': '\u82f1\u9633\u8054\u76df'}]\"}"}}]}, {"role": "tool", "text": "{\"message\": \"\u6536\u5230\u60a8\u7684\u5429\u5490\u4e86\uff0c\u53ef\u8fd9\u4e2a\u8981\u6c42\u597d\u96be\uff0c\u6682\u65f6\u505a\u4e0d\u5230\uff0c\u8bf7\u6362\u4e2a\u8bf4\u6cd5\u8bd5\u8bd5\uff01\"}", "files": [], "tool_calls": [{"id": "call_f640f05c-eb9f-43f0-86ed-1397fabf2c37", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\u589e\u52a0', 'demand': '\u82f1\u9633\u8054\u76df'}]\"}"}}]}]

Database records after prasing

[{'role': 'user', 'text': '不想看新京报', 'files': []}, {'role': 'assistant', 'text': '', 'files': [], 'tool_calls': [{'id': 'call_8a7e093f-8938-4d7c-81ac-65e43aa8fa3b', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'阻止\', \'demand\': \'新京报\'}]"}'}}]}, {'role': 'tool', 'text': '{"profile": [{"granularity": "TNAME", "type": "ALL", "content": "T1486538331796", "priority": -1.0}], "message": "已经根据您 的吩咐调整了推荐模式,现在您可以去一探究竟啦!"}', 'files': [], 'tool_calls': [{'id': 'call_8a7e093f-8938-4d7c-81ac-65e43aa8fa3b', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'阻止\', \'demand\': \'新京报\'}]"}'}}]}]

[{'role': 'user', 'text': '不想看新京报', 'files': []}, {'role': 'assistant', 'text': '用户表达了不想看来自“新京报”的内容,这涉及到调整推荐内容,阻止特定来源的信息。', 'files': [], 'tool_calls': [{'id': 'a7455157-a8ea-4a7c-8d21-529de2fdab0b', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'\\u963b\\u6b62\', \'demand\': \'\\u65b0\\u4eac\\u62a5\'}]"}'}}]}, {'role': 'tool', 'text': '{"profile": [{"granularity": "TNAME", "type": "ALL", "content": "T1486538331796", "priority": -1.0}], "message": "已经根据您的吩咐调整了推荐模式,现在您可以去一探究竟啦!"}', 'files': [], 'tool_calls': [{'id': 'a7455157-a8ea-4a7c-8d21-529de2fdab0b', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'\\u963b\\u6b62\', \'demand\':\'\\u65b0\\u4eac\\u62a5\'}]"}'}}]}, {'role': 'assistant', 'text': '我已经帮您设置好了,您将不再看到新京报的相关信息。', 'files': []}, {'role': 'user', 'text': '想看英雄联盟', 'files': []}, {'role': 'assistant', 'text': '', 'files': [], 'tool_calls': [{'id': 'call_3eb89cec-17f8-4cf6-beb3-f0883b6a1386', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'增加\', \'demand\': \'英阳联盟\'}]"}'}}]}, {'role': 'tool', 'text': '{"message": "收到您的吩咐了,可这个要求好难,暂时做不到,请换个说法试试!"}', 'files': [], 'tool_calls': [{'id': 'call_3eb89cec-17f8-4cf6-beb3-f0883b6a1386', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'增加\', \'demand\': \'英阳联盟\'}]"}'}}]}]

[{'role': 'user', 'text': '不想看新京报', 'files': []}, {'role': 'assistant', 'text': '用户表达了不想看来自“新京报”的内容,这涉及到调整推荐内容,阻止特定来源的信息。', 'files': [], 'tool_calls': [{'id': '222fed6b-c2fc-416d-8e0a-60c2d38a0a67', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'\\u963b\\u6b62\', \'demand\': \'\\u65b0\\u4eac\\u62a5\'}]"}'}}]}, {'role': 'tool', 'text': '{"profile": [{"granularity": "TNAME", "type": "ALL", "content": "T1486538331796", "priority": -1.0}], "message": "已经根据您的吩咐调整了推荐模式,现在您可以去一探究竟啦!"}', 'files': [], 'tool_calls': [{'id': '222fed6b-c2fc-416d-8e0a-60c2d38a0a67', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'\\u963b\\u6b62\', \'demand\': \'\\u65b0\\u4eac\\u62a5\'}]"}'}}]}, {'role': 'assistant', 'text': '我已经帮您设置好了,您将不再看到新京报的相关信息。', 'files': []}, {'role': 'user', 'text': '想看英雄联盟', 'files': []}, {'role': 'assistant', 'text': 'I can use ai_agent_profile.', 'files': [], 'tool_calls': [{'id': '8613338c-5e89-4e11-b675-762011a74f7e', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'\\u589e\\u52a0\', \'demand\': \'\\u82f1\\u9633\\u8054\\u76df\'}]"}'}}]}, {'role': 'tool', 'text': '{"message": "收到您的吩咐了,可这个要求好难,暂时做不到,请换个说法试试!"}', 'files': [], 'tool_calls': [{'id': '8613338c-5e89-4e11-b675-762011a74f7e', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'\\u589e\\u52a0\', \'demand\': \'\\u82f1\\u9633\\u8054\\u76df\'*}]"}'}}]}, {'role': 'assistant', 'text': '暂时无法识别“英阳联盟”,可能是您输入有误。', 'files': []}, {'role': 'user', 'text': '多推英雄联盟', 'files': []}, {'role': 'assistant', 'text': '', 'files': [], 'tool_calls': [{'id': 'call_f640f05c-eb9f-43f0-86ed-1397fabf2c37', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'增加\', \'demand\': \'英阳联盟\'}]"}'}}]}, {'role': 'tool', 'text': '{"message": "收到您的吩咐了,可这个要求好难,暂时做不到,请换个说法试试!"}', 'files': [], 'tool_calls': [{'id': 'call_f640f05c-eb9f-43f0-86ed-1397fabf2c37', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'增加\', \'demand\': \'英阳联盟\'}]"}'}}]}]

✔️ Expected Behavior

"arguments": "{\"preferences\": \"[{'action': '\u963b\u6b62', 'demand': '\u65b0\u4eac\u62a5'}]\"}"}}

Actual Behavior

"arguments": "{\"preferences\": \"[{'action': '\\u963b\\u6b62', 'demand': '\\u65b0\\u4eac\\u62a5'}]\"}"}}

Originally created by @lidajiededa on GitHub (Aug 2, 2024). ### Self Checks - [X] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [X] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [X] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [X] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [X] Please do not modify this template :) and fill in all the required fields. ### Dify version 0.6.15 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce ### Model qwen-2-72B ### Problems During the process of using agents for function calls and multiple rounds of conversations, we found that the latter few rounds of conversations would produce abnormal responses. By examining the database, we found that there is an issue with ("tool_calls" ->"function" ->"arguments") when retrieving history in multiple rounds of conversations. We let the arguments be a json list with 2 attributes -- 'action' and 'demand'. The 'tool_calls' result is rightly shown, but in the second and three rounds of conversation, agent should first get the histroy results. We found that there are '\\\\'s in 'arguments': `"arguments": "{\"preferences\": \"[{'action': '\\u963b\\u6b62', 'demand': '\\u65b0\\u4eac\\u62a5'}]\"}"}} ` The correct one should be `"arguments": "{\"preferences\": \"[{'action': '\u963b\u6b62', 'demand': '\u65b0\u4eac\u62a5'}]\"}"}} This situation will lead to abnormal performance of the agent in the later rounds. This issue may be caused by encoding problems during the reading and writing of history in multiple rounds of dialogue. The following are the database records and the results after decoding. We can see that there are '\\\\'s in the 'arguments', ade there is a problem with the output of the last two rounds, as it outputs' 英阳联盟' instead of '英雄联盟' `### Database records #### round1 `[{"role": "user", "text": "\u4e0d\u60f3\u770b\u65b0\u4eac\u62a5", "files": []}, {"role": "assistant", "text": "", "files": [], "tool_calls": [{"id": "call_8a7e093f-8938-4d7c-81ac-65e43aa8fa3b", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\u963b\u6b62', 'demand': '\u65b0\u4eac\u62a5'}]\"}"}}]}, {"role": "tool", "text": "{\"profile\": [{\"granularity\": \"TNAME\", \"type\": \"ALL\", \"content\": \"T1486538331796\", \"priority\": -1.0}], \"message\": \"\u5df2\u7ecf\u6839\u636e\u60a8\u7684\u5429\u5490\u8c03\u6574\u4e86\u63a8\u8350\u6a21\u5f0f\uff0c\u73b0\u5728\u60a8\u53ef\u4ee5\u53bb\u4e00\u63a2\u7a76\u7adf\u5566\uff01\"}", "files": [], "tool_calls": [{"id": "call_8a7e093f-8938-4d7c-81ac-65e43aa8fa3b", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\u963b\u6b62', 'demand': '\u65b0\u4eac\u62a5'}]\"}"}}]}]` #### round2 `[{"role": "user", "text": "\u4e0d\u60f3\u770b\u65b0\u4eac\u62a5", "files": []}, {"role": "assistant", "text": "\u7528\u6237\u8868\u8fbe\u4e86\u4e0d\u60f3\u770b\u6765\u81ea\u201c\u65b0\u4eac\u62a5\u201d\u7684\u5185\u5bb9\uff0c\u8fd9\u6d89\u53ca\u5230\u8c03\u6574\u63a8\u8350\u5185\u5bb9\uff0c\u963b\u6b62\u7279\u5b9a\u6765\u6e90\u7684\u4fe1\u606f\u3002", "files": [], "tool_calls": [{"id": "a7455157-a8ea-4a7c-8d21-529de2fdab0b", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\\u963b\\u6b62', 'demand': '\\u65b0\\u4eac\\u62a5'}]\"}"}}]}, {"role": "tool", "text": "{\"profile\": [{\"granularity\": \"TNAME\", \"type\": \"ALL\", \"content\": \"T1486538331796\", \"priority\": -1.0}], \"message\": \"\u5df2\u7ecf\u6839\u636e\u60a8\u7684\u5429\u5490\u8c03\u6574\u4e86\u63a8\u8350\u6a21\u5f0f\uff0c\u73b0\u5728\u60a8\u53ef\u4ee5\u53bb\u4e00\u63a2\u7a76\u7adf\u5566\uff01\"}", "files": [], "tool_calls": [{"id": "a7455157-a8ea-4a7c-8d21-529de2fdab0b", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\\u963b\\u6b62', 'demand': '\\u65b0\\u4eac\\u62a5'}]\"}"}}]}, {"role": "assistant", "text": "\u6211\u5df2\u7ecf\u5e2e\u60a8\u8bbe\u7f6e\u597d\u4e86\uff0c\u60a8\u5c06\u4e0d\u518d\u770b\u5230\u65b0\u4eac\u62a5\u7684\u76f8\u5173\u4fe1\u606f\u3002", "files": []}, {"role": "user", "text": "\u60f3\u770b\u82f1\u96c4\u8054\u76df", "files": []}, {"role": "assistant", "text": "", "files": [], "tool_calls": [{"id": "call_3eb89cec-17f8-4cf6-beb3-f0883b6a1386", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\u589e\u52a0', 'demand': '\u82f1\u9633\u8054\u76df'}]\"}"}}]}, {"role": "tool", "text": "{\"message\": \"\u6536\u5230\u60a8\u7684\u5429\u5490\u4e86\uff0c\u53ef\u8fd9\u4e2a\u8981\u6c42\u597d\u96be\uff0c\u6682\u65f6\u505a\u4e0d\u5230\uff0c\u8bf7\u6362\u4e2a\u8bf4\u6cd5\u8bd5\u8bd5\uff01\"}", "files": [], "tool_calls": [{"id": "call_3eb89cec-17f8-4cf6-beb3-f0883b6a1386", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\u589e\u52a0', 'demand': '\u82f1\u9633\u8054\u76df'}]\"}"}}]}]` #### round3 `[{"role": "user", "text": "\u4e0d\u60f3\u770b\u65b0\u4eac\u62a5", "files": []}, {"role": "assistant", "text": "\u7528\u6237\u8868\u8fbe\u4e86\u4e0d\u60f3\u770b\u6765\u81ea\u201c\u65b0\u4eac\u62a5\u201d\u7684\u5185\u5bb9\uff0c\u8fd9\u6d89\u53ca\u5230\u8c03\u6574\u63a8\u8350\u5185\u5bb9\uff0c\u963b\u6b62\u7279\u5b9a\u6765\u6e90\u7684\u4fe1\u606f\u3002", "files": [], "tool_calls": [{"id": "222fed6b-c2fc-416d-8e0a-60c2d38a0a67", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\\u963b\\u6b62', 'demand': '\\u65b0\\u4eac\\u62a5'}]\"}"}}]}, {"role": "tool", "text": "{\"profile\": [{\"granularity\": \"TNAME\", \"type\": \"ALL\", \"content\": \"T1486538331796\", \"priority\": -1.0}], \"message\": \"\u5df2\u7ecf\u6839\u636e\u60a8\u7684\u5429\u5490\u8c03\u6574\u4e86\u63a8\u8350\u6a21\u5f0f\uff0c\u73b0\u5728\u60a8\u53ef\u4ee5\u53bb\u4e00\u63a2\u7a76\u7adf\u5566\uff01\"}", "files": [], "tool_calls": [{"id": "222fed6b-c2fc-416d-8e0a-60c2d38a0a67", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\\u963b\\u6b62', 'demand': '\\u65b0\\u4eac\\u62a5'}]\"}"}}]}, {"role": "assistant", "text": "\u6211\u5df2\u7ecf\u5e2e\u60a8\u8bbe\u7f6e\u597d\u4e86\uff0c\u60a8\u5c06\u4e0d\u518d\u770b\u5230\u65b0\u4eac\u62a5\u7684\u76f8\u5173\u4fe1\u606f\u3002", "files": []}, {"role": "user", "text": "\u60f3\u770b\u82f1\u96c4\u8054\u76df", "files": []}, {"role": "assistant", "text": "I can use ai_agent_profile.", "files": [], "tool_calls": [{"id": "8613338c-5e89-4e11-b675-762011a74f7e", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\\u589e\\u52a0', 'demand': '\\u82f1\\u9633\\u8054\\u76df'}]\"}"}}]}, {"role": "tool", "text": "{\"message\": \"\u6536\u5230\u60a8\u7684\u5429\u5490\u4e86\uff0c\u53ef\u8fd9\u4e2a\u8981\u6c42\u597d\u96be\uff0c\u6682\u65f6\u505a\u4e0d\u5230\uff0c\u8bf7\u6362\u4e2a\u8bf4\u6cd5\u8bd5\u8bd5\uff01\"}", "files": [], "tool_calls": [{"id": "8613338c-5e89-4e11-b675-762011a74f7e", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\\u589e\\u52a0', 'demand': '\\u82f1\\u9633\\u8054\\u76df'}]\"}"}}]}, {"role": "assistant", "text": "\u6682\u65f6\u65e0\u6cd5\u8bc6\u522b\u201c\u82f1\u9633\u8054\u76df\u201d\uff0c\u53ef\u80fd\u662f\u60a8\u8f93\u5165\u6709\u8bef\uff0c\u6216\u8005\u7684\u80fd\u529b\u6709\u9650\uff0c\u60a8\u53ef\u4ee5\u5c1d\u8bd5\u6362\u4e2a\u8bf4\u6cd5\u3002\u6bd4\u5982\uff0c\u5982\u679c\u60a8\u60f3\u770b\u82f1\u96c4\u8054\u76df\u7684\u65b0\u95fb\u6216\u8005\u8d5b\u4e8b\u4fe1\u606f\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u8f93\u5165\u201c\u82f1\u96c4\u8054\u76df\u65b0\u95fb\u201d\u6216\u8005\u201c\u82f1\u96c4\u8054\u76df\u8d5b\u4e8b\u201d\u3002", "files": []}, {"role": "user", "text": "\u591a\u63a8\u82f1\u96c4\u8054\u76df", "files": []}, {"role": "assistant", "text": "", "files": [], "tool_calls": [{"id": "call_f640f05c-eb9f-43f0-86ed-1397fabf2c37", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\u589e\u52a0', 'demand': '\u82f1\u9633\u8054\u76df'}]\"}"}}]}, {"role": "tool", "text": "{\"message\": \"\u6536\u5230\u60a8\u7684\u5429\u5490\u4e86\uff0c\u53ef\u8fd9\u4e2a\u8981\u6c42\u597d\u96be\uff0c\u6682\u65f6\u505a\u4e0d\u5230\uff0c\u8bf7\u6362\u4e2a\u8bf4\u6cd5\u8bd5\u8bd5\uff01\"}", "files": [], "tool_calls": [{"id": "call_f640f05c-eb9f-43f0-86ed-1397fabf2c37", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\u589e\u52a0', 'demand': '\u82f1\u9633\u8054\u76df'}]\"}"}}]}]` ### Database records after prasing `[{'role': 'user', 'text': '不想看新京报', 'files': []}, {'role': 'assistant', 'text': '', 'files': [], 'tool_calls': [{'id': 'call_8a7e093f-8938-4d7c-81ac-65e43aa8fa3b', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'阻止\', \'demand\': \'新京报\'}]"}'}}]}, {'role': 'tool', 'text': '{"profile": [{"granularity": "TNAME", "type": "ALL", "content": "T1486538331796", "priority": -1.0}], "message": "已经根据您 的吩咐调整了推荐模式,现在您可以去一探究竟啦!"}', 'files': [], 'tool_calls': [{'id': 'call_8a7e093f-8938-4d7c-81ac-65e43aa8fa3b', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'阻止\', \'demand\': \'新京报\'}]"}'}}]}]` `[{'role': 'user', 'text': '不想看新京报', 'files': []}, {'role': 'assistant', 'text': '用户表达了不想看来自“新京报”的内容,这涉及到调整推荐内容,阻止特定来源的信息。', 'files': [], 'tool_calls': [{'id': 'a7455157-a8ea-4a7c-8d21-529de2fdab0b', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'\\u963b\\u6b62\', \'demand\': \'\\u65b0\\u4eac\\u62a5\'}]"}'}}]}, {'role': 'tool', 'text': '{"profile": [{"granularity": "TNAME", "type": "ALL", "content": "T1486538331796", "priority": -1.0}], "message": "已经根据您的吩咐调整了推荐模式,现在您可以去一探究竟啦!"}', 'files': [], 'tool_calls': [{'id': 'a7455157-a8ea-4a7c-8d21-529de2fdab0b', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'\\u963b\\u6b62\', \'demand\':\'\\u65b0\\u4eac\\u62a5\'}]"}'}}]}, {'role': 'assistant', 'text': '我已经帮您设置好了,您将不再看到新京报的相关信息。', 'files': []}, {'role': 'user', 'text': '想看英雄联盟', 'files': []}, {'role': 'assistant', 'text': '', 'files': [], 'tool_calls': [{'id': 'call_3eb89cec-17f8-4cf6-beb3-f0883b6a1386', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'增加\', \'demand\': \'英阳联盟\'}]"}'}}]}, {'role': 'tool', 'text': '{"message": "收到您的吩咐了,可这个要求好难,暂时做不到,请换个说法试试!"}', 'files': [], 'tool_calls': [{'id': 'call_3eb89cec-17f8-4cf6-beb3-f0883b6a1386', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'增加\', \'demand\': \'英阳联盟\'}]"}'}}]}]` `[{'role': 'user', 'text': '不想看新京报', 'files': []}, {'role': 'assistant', 'text': '用户表达了不想看来自“新京报”的内容,这涉及到调整推荐内容,阻止特定来源的信息。', 'files': [], 'tool_calls': [{'id': '222fed6b-c2fc-416d-8e0a-60c2d38a0a67', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'\\u963b\\u6b62\', \'demand\': \'\\u65b0\\u4eac\\u62a5\'}]"}'}}]}, {'role': 'tool', 'text': '{"profile": [{"granularity": "TNAME", "type": "ALL", "content": "T1486538331796", "priority": -1.0}], "message": "已经根据您的吩咐调整了推荐模式,现在您可以去一探究竟啦!"}', 'files': [], 'tool_calls': [{'id': '222fed6b-c2fc-416d-8e0a-60c2d38a0a67', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'\\u963b\\u6b62\', \'demand\': \'\\u65b0\\u4eac\\u62a5\'}]"}'}}]}, {'role': 'assistant', 'text': '我已经帮您设置好了,您将不再看到新京报的相关信息。', 'files': []}, {'role': 'user', 'text': '想看英雄联盟', 'files': []}, {'role': 'assistant', 'text': 'I can use ai_agent_profile.', 'files': [], 'tool_calls': [{'id': '8613338c-5e89-4e11-b675-762011a74f7e', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'\\u589e\\u52a0\', \'demand\': \'\\u82f1\\u9633\\u8054\\u76df\'}]"}'}}]}, {'role': 'tool', 'text': '{"message": "收到您的吩咐了,可这个要求好难,暂时做不到,请换个说法试试!"}', 'files': [], 'tool_calls': [{'id': '8613338c-5e89-4e11-b675-762011a74f7e', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'\\u589e\\u52a0\', \'demand\': \'\\u82f1\\u9633\\u8054\\u76df\'*}]"}'}}]}, {'role': 'assistant', 'text': '暂时无法识别“英阳联盟”,可能是您输入有误。', 'files': []}, {'role': 'user', 'text': '多推英雄联盟', 'files': []}, {'role': 'assistant', 'text': '', 'files': [], 'tool_calls': [{'id': 'call_f640f05c-eb9f-43f0-86ed-1397fabf2c37', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'增加\', \'demand\': \'英阳联盟\'}]"}'}}]}, {'role': 'tool', 'text': '{"message": "收到您的吩咐了,可这个要求好难,暂时做不到,请换个说法试试!"}', 'files': [], 'tool_calls': [{'id': 'call_f640f05c-eb9f-43f0-86ed-1397fabf2c37', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'增加\', \'demand\': \'英阳联盟\'}]"}'}}]}]` ### ✔️ Expected Behavior `"arguments": "{\"preferences\": \"[{'action': '\u963b\u6b62', 'demand': '\u65b0\u4eac\u62a5'}]\"}"}} ` ### ❌ Actual Behavior `"arguments": "{\"preferences\": \"[{'action': '\\u963b\\u6b62', 'demand': '\\u65b0\\u4eac\\u62a5'}]\"}"}} `
yindo added the 🐞 bug🤖 feat:agentstale labels 2026-02-21 18:08:22 -05:00
yindo closed this issue 2026-02-21 18:08:22 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Aug 2, 2024):

@lidajiededa Hello! I'm here to assist you with any bugs, questions, or contributions for the repository. Let me know how I can help!

To resolve the encoding issue with "tool_calls" -> "function" -> "arguments" in multiple rounds of conversation, which is causing abnormal agent performance in later rounds, you should ensure that the arguments are properly concatenated and not corrupted over multiple rounds. The issue seems to be related to how the arguments are being accumulated.

In the _handle_generate_stream_response method, the increase_tool_call function is responsible for updating the tool calls. Specifically, the line tool_call.function.arguments += new_tool_call.function.arguments is where the arguments are concatenated. This can lead to issues if the arguments are not properly managed.

Here is a potential fix to ensure that the arguments are correctly handled:

def increase_tool_call(new_tool_calls: list[AssistantPromptMessage.ToolCall]):
    def get_tool_call(tool_call_id: str):
        if not tool_call_id:
            return tools_calls[-1]
        tool_call = next((tool_call for tool_call in tools_calls if tool_call.id == tool_call_id), None)
        if tool_call is None:
            tool_call = AssistantPromptMessage.ToolCall(
                id=tool_call_id,
                type="function",
                function=AssistantPromptMessage.ToolCall.ToolCallFunction(
                    name="",
                    arguments=""
                )
            )
            tools_calls.append(tool_call)

        return tool_call

    for new_tool_call in new_tool_calls:
        # get tool call
        tool_call = get_tool_call(new_tool_call.id)
        # update tool call
        if new_tool_call.id:
            tool_call.id = new_tool_call.id
        if new_tool_call.type:
            tool_call.type = new_tool_call.type
        if new_tool_call.function.name:
            tool_call.function.name = new_tool_call.function.name
        if new_tool_call.function.arguments:
            # Ensure arguments are properly concatenated without corruption
            if tool_call.function.arguments:
                tool_call.function.arguments += f" {new_tool_call.function.arguments}"
            else:
                tool_call.function.arguments = new_tool_call.function.arguments

def _handle_chat_generate_stream_response(
        self,
        model: str,
        credentials: dict,
        response: Stream[ChatCompletionChunk],
        prompt_messages: list[PromptMessage],
        tools: Optional[list[PromptMessageTool]] = None
    ):
        index = 0
        full_assistant_content = ''
        real_model = model
        system_fingerprint = None
        completion = ''
        tool_calls = []
        for chunk in response:
            if len(chunk.choices) == 0:
                continue

            delta = chunk.choices[0]

            # extract tool calls from response
            self._update_tool_calls(tool_calls=tool_calls, tool_calls_response=delta.delta.tool_calls)

            # Handling exceptions when content filters' streaming mode is set to asynchronous modified filter
            if delta.finish_reason is None and not delta.delta.content:
                continue

            # transform assistant message to prompt message
            assistant_prompt_message = AssistantPromptMessage(
                content=delta.delta.content if delta.delta.content else '',
                tool_calls=tool_calls
            )

            full_assistant_content += delta.delta.content if delta.delta.content else ''

            real_model = chunk.model
            system_fingerprint = chunk.system_fingerprint
            completion += delta.delta.content if delta.delta.content else ''

            yield LLMResultChunk(
                model=real_model,
                prompt_messages=prompt_messages,
                system_fingerprint=system_fingerprint,
                delta=LLMResultChunkDelta(
                    index=index,
                    message=assistant_prompt_message,
                )
            )

            index += 0

        # calculate num tokens
        prompt_tokens = self._num_tokens_from_messages(credentials, prompt_messages, tools)

Additionally, ensure that the arguments are properly encoded as JSON strings to avoid encoding issues. The following snippet from the FunctionCallAgentRunner class in the Dify platform demonstrates how to handle tool call arguments:

assistant_message = AssistantPromptMessage(
    content='',
    tool_calls=[]
)
if tool_calls:
    assistant_message.tool_calls=[
        AssistantPromptMessage.ToolCall(
            id=tool_call[0],
            type='function',
            function=AssistantPromptMessage.ToolCall.ToolCallFunction(
                name=tool_call[1],
                arguments=json.dumps(tool_call[2], ensure_ascii=False)
            )
        ) for tool_call in tool_calls
    ]
else:
    assistant_message.content = response

self._current_thoughts.append(assistant_message)

This change ensures that the arguments are properly encoded as JSON strings, preventing potential corruption or encoding issues. Additionally, the _handle_generate_stream_response method has been updated to properly handle tool calls and ensure the integrity of the arguments over multiple rounds of conversation [1][2][3][4].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Aug 2, 2024): <!-- Greeting --> @lidajiededa Hello! I'm here to assist you with any bugs, questions, or contributions for the repository. Let me know how I can help! <!-- Answer --> To resolve the encoding issue with "tool_calls" -> "function" -> "arguments" in multiple rounds of conversation, which is causing abnormal agent performance in later rounds, you should ensure that the arguments are properly concatenated and not corrupted over multiple rounds. The issue seems to be related to how the arguments are being accumulated. In the `_handle_generate_stream_response` method, the `increase_tool_call` function is responsible for updating the tool calls. Specifically, the line `tool_call.function.arguments += new_tool_call.function.arguments` is where the arguments are concatenated. This can lead to issues if the arguments are not properly managed. Here is a potential fix to ensure that the arguments are correctly handled: ```python def increase_tool_call(new_tool_calls: list[AssistantPromptMessage.ToolCall]): def get_tool_call(tool_call_id: str): if not tool_call_id: return tools_calls[-1] tool_call = next((tool_call for tool_call in tools_calls if tool_call.id == tool_call_id), None) if tool_call is None: tool_call = AssistantPromptMessage.ToolCall( id=tool_call_id, type="function", function=AssistantPromptMessage.ToolCall.ToolCallFunction( name="", arguments="" ) ) tools_calls.append(tool_call) return tool_call for new_tool_call in new_tool_calls: # get tool call tool_call = get_tool_call(new_tool_call.id) # update tool call if new_tool_call.id: tool_call.id = new_tool_call.id if new_tool_call.type: tool_call.type = new_tool_call.type if new_tool_call.function.name: tool_call.function.name = new_tool_call.function.name if new_tool_call.function.arguments: # Ensure arguments are properly concatenated without corruption if tool_call.function.arguments: tool_call.function.arguments += f" {new_tool_call.function.arguments}" else: tool_call.function.arguments = new_tool_call.function.arguments def _handle_chat_generate_stream_response( self, model: str, credentials: dict, response: Stream[ChatCompletionChunk], prompt_messages: list[PromptMessage], tools: Optional[list[PromptMessageTool]] = None ): index = 0 full_assistant_content = '' real_model = model system_fingerprint = None completion = '' tool_calls = [] for chunk in response: if len(chunk.choices) == 0: continue delta = chunk.choices[0] # extract tool calls from response self._update_tool_calls(tool_calls=tool_calls, tool_calls_response=delta.delta.tool_calls) # Handling exceptions when content filters' streaming mode is set to asynchronous modified filter if delta.finish_reason is None and not delta.delta.content: continue # transform assistant message to prompt message assistant_prompt_message = AssistantPromptMessage( content=delta.delta.content if delta.delta.content else '', tool_calls=tool_calls ) full_assistant_content += delta.delta.content if delta.delta.content else '' real_model = chunk.model system_fingerprint = chunk.system_fingerprint completion += delta.delta.content if delta.delta.content else '' yield LLMResultChunk( model=real_model, prompt_messages=prompt_messages, system_fingerprint=system_fingerprint, delta=LLMResultChunkDelta( index=index, message=assistant_prompt_message, ) ) index += 0 # calculate num tokens prompt_tokens = self._num_tokens_from_messages(credentials, prompt_messages, tools) ``` Additionally, ensure that the arguments are properly encoded as JSON strings to avoid encoding issues. The following snippet from the `FunctionCallAgentRunner` class in the Dify platform demonstrates how to handle tool call arguments: ```python assistant_message = AssistantPromptMessage( content='', tool_calls=[] ) if tool_calls: assistant_message.tool_calls=[ AssistantPromptMessage.ToolCall( id=tool_call[0], type='function', function=AssistantPromptMessage.ToolCall.ToolCallFunction( name=tool_call[1], arguments=json.dumps(tool_call[2], ensure_ascii=False) ) ) for tool_call in tool_calls ] else: assistant_message.content = response self._current_thoughts.append(assistant_message) ``` This change ensures that the arguments are properly encoded as JSON strings, preventing potential corruption or encoding issues. Additionally, the `_handle_generate_stream_response` method has been updated to properly handle tool calls and ensure the integrity of the arguments over multiple rounds of conversation <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/core/model_runtime/model_providers/openai_api_compatible/llm/llm.py)</sup><sup>[[2]](https://github.com/langgenius/dify/blob/main/api/core/model_runtime/model_providers/azure_openai/llm/llm.py)</sup><sup>[[3]](https://github.com/langgenius/dify/blob/main/api/core/agent/fc_agent_runner.py)</sup><sup>[[4]](https://github.com/langgenius/dify/blob/main/api/core/model_runtime/model_providers/moonshot/llm/llm.py)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@FAFUuser commented on GitHub (Sep 4, 2024):

@lidajiededa Hello! I'm here to assist you with any bugs, questions, or contributions for the repository. Let me know how I can help!

To resolve the encoding issue with "tool_calls" -> "function" -> "arguments" in multiple rounds of conversation, which is causing abnormal agent performance in later rounds, you should ensure that the arguments are properly concatenated and not corrupted over multiple rounds. The issue seems to be related to how the arguments are being accumulated.

In the _handle_generate_stream_response method, the increase_tool_call function is responsible for updating the tool calls. Specifically, the line tool_call.function.arguments += new_tool_call.function.arguments is where the arguments are concatenated. This can lead to issues if the arguments are not properly managed.

Here is a potential fix to ensure that the arguments are correctly handled:

def increase_tool_call(new_tool_calls: list[AssistantPromptMessage.ToolCall]):
    def get_tool_call(tool_call_id: str):
        if not tool_call_id:
            return tools_calls[-1]
        tool_call = next((tool_call for tool_call in tools_calls if tool_call.id == tool_call_id), None)
        if tool_call is None:
            tool_call = AssistantPromptMessage.ToolCall(
                id=tool_call_id,
                type="function",
                function=AssistantPromptMessage.ToolCall.ToolCallFunction(
                    name="",
                    arguments=""
                )
            )
            tools_calls.append(tool_call)

        return tool_call

    for new_tool_call in new_tool_calls:
        # get tool call
        tool_call = get_tool_call(new_tool_call.id)
        # update tool call
        if new_tool_call.id:
            tool_call.id = new_tool_call.id
        if new_tool_call.type:
            tool_call.type = new_tool_call.type
        if new_tool_call.function.name:
            tool_call.function.name = new_tool_call.function.name
        if new_tool_call.function.arguments:
            # Ensure arguments are properly concatenated without corruption
            if tool_call.function.arguments:
                tool_call.function.arguments += f" {new_tool_call.function.arguments}"
            else:
                tool_call.function.arguments = new_tool_call.function.arguments

def _handle_chat_generate_stream_response(
        self,
        model: str,
        credentials: dict,
        response: Stream[ChatCompletionChunk],
        prompt_messages: list[PromptMessage],
        tools: Optional[list[PromptMessageTool]] = None
    ):
        index = 0
        full_assistant_content = ''
        real_model = model
        system_fingerprint = None
        completion = ''
        tool_calls = []
        for chunk in response:
            if len(chunk.choices) == 0:
                continue

            delta = chunk.choices[0]

            # extract tool calls from response
            self._update_tool_calls(tool_calls=tool_calls, tool_calls_response=delta.delta.tool_calls)

            # Handling exceptions when content filters' streaming mode is set to asynchronous modified filter
            if delta.finish_reason is None and not delta.delta.content:
                continue

            # transform assistant message to prompt message
            assistant_prompt_message = AssistantPromptMessage(
                content=delta.delta.content if delta.delta.content else '',
                tool_calls=tool_calls
            )

            full_assistant_content += delta.delta.content if delta.delta.content else ''

            real_model = chunk.model
            system_fingerprint = chunk.system_fingerprint
            completion += delta.delta.content if delta.delta.content else ''

            yield LLMResultChunk(
                model=real_model,
                prompt_messages=prompt_messages,
                system_fingerprint=system_fingerprint,
                delta=LLMResultChunkDelta(
                    index=index,
                    message=assistant_prompt_message,
                )
            )

            index += 0

        # calculate num tokens
        prompt_tokens = self._num_tokens_from_messages(credentials, prompt_messages, tools)

Additionally, ensure that the arguments are properly encoded as JSON strings to avoid encoding issues. The following snippet from the FunctionCallAgentRunner class in the Dify platform demonstrates how to handle tool call arguments:

assistant_message = AssistantPromptMessage(
    content='',
    tool_calls=[]
)
if tool_calls:
    assistant_message.tool_calls=[
        AssistantPromptMessage.ToolCall(
            id=tool_call[0],
            type='function',
            function=AssistantPromptMessage.ToolCall.ToolCallFunction(
                name=tool_call[1],
                arguments=json.dumps(tool_call[2], ensure_ascii=False)
            )
        ) for tool_call in tool_calls
    ]
else:
    assistant_message.content = response

self._current_thoughts.append(assistant_message)

This change ensures that the arguments are properly encoded as JSON strings, preventing potential corruption or encoding issues. Additionally, the _handle_generate_stream_response method has been updated to properly handle tool calls and ensure the integrity of the arguments over multiple rounds of conversation [1][2][3][4].

To continue talking to Dosu, mention @dosu.

hello,In the created Agent application, when using custom tools (with both tool names and parameters in Chinese), the agent's thinking process occasionally encounters issues with Chinese character encoding, resulting in garbled text. Through debugging, I found that the garbled text appears in the resp within llm.py (xinference). Additionally, even when there is garbled text, the parameters are not correctly parsed during tool invocation. For example, the parameter '中坤' goes through the process: '中坤' --> garbled text --> '中移', which leads to errors.

@FAFUuser commented on GitHub (Sep 4, 2024): > @lidajiededa Hello! I'm here to assist you with any bugs, questions, or contributions for the repository. Let me know how I can help! > > To resolve the encoding issue with "tool_calls" -> "function" -> "arguments" in multiple rounds of conversation, which is causing abnormal agent performance in later rounds, you should ensure that the arguments are properly concatenated and not corrupted over multiple rounds. The issue seems to be related to how the arguments are being accumulated. > > In the `_handle_generate_stream_response` method, the `increase_tool_call` function is responsible for updating the tool calls. Specifically, the line `tool_call.function.arguments += new_tool_call.function.arguments` is where the arguments are concatenated. This can lead to issues if the arguments are not properly managed. > > Here is a potential fix to ensure that the arguments are correctly handled: > > ```python > def increase_tool_call(new_tool_calls: list[AssistantPromptMessage.ToolCall]): > def get_tool_call(tool_call_id: str): > if not tool_call_id: > return tools_calls[-1] > tool_call = next((tool_call for tool_call in tools_calls if tool_call.id == tool_call_id), None) > if tool_call is None: > tool_call = AssistantPromptMessage.ToolCall( > id=tool_call_id, > type="function", > function=AssistantPromptMessage.ToolCall.ToolCallFunction( > name="", > arguments="" > ) > ) > tools_calls.append(tool_call) > > return tool_call > > for new_tool_call in new_tool_calls: > # get tool call > tool_call = get_tool_call(new_tool_call.id) > # update tool call > if new_tool_call.id: > tool_call.id = new_tool_call.id > if new_tool_call.type: > tool_call.type = new_tool_call.type > if new_tool_call.function.name: > tool_call.function.name = new_tool_call.function.name > if new_tool_call.function.arguments: > # Ensure arguments are properly concatenated without corruption > if tool_call.function.arguments: > tool_call.function.arguments += f" {new_tool_call.function.arguments}" > else: > tool_call.function.arguments = new_tool_call.function.arguments > > def _handle_chat_generate_stream_response( > self, > model: str, > credentials: dict, > response: Stream[ChatCompletionChunk], > prompt_messages: list[PromptMessage], > tools: Optional[list[PromptMessageTool]] = None > ): > index = 0 > full_assistant_content = '' > real_model = model > system_fingerprint = None > completion = '' > tool_calls = [] > for chunk in response: > if len(chunk.choices) == 0: > continue > > delta = chunk.choices[0] > > # extract tool calls from response > self._update_tool_calls(tool_calls=tool_calls, tool_calls_response=delta.delta.tool_calls) > > # Handling exceptions when content filters' streaming mode is set to asynchronous modified filter > if delta.finish_reason is None and not delta.delta.content: > continue > > # transform assistant message to prompt message > assistant_prompt_message = AssistantPromptMessage( > content=delta.delta.content if delta.delta.content else '', > tool_calls=tool_calls > ) > > full_assistant_content += delta.delta.content if delta.delta.content else '' > > real_model = chunk.model > system_fingerprint = chunk.system_fingerprint > completion += delta.delta.content if delta.delta.content else '' > > yield LLMResultChunk( > model=real_model, > prompt_messages=prompt_messages, > system_fingerprint=system_fingerprint, > delta=LLMResultChunkDelta( > index=index, > message=assistant_prompt_message, > ) > ) > > index += 0 > > # calculate num tokens > prompt_tokens = self._num_tokens_from_messages(credentials, prompt_messages, tools) > ``` > > Additionally, ensure that the arguments are properly encoded as JSON strings to avoid encoding issues. The following snippet from the `FunctionCallAgentRunner` class in the Dify platform demonstrates how to handle tool call arguments: > > ```python > assistant_message = AssistantPromptMessage( > content='', > tool_calls=[] > ) > if tool_calls: > assistant_message.tool_calls=[ > AssistantPromptMessage.ToolCall( > id=tool_call[0], > type='function', > function=AssistantPromptMessage.ToolCall.ToolCallFunction( > name=tool_call[1], > arguments=json.dumps(tool_call[2], ensure_ascii=False) > ) > ) for tool_call in tool_calls > ] > else: > assistant_message.content = response > > self._current_thoughts.append(assistant_message) > ``` > > This change ensures that the arguments are properly encoded as JSON strings, preventing potential corruption or encoding issues. Additionally, the `_handle_generate_stream_response` method has been updated to properly handle tool calls and ensure the integrity of the arguments over multiple rounds of conversation [[1]](https://github.com/langgenius/dify/blob/main/api/core/model_runtime/model_providers/openai_api_compatible/llm/llm.py)[[2]](https://github.com/langgenius/dify/blob/main/api/core/model_runtime/model_providers/azure_openai/llm/llm.py)[[3]](https://github.com/langgenius/dify/blob/main/api/core/agent/fc_agent_runner.py)[[4]](https://github.com/langgenius/dify/blob/main/api/core/model_runtime/model_providers/moonshot/llm/llm.py). > > _To continue talking to [Dosu](https://dosu.dev), mention @dosu._ hello,In the created Agent application, when using custom tools (with both tool names and parameters in Chinese), the agent's thinking process occasionally encounters issues with Chinese character encoding, resulting in garbled text. Through debugging, I found that the garbled text appears in the resp within llm.py (xinference). Additionally, even when there is garbled text, the parameters are not correctly parsed during tool invocation. For example, the parameter '中坤' goes through the process: '中坤' --> garbled text --> '中移', which leads to errors.
Author
Owner

@FAFUuser commented on GitHub (Sep 5, 2024):

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.6.15

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

Model

qwen-2-72B

Problems

During the process of using agents for function calls and multiple rounds of conversations, we found that the latter few rounds of conversations would produce abnormal responses. By examining the database, we found that there is an issue with ("tool_calls" ->"function" ->"arguments") when retrieving history in multiple rounds of conversations. We let the arguments be a json list with 2 attributes -- 'action' and 'demand'. The 'tool_calls' result is rightly shown, but in the second and three rounds of conversation, agent should first get the histroy results. We found that there are '\'s in 'arguments':

"arguments": "{\"preferences\": \"[{'action': '\\u963b\\u6b62', 'demand': '\\u65b0\\u4eac\\u62a5'}]\"}"}}

The correct one should be `"arguments": "{"preferences": "[{'action': '\u963b\u6b62', 'demand': '\u65b0\u4eac\u62a5'}]"}"}}

This situation will lead to abnormal performance of the agent in the later rounds.

This issue may be caused by encoding problems during the reading and writing of history in multiple rounds of dialogue.

The following are the database records and the results after decoding. We can see that there are '\'s in the 'arguments', ade there is a problem with the output of the last two rounds, as it outputs' 英阳联盟' instead of '英雄联盟'

`### Database records

round1

[{"role": "user", "text": "\u4e0d\u60f3\u770b\u65b0\u4eac\u62a5", "files": []}, {"role": "assistant", "text": "", "files": [], "tool_calls": [{"id": "call_8a7e093f-8938-4d7c-81ac-65e43aa8fa3b", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\u963b\u6b62', 'demand': '\u65b0\u4eac\u62a5'}]\"}"}}]}, {"role": "tool", "text": "{\"profile\": [{\"granularity\": \"TNAME\", \"type\": \"ALL\", \"content\": \"T1486538331796\", \"priority\": -1.0}], \"message\": \"\u5df2\u7ecf\u6839\u636e\u60a8\u7684\u5429\u5490\u8c03\u6574\u4e86\u63a8\u8350\u6a21\u5f0f\uff0c\u73b0\u5728\u60a8\u53ef\u4ee5\u53bb\u4e00\u63a2\u7a76\u7adf\u5566\uff01\"}", "files": [], "tool_calls": [{"id": "call_8a7e093f-8938-4d7c-81ac-65e43aa8fa3b", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\u963b\u6b62', 'demand': '\u65b0\u4eac\u62a5'}]\"}"}}]}]

round2

[{"role": "user", "text": "\u4e0d\u60f3\u770b\u65b0\u4eac\u62a5", "files": []}, {"role": "assistant", "text": "\u7528\u6237\u8868\u8fbe\u4e86\u4e0d\u60f3\u770b\u6765\u81ea\u201c\u65b0\u4eac\u62a5\u201d\u7684\u5185\u5bb9\uff0c\u8fd9\u6d89\u53ca\u5230\u8c03\u6574\u63a8\u8350\u5185\u5bb9\uff0c\u963b\u6b62\u7279\u5b9a\u6765\u6e90\u7684\u4fe1\u606f\u3002", "files": [], "tool_calls": [{"id": "a7455157-a8ea-4a7c-8d21-529de2fdab0b", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\\u963b\\u6b62', 'demand': '\\u65b0\\u4eac\\u62a5'}]\"}"}}]}, {"role": "tool", "text": "{\"profile\": [{\"granularity\": \"TNAME\", \"type\": \"ALL\", \"content\": \"T1486538331796\", \"priority\": -1.0}], \"message\": \"\u5df2\u7ecf\u6839\u636e\u60a8\u7684\u5429\u5490\u8c03\u6574\u4e86\u63a8\u8350\u6a21\u5f0f\uff0c\u73b0\u5728\u60a8\u53ef\u4ee5\u53bb\u4e00\u63a2\u7a76\u7adf\u5566\uff01\"}", "files": [], "tool_calls": [{"id": "a7455157-a8ea-4a7c-8d21-529de2fdab0b", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\\u963b\\u6b62', 'demand': '\\u65b0\\u4eac\\u62a5'}]\"}"}}]}, {"role": "assistant", "text": "\u6211\u5df2\u7ecf\u5e2e\u60a8\u8bbe\u7f6e\u597d\u4e86\uff0c\u60a8\u5c06\u4e0d\u518d\u770b\u5230\u65b0\u4eac\u62a5\u7684\u76f8\u5173\u4fe1\u606f\u3002", "files": []}, {"role": "user", "text": "\u60f3\u770b\u82f1\u96c4\u8054\u76df", "files": []}, {"role": "assistant", "text": "", "files": [], "tool_calls": [{"id": "call_3eb89cec-17f8-4cf6-beb3-f0883b6a1386", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\u589e\u52a0', 'demand': '\u82f1\u9633\u8054\u76df'}]\"}"}}]}, {"role": "tool", "text": "{\"message\": \"\u6536\u5230\u60a8\u7684\u5429\u5490\u4e86\uff0c\u53ef\u8fd9\u4e2a\u8981\u6c42\u597d\u96be\uff0c\u6682\u65f6\u505a\u4e0d\u5230\uff0c\u8bf7\u6362\u4e2a\u8bf4\u6cd5\u8bd5\u8bd5\uff01\"}", "files": [], "tool_calls": [{"id": "call_3eb89cec-17f8-4cf6-beb3-f0883b6a1386", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\u589e\u52a0', 'demand': '\u82f1\u9633\u8054\u76df'}]\"}"}}]}]

round3

[{"role": "user", "text": "\u4e0d\u60f3\u770b\u65b0\u4eac\u62a5", "files": []}, {"role": "assistant", "text": "\u7528\u6237\u8868\u8fbe\u4e86\u4e0d\u60f3\u770b\u6765\u81ea\u201c\u65b0\u4eac\u62a5\u201d\u7684\u5185\u5bb9\uff0c\u8fd9\u6d89\u53ca\u5230\u8c03\u6574\u63a8\u8350\u5185\u5bb9\uff0c\u963b\u6b62\u7279\u5b9a\u6765\u6e90\u7684\u4fe1\u606f\u3002", "files": [], "tool_calls": [{"id": "222fed6b-c2fc-416d-8e0a-60c2d38a0a67", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\\u963b\\u6b62', 'demand': '\\u65b0\\u4eac\\u62a5'}]\"}"}}]}, {"role": "tool", "text": "{\"profile\": [{\"granularity\": \"TNAME\", \"type\": \"ALL\", \"content\": \"T1486538331796\", \"priority\": -1.0}], \"message\": \"\u5df2\u7ecf\u6839\u636e\u60a8\u7684\u5429\u5490\u8c03\u6574\u4e86\u63a8\u8350\u6a21\u5f0f\uff0c\u73b0\u5728\u60a8\u53ef\u4ee5\u53bb\u4e00\u63a2\u7a76\u7adf\u5566\uff01\"}", "files": [], "tool_calls": [{"id": "222fed6b-c2fc-416d-8e0a-60c2d38a0a67", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\\u963b\\u6b62', 'demand': '\\u65b0\\u4eac\\u62a5'}]\"}"}}]}, {"role": "assistant", "text": "\u6211\u5df2\u7ecf\u5e2e\u60a8\u8bbe\u7f6e\u597d\u4e86\uff0c\u60a8\u5c06\u4e0d\u518d\u770b\u5230\u65b0\u4eac\u62a5\u7684\u76f8\u5173\u4fe1\u606f\u3002", "files": []}, {"role": "user", "text": "\u60f3\u770b\u82f1\u96c4\u8054\u76df", "files": []}, {"role": "assistant", "text": "I can use ai_agent_profile.", "files": [], "tool_calls": [{"id": "8613338c-5e89-4e11-b675-762011a74f7e", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\\u589e\\u52a0', 'demand': '\\u82f1\\u9633\\u8054\\u76df'}]\"}"}}]}, {"role": "tool", "text": "{\"message\": \"\u6536\u5230\u60a8\u7684\u5429\u5490\u4e86\uff0c\u53ef\u8fd9\u4e2a\u8981\u6c42\u597d\u96be\uff0c\u6682\u65f6\u505a\u4e0d\u5230\uff0c\u8bf7\u6362\u4e2a\u8bf4\u6cd5\u8bd5\u8bd5\uff01\"}", "files": [], "tool_calls": [{"id": "8613338c-5e89-4e11-b675-762011a74f7e", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\\u589e\\u52a0', 'demand': '\\u82f1\\u9633\\u8054\\u76df'}]\"}"}}]}, {"role": "assistant", "text": "\u6682\u65f6\u65e0\u6cd5\u8bc6\u522b\u201c\u82f1\u9633\u8054\u76df\u201d\uff0c\u53ef\u80fd\u662f\u60a8\u8f93\u5165\u6709\u8bef\uff0c\u6216\u8005\u7684\u80fd\u529b\u6709\u9650\uff0c\u60a8\u53ef\u4ee5\u5c1d\u8bd5\u6362\u4e2a\u8bf4\u6cd5\u3002\u6bd4\u5982\uff0c\u5982\u679c\u60a8\u60f3\u770b\u82f1\u96c4\u8054\u76df\u7684\u65b0\u95fb\u6216\u8005\u8d5b\u4e8b\u4fe1\u606f\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u8f93\u5165\u201c\u82f1\u96c4\u8054\u76df\u65b0\u95fb\u201d\u6216\u8005\u201c\u82f1\u96c4\u8054\u76df\u8d5b\u4e8b\u201d\u3002", "files": []}, {"role": "user", "text": "\u591a\u63a8\u82f1\u96c4\u8054\u76df", "files": []}, {"role": "assistant", "text": "", "files": [], "tool_calls": [{"id": "call_f640f05c-eb9f-43f0-86ed-1397fabf2c37", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\u589e\u52a0', 'demand': '\u82f1\u9633\u8054\u76df'}]\"}"}}]}, {"role": "tool", "text": "{\"message\": \"\u6536\u5230\u60a8\u7684\u5429\u5490\u4e86\uff0c\u53ef\u8fd9\u4e2a\u8981\u6c42\u597d\u96be\uff0c\u6682\u65f6\u505a\u4e0d\u5230\uff0c\u8bf7\u6362\u4e2a\u8bf4\u6cd5\u8bd5\u8bd5\uff01\"}", "files": [], "tool_calls": [{"id": "call_f640f05c-eb9f-43f0-86ed-1397fabf2c37", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\u589e\u52a0', 'demand': '\u82f1\u9633\u8054\u76df'}]\"}"}}]}]

Database records after prasing

[{'role': 'user', 'text': '不想看新京报', 'files': []}, {'role': 'assistant', 'text': '', 'files': [], 'tool_calls': [{'id': 'call_8a7e093f-8938-4d7c-81ac-65e43aa8fa3b', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'阻止\', \'demand\': \'新京报\'}]"}'}}]}, {'role': 'tool', 'text': '{"profile": [{"granularity": "TNAME", "type": "ALL", "content": "T1486538331796", "priority": -1.0}], "message": "已经根据您 的吩咐调整了推荐模式,现在您可以去一探究竟啦!"}', 'files': [], 'tool_calls': [{'id': 'call_8a7e093f-8938-4d7c-81ac-65e43aa8fa3b', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'阻止\', \'demand\': \'新京报\'}]"}'}}]}]

[{'role': 'user', 'text': '不想看新京报', 'files': []}, {'role': 'assistant', 'text': '用户表达了不想看来自“新京报”的内容,这涉及到调整推荐内容,阻止特定来源的信息。', 'files': [], 'tool_calls': [{'id': 'a7455157-a8ea-4a7c-8d21-529de2fdab0b', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'\\u963b\\u6b62\', \'demand\': \'\\u65b0\\u4eac\\u62a5\'}]"}'}}]}, {'role': 'tool', 'text': '{"profile": [{"granularity": "TNAME", "type": "ALL", "content": "T1486538331796", "priority": -1.0}], "message": "已经根据您的吩咐调整了推荐模式,现在您可以去一探究竟啦!"}', 'files': [], 'tool_calls': [{'id': 'a7455157-a8ea-4a7c-8d21-529de2fdab0b', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'\\u963b\\u6b62\', \'demand\':\'\\u65b0\\u4eac\\u62a5\'}]"}'}}]}, {'role': 'assistant', 'text': '我已经帮您设置好了,您将不再看到新京报的相关信息。', 'files': []}, {'role': 'user', 'text': '想看英雄联盟', 'files': []}, {'role': 'assistant', 'text': '', 'files': [], 'tool_calls': [{'id': 'call_3eb89cec-17f8-4cf6-beb3-f0883b6a1386', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'增加\', \'demand\': \'英阳联盟\'}]"}'}}]}, {'role': 'tool', 'text': '{"message": "收到您的吩咐了,可这个要求好难,暂时做不到,请换个说法试试!"}', 'files': [], 'tool_calls': [{'id': 'call_3eb89cec-17f8-4cf6-beb3-f0883b6a1386', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'增加\', \'demand\': \'英阳联盟\'}]"}'}}]}]

[{'role': 'user', 'text': '不想看新京报', 'files': []}, {'role': 'assistant', 'text': '用户表达了不想看来自“新京报”的内容,这涉及到调整推荐内容,阻止特定来源的信息。', 'files': [], 'tool_calls': [{'id': '222fed6b-c2fc-416d-8e0a-60c2d38a0a67', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'\\u963b\\u6b62\', \'demand\': \'\\u65b0\\u4eac\\u62a5\'}]"}'}}]}, {'role': 'tool', 'text': '{"profile": [{"granularity": "TNAME", "type": "ALL", "content": "T1486538331796", "priority": -1.0}], "message": "已经根据您的吩咐调整了推荐模式,现在您可以去一探究竟啦!"}', 'files': [], 'tool_calls': [{'id': '222fed6b-c2fc-416d-8e0a-60c2d38a0a67', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'\\u963b\\u6b62\', \'demand\': \'\\u65b0\\u4eac\\u62a5\'}]"}'}}]}, {'role': 'assistant', 'text': '我已经帮您设置好了,您将不再看到新京报的相关信息。', 'files': []}, {'role': 'user', 'text': '想看英雄联盟', 'files': []}, {'role': 'assistant', 'text': 'I can use ai_agent_profile.', 'files': [], 'tool_calls': [{'id': '8613338c-5e89-4e11-b675-762011a74f7e', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'\\u589e\\u52a0\', \'demand\': \'\\u82f1\\u9633\\u8054\\u76df\'}]"}'}}]}, {'role': 'tool', 'text': '{"message": "收到您的吩咐了,可这个要求好难,暂时做不到,请换个说法试试!"}', 'files': [], 'tool_calls': [{'id': '8613338c-5e89-4e11-b675-762011a74f7e', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'\\u589e\\u52a0\', \'demand\': \'\\u82f1\\u9633\\u8054\\u76df\'*}]"}'}}]}, {'role': 'assistant', 'text': '暂时无法识别“英阳联盟”,可能是您输入有误。', 'files': []}, {'role': 'user', 'text': '多推英雄联盟', 'files': []}, {'role': 'assistant', 'text': '', 'files': [], 'tool_calls': [{'id': 'call_f640f05c-eb9f-43f0-86ed-1397fabf2c37', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'增加\', \'demand\': \'英阳联盟\'}]"}'}}]}, {'role': 'tool', 'text': '{"message": "收到您的吩咐了,可这个要求好难,暂时做不到,请换个说法试试!"}', 'files': [], 'tool_calls': [{'id': 'call_f640f05c-eb9f-43f0-86ed-1397fabf2c37', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'增加\', \'demand\': \'英阳联盟\'}]"}'}}]}]

✔️ Expected Behavior

"arguments": "{\"preferences\": \"[{'action': '\u963b\u6b62', 'demand': '\u65b0\u4eac\u62a5'}]\"}"}}

Actual Behavior

"arguments": "{\"preferences\": \"[{'action': '\\u963b\\u6b62', 'demand': '\\u65b0\\u4eac\\u62a5'}]\"}"}}
Hello, have you resolved the issue with Chinese characters appearing as garbled text?

@FAFUuser commented on GitHub (Sep 5, 2024): > ### Self Checks > * [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). > * [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. > * [x] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). > * [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) > * [x] Please do not modify this template :) and fill in all the required fields. > > ### Dify version > 0.6.15 > > ### Cloud or Self Hosted > Self Hosted (Docker) > > ### Steps to reproduce > ### Model > qwen-2-72B > > ### Problems > During the process of using agents for function calls and multiple rounds of conversations, we found that the latter few rounds of conversations would produce abnormal responses. By examining the database, we found that there is an issue with ("tool_calls" ->"function" ->"arguments") when retrieving history in multiple rounds of conversations. We let the arguments be a json list with 2 attributes -- 'action' and 'demand'. The 'tool_calls' result is rightly shown, but in the second and three rounds of conversation, agent should first get the histroy results. We found that there are '\\'s in 'arguments': > > `"arguments": "{\"preferences\": \"[{'action': '\\u963b\\u6b62', 'demand': '\\u65b0\\u4eac\\u62a5'}]\"}"}} ` > > The correct one should be `"arguments": "{"preferences": "[{'action': '\u963b\u6b62', 'demand': '\u65b0\u4eac\u62a5'}]"}"}} > > This situation will lead to abnormal performance of the agent in the later rounds. > > This issue may be caused by encoding problems during the reading and writing of history in multiple rounds of dialogue. > > The following are the database records and the results after decoding. We can see that there are '\\'s in the 'arguments', ade there is a problem with the output of the last two rounds, as it outputs' 英阳联盟' instead of '英雄联盟' > > `### Database records > > #### round1 > `[{"role": "user", "text": "\u4e0d\u60f3\u770b\u65b0\u4eac\u62a5", "files": []}, {"role": "assistant", "text": "", "files": [], "tool_calls": [{"id": "call_8a7e093f-8938-4d7c-81ac-65e43aa8fa3b", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\u963b\u6b62', 'demand': '\u65b0\u4eac\u62a5'}]\"}"}}]}, {"role": "tool", "text": "{\"profile\": [{\"granularity\": \"TNAME\", \"type\": \"ALL\", \"content\": \"T1486538331796\", \"priority\": -1.0}], \"message\": \"\u5df2\u7ecf\u6839\u636e\u60a8\u7684\u5429\u5490\u8c03\u6574\u4e86\u63a8\u8350\u6a21\u5f0f\uff0c\u73b0\u5728\u60a8\u53ef\u4ee5\u53bb\u4e00\u63a2\u7a76\u7adf\u5566\uff01\"}", "files": [], "tool_calls": [{"id": "call_8a7e093f-8938-4d7c-81ac-65e43aa8fa3b", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\u963b\u6b62', 'demand': '\u65b0\u4eac\u62a5'}]\"}"}}]}]` > > #### round2 > `[{"role": "user", "text": "\u4e0d\u60f3\u770b\u65b0\u4eac\u62a5", "files": []}, {"role": "assistant", "text": "\u7528\u6237\u8868\u8fbe\u4e86\u4e0d\u60f3\u770b\u6765\u81ea\u201c\u65b0\u4eac\u62a5\u201d\u7684\u5185\u5bb9\uff0c\u8fd9\u6d89\u53ca\u5230\u8c03\u6574\u63a8\u8350\u5185\u5bb9\uff0c\u963b\u6b62\u7279\u5b9a\u6765\u6e90\u7684\u4fe1\u606f\u3002", "files": [], "tool_calls": [{"id": "a7455157-a8ea-4a7c-8d21-529de2fdab0b", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\\u963b\\u6b62', 'demand': '\\u65b0\\u4eac\\u62a5'}]\"}"}}]}, {"role": "tool", "text": "{\"profile\": [{\"granularity\": \"TNAME\", \"type\": \"ALL\", \"content\": \"T1486538331796\", \"priority\": -1.0}], \"message\": \"\u5df2\u7ecf\u6839\u636e\u60a8\u7684\u5429\u5490\u8c03\u6574\u4e86\u63a8\u8350\u6a21\u5f0f\uff0c\u73b0\u5728\u60a8\u53ef\u4ee5\u53bb\u4e00\u63a2\u7a76\u7adf\u5566\uff01\"}", "files": [], "tool_calls": [{"id": "a7455157-a8ea-4a7c-8d21-529de2fdab0b", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\\u963b\\u6b62', 'demand': '\\u65b0\\u4eac\\u62a5'}]\"}"}}]}, {"role": "assistant", "text": "\u6211\u5df2\u7ecf\u5e2e\u60a8\u8bbe\u7f6e\u597d\u4e86\uff0c\u60a8\u5c06\u4e0d\u518d\u770b\u5230\u65b0\u4eac\u62a5\u7684\u76f8\u5173\u4fe1\u606f\u3002", "files": []}, {"role": "user", "text": "\u60f3\u770b\u82f1\u96c4\u8054\u76df", "files": []}, {"role": "assistant", "text": "", "files": [], "tool_calls": [{"id": "call_3eb89cec-17f8-4cf6-beb3-f0883b6a1386", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\u589e\u52a0', 'demand': '\u82f1\u9633\u8054\u76df'}]\"}"}}]}, {"role": "tool", "text": "{\"message\": \"\u6536\u5230\u60a8\u7684\u5429\u5490\u4e86\uff0c\u53ef\u8fd9\u4e2a\u8981\u6c42\u597d\u96be\uff0c\u6682\u65f6\u505a\u4e0d\u5230\uff0c\u8bf7\u6362\u4e2a\u8bf4\u6cd5\u8bd5\u8bd5\uff01\"}", "files": [], "tool_calls": [{"id": "call_3eb89cec-17f8-4cf6-beb3-f0883b6a1386", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\u589e\u52a0', 'demand': '\u82f1\u9633\u8054\u76df'}]\"}"}}]}]` > > #### round3 > `[{"role": "user", "text": "\u4e0d\u60f3\u770b\u65b0\u4eac\u62a5", "files": []}, {"role": "assistant", "text": "\u7528\u6237\u8868\u8fbe\u4e86\u4e0d\u60f3\u770b\u6765\u81ea\u201c\u65b0\u4eac\u62a5\u201d\u7684\u5185\u5bb9\uff0c\u8fd9\u6d89\u53ca\u5230\u8c03\u6574\u63a8\u8350\u5185\u5bb9\uff0c\u963b\u6b62\u7279\u5b9a\u6765\u6e90\u7684\u4fe1\u606f\u3002", "files": [], "tool_calls": [{"id": "222fed6b-c2fc-416d-8e0a-60c2d38a0a67", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\\u963b\\u6b62', 'demand': '\\u65b0\\u4eac\\u62a5'}]\"}"}}]}, {"role": "tool", "text": "{\"profile\": [{\"granularity\": \"TNAME\", \"type\": \"ALL\", \"content\": \"T1486538331796\", \"priority\": -1.0}], \"message\": \"\u5df2\u7ecf\u6839\u636e\u60a8\u7684\u5429\u5490\u8c03\u6574\u4e86\u63a8\u8350\u6a21\u5f0f\uff0c\u73b0\u5728\u60a8\u53ef\u4ee5\u53bb\u4e00\u63a2\u7a76\u7adf\u5566\uff01\"}", "files": [], "tool_calls": [{"id": "222fed6b-c2fc-416d-8e0a-60c2d38a0a67", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\\u963b\\u6b62', 'demand': '\\u65b0\\u4eac\\u62a5'}]\"}"}}]}, {"role": "assistant", "text": "\u6211\u5df2\u7ecf\u5e2e\u60a8\u8bbe\u7f6e\u597d\u4e86\uff0c\u60a8\u5c06\u4e0d\u518d\u770b\u5230\u65b0\u4eac\u62a5\u7684\u76f8\u5173\u4fe1\u606f\u3002", "files": []}, {"role": "user", "text": "\u60f3\u770b\u82f1\u96c4\u8054\u76df", "files": []}, {"role": "assistant", "text": "I can use ai_agent_profile.", "files": [], "tool_calls": [{"id": "8613338c-5e89-4e11-b675-762011a74f7e", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\\u589e\\u52a0', 'demand': '\\u82f1\\u9633\\u8054\\u76df'}]\"}"}}]}, {"role": "tool", "text": "{\"message\": \"\u6536\u5230\u60a8\u7684\u5429\u5490\u4e86\uff0c\u53ef\u8fd9\u4e2a\u8981\u6c42\u597d\u96be\uff0c\u6682\u65f6\u505a\u4e0d\u5230\uff0c\u8bf7\u6362\u4e2a\u8bf4\u6cd5\u8bd5\u8bd5\uff01\"}", "files": [], "tool_calls": [{"id": "8613338c-5e89-4e11-b675-762011a74f7e", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\\u589e\\u52a0', 'demand': '\\u82f1\\u9633\\u8054\\u76df'}]\"}"}}]}, {"role": "assistant", "text": "\u6682\u65f6\u65e0\u6cd5\u8bc6\u522b\u201c\u82f1\u9633\u8054\u76df\u201d\uff0c\u53ef\u80fd\u662f\u60a8\u8f93\u5165\u6709\u8bef\uff0c\u6216\u8005\u7684\u80fd\u529b\u6709\u9650\uff0c\u60a8\u53ef\u4ee5\u5c1d\u8bd5\u6362\u4e2a\u8bf4\u6cd5\u3002\u6bd4\u5982\uff0c\u5982\u679c\u60a8\u60f3\u770b\u82f1\u96c4\u8054\u76df\u7684\u65b0\u95fb\u6216\u8005\u8d5b\u4e8b\u4fe1\u606f\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u8f93\u5165\u201c\u82f1\u96c4\u8054\u76df\u65b0\u95fb\u201d\u6216\u8005\u201c\u82f1\u96c4\u8054\u76df\u8d5b\u4e8b\u201d\u3002", "files": []}, {"role": "user", "text": "\u591a\u63a8\u82f1\u96c4\u8054\u76df", "files": []}, {"role": "assistant", "text": "", "files": [], "tool_calls": [{"id": "call_f640f05c-eb9f-43f0-86ed-1397fabf2c37", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\u589e\u52a0', 'demand': '\u82f1\u9633\u8054\u76df'}]\"}"}}]}, {"role": "tool", "text": "{\"message\": \"\u6536\u5230\u60a8\u7684\u5429\u5490\u4e86\uff0c\u53ef\u8fd9\u4e2a\u8981\u6c42\u597d\u96be\uff0c\u6682\u65f6\u505a\u4e0d\u5230\uff0c\u8bf7\u6362\u4e2a\u8bf4\u6cd5\u8bd5\u8bd5\uff01\"}", "files": [], "tool_calls": [{"id": "call_f640f05c-eb9f-43f0-86ed-1397fabf2c37", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\u589e\u52a0', 'demand': '\u82f1\u9633\u8054\u76df'}]\"}"}}]}]` > > ### Database records after prasing > `[{'role': 'user', 'text': '不想看新京报', 'files': []}, {'role': 'assistant', 'text': '', 'files': [], 'tool_calls': [{'id': 'call_8a7e093f-8938-4d7c-81ac-65e43aa8fa3b', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'阻止\', \'demand\': \'新京报\'}]"}'}}]}, {'role': 'tool', 'text': '{"profile": [{"granularity": "TNAME", "type": "ALL", "content": "T1486538331796", "priority": -1.0}], "message": "已经根据您 的吩咐调整了推荐模式,现在您可以去一探究竟啦!"}', 'files': [], 'tool_calls': [{'id': 'call_8a7e093f-8938-4d7c-81ac-65e43aa8fa3b', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'阻止\', \'demand\': \'新京报\'}]"}'}}]}]` > > `[{'role': 'user', 'text': '不想看新京报', 'files': []}, {'role': 'assistant', 'text': '用户表达了不想看来自“新京报”的内容,这涉及到调整推荐内容,阻止特定来源的信息。', 'files': [], 'tool_calls': [{'id': 'a7455157-a8ea-4a7c-8d21-529de2fdab0b', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'\\u963b\\u6b62\', \'demand\': \'\\u65b0\\u4eac\\u62a5\'}]"}'}}]}, {'role': 'tool', 'text': '{"profile": [{"granularity": "TNAME", "type": "ALL", "content": "T1486538331796", "priority": -1.0}], "message": "已经根据您的吩咐调整了推荐模式,现在您可以去一探究竟啦!"}', 'files': [], 'tool_calls': [{'id': 'a7455157-a8ea-4a7c-8d21-529de2fdab0b', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'\\u963b\\u6b62\', \'demand\':\'\\u65b0\\u4eac\\u62a5\'}]"}'}}]}, {'role': 'assistant', 'text': '我已经帮您设置好了,您将不再看到新京报的相关信息。', 'files': []}, {'role': 'user', 'text': '想看英雄联盟', 'files': []}, {'role': 'assistant', 'text': '', 'files': [], 'tool_calls': [{'id': 'call_3eb89cec-17f8-4cf6-beb3-f0883b6a1386', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'增加\', \'demand\': \'英阳联盟\'}]"}'}}]}, {'role': 'tool', 'text': '{"message": "收到您的吩咐了,可这个要求好难,暂时做不到,请换个说法试试!"}', 'files': [], 'tool_calls': [{'id': 'call_3eb89cec-17f8-4cf6-beb3-f0883b6a1386', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'增加\', \'demand\': \'英阳联盟\'}]"}'}}]}]` > > `[{'role': 'user', 'text': '不想看新京报', 'files': []}, {'role': 'assistant', 'text': '用户表达了不想看来自“新京报”的内容,这涉及到调整推荐内容,阻止特定来源的信息。', 'files': [], 'tool_calls': [{'id': '222fed6b-c2fc-416d-8e0a-60c2d38a0a67', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'\\u963b\\u6b62\', \'demand\': \'\\u65b0\\u4eac\\u62a5\'}]"}'}}]}, {'role': 'tool', 'text': '{"profile": [{"granularity": "TNAME", "type": "ALL", "content": "T1486538331796", "priority": -1.0}], "message": "已经根据您的吩咐调整了推荐模式,现在您可以去一探究竟啦!"}', 'files': [], 'tool_calls': [{'id': '222fed6b-c2fc-416d-8e0a-60c2d38a0a67', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'\\u963b\\u6b62\', \'demand\': \'\\u65b0\\u4eac\\u62a5\'}]"}'}}]}, {'role': 'assistant', 'text': '我已经帮您设置好了,您将不再看到新京报的相关信息。', 'files': []}, {'role': 'user', 'text': '想看英雄联盟', 'files': []}, {'role': 'assistant', 'text': 'I can use ai_agent_profile.', 'files': [], 'tool_calls': [{'id': '8613338c-5e89-4e11-b675-762011a74f7e', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'\\u589e\\u52a0\', \'demand\': \'\\u82f1\\u9633\\u8054\\u76df\'}]"}'}}]}, {'role': 'tool', 'text': '{"message": "收到您的吩咐了,可这个要求好难,暂时做不到,请换个说法试试!"}', 'files': [], 'tool_calls': [{'id': '8613338c-5e89-4e11-b675-762011a74f7e', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'\\u589e\\u52a0\', \'demand\': \'\\u82f1\\u9633\\u8054\\u76df\'*}]"}'}}]}, {'role': 'assistant', 'text': '暂时无法识别“英阳联盟”,可能是您输入有误。', 'files': []}, {'role': 'user', 'text': '多推英雄联盟', 'files': []}, {'role': 'assistant', 'text': '', 'files': [], 'tool_calls': [{'id': 'call_f640f05c-eb9f-43f0-86ed-1397fabf2c37', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'增加\', \'demand\': \'英阳联盟\'}]"}'}}]}, {'role': 'tool', 'text': '{"message": "收到您的吩咐了,可这个要求好难,暂时做不到,请换个说法试试!"}', 'files': [], 'tool_calls': [{'id': 'call_f640f05c-eb9f-43f0-86ed-1397fabf2c37', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'增加\', \'demand\': \'英阳联盟\'}]"}'}}]}]` > > ### ✔️ Expected Behavior > `"arguments": "{\"preferences\": \"[{'action': '\u963b\u6b62', 'demand': '\u65b0\u4eac\u62a5'}]\"}"}} ` > > ### ❌ Actual Behavior > `"arguments": "{\"preferences\": \"[{'action': '\\u963b\\u6b62', 'demand': '\\u65b0\\u4eac\\u62a5'}]\"}"}} ` Hello, have you resolved the issue with Chinese characters appearing as garbled text?
Author
Owner

@lidajiededa commented on GitHub (Sep 5, 2024):

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.6.15

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

Model

qwen-2-72B

Problems

During the process of using agents for function calls and multiple rounds of conversations, we found that the latter few rounds of conversations would produce abnormal responses. By examining the database, we found that there is an issue with ("tool_calls" ->"function" ->"arguments") when retrieving history in multiple rounds of conversations. We let the arguments be a json list with 2 attributes -- 'action' and 'demand'. The 'tool_calls' result is rightly shown, but in the second and three rounds of conversation, agent should first get the histroy results. We found that there are ''s in 'arguments':
"arguments": "{\"preferences\": \"[{'action': '\\u963b\\u6b62', 'demand': '\\u65b0\\u4eac\\u62a5'}]\"}"}}
The correct one should be "arguments": "{"preferences": "[{'action': '\u963b\u6b62', 'demand': '\u65b0\u4eac\u62a5'}]"}"}} This situation will lead to abnormal performance of the agent in the later rounds. This issue may be caused by encoding problems during the reading and writing of history in multiple rounds of dialogue. The following are the database records and the results after decoding. We can see that there are '\'s in the 'arguments', ade there is a problem with the output of the last two rounds, as it outputs' 英阳联盟' instead of '英雄联盟' ### Database records

round1

[{"role": "user", "text": "\u4e0d\u60f3\u770b\u65b0\u4eac\u62a5", "files": []}, {"role": "assistant", "text": "", "files": [], "tool_calls": [{"id": "call_8a7e093f-8938-4d7c-81ac-65e43aa8fa3b", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\u963b\u6b62', 'demand': '\u65b0\u4eac\u62a5'}]\"}"}}]}, {"role": "tool", "text": "{\"profile\": [{\"granularity\": \"TNAME\", \"type\": \"ALL\", \"content\": \"T1486538331796\", \"priority\": -1.0}], \"message\": \"\u5df2\u7ecf\u6839\u636e\u60a8\u7684\u5429\u5490\u8c03\u6574\u4e86\u63a8\u8350\u6a21\u5f0f\uff0c\u73b0\u5728\u60a8\u53ef\u4ee5\u53bb\u4e00\u63a2\u7a76\u7adf\u5566\uff01\"}", "files": [], "tool_calls": [{"id": "call_8a7e093f-8938-4d7c-81ac-65e43aa8fa3b", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\u963b\u6b62', 'demand': '\u65b0\u4eac\u62a5'}]\"}"}}]}]

round2

[{"role": "user", "text": "\u4e0d\u60f3\u770b\u65b0\u4eac\u62a5", "files": []}, {"role": "assistant", "text": "\u7528\u6237\u8868\u8fbe\u4e86\u4e0d\u60f3\u770b\u6765\u81ea\u201c\u65b0\u4eac\u62a5\u201d\u7684\u5185\u5bb9\uff0c\u8fd9\u6d89\u53ca\u5230\u8c03\u6574\u63a8\u8350\u5185\u5bb9\uff0c\u963b\u6b62\u7279\u5b9a\u6765\u6e90\u7684\u4fe1\u606f\u3002", "files": [], "tool_calls": [{"id": "a7455157-a8ea-4a7c-8d21-529de2fdab0b", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\\u963b\\u6b62', 'demand': '\\u65b0\\u4eac\\u62a5'}]\"}"}}]}, {"role": "tool", "text": "{\"profile\": [{\"granularity\": \"TNAME\", \"type\": \"ALL\", \"content\": \"T1486538331796\", \"priority\": -1.0}], \"message\": \"\u5df2\u7ecf\u6839\u636e\u60a8\u7684\u5429\u5490\u8c03\u6574\u4e86\u63a8\u8350\u6a21\u5f0f\uff0c\u73b0\u5728\u60a8\u53ef\u4ee5\u53bb\u4e00\u63a2\u7a76\u7adf\u5566\uff01\"}", "files": [], "tool_calls": [{"id": "a7455157-a8ea-4a7c-8d21-529de2fdab0b", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\\u963b\\u6b62', 'demand': '\\u65b0\\u4eac\\u62a5'}]\"}"}}]}, {"role": "assistant", "text": "\u6211\u5df2\u7ecf\u5e2e\u60a8\u8bbe\u7f6e\u597d\u4e86\uff0c\u60a8\u5c06\u4e0d\u518d\u770b\u5230\u65b0\u4eac\u62a5\u7684\u76f8\u5173\u4fe1\u606f\u3002", "files": []}, {"role": "user", "text": "\u60f3\u770b\u82f1\u96c4\u8054\u76df", "files": []}, {"role": "assistant", "text": "", "files": [], "tool_calls": [{"id": "call_3eb89cec-17f8-4cf6-beb3-f0883b6a1386", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\u589e\u52a0', 'demand': '\u82f1\u9633\u8054\u76df'}]\"}"}}]}, {"role": "tool", "text": "{\"message\": \"\u6536\u5230\u60a8\u7684\u5429\u5490\u4e86\uff0c\u53ef\u8fd9\u4e2a\u8981\u6c42\u597d\u96be\uff0c\u6682\u65f6\u505a\u4e0d\u5230\uff0c\u8bf7\u6362\u4e2a\u8bf4\u6cd5\u8bd5\u8bd5\uff01\"}", "files": [], "tool_calls": [{"id": "call_3eb89cec-17f8-4cf6-beb3-f0883b6a1386", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\u589e\u52a0', 'demand': '\u82f1\u9633\u8054\u76df'}]\"}"}}]}]

round3

[{"role": "user", "text": "\u4e0d\u60f3\u770b\u65b0\u4eac\u62a5", "files": []}, {"role": "assistant", "text": "\u7528\u6237\u8868\u8fbe\u4e86\u4e0d\u60f3\u770b\u6765\u81ea\u201c\u65b0\u4eac\u62a5\u201d\u7684\u5185\u5bb9\uff0c\u8fd9\u6d89\u53ca\u5230\u8c03\u6574\u63a8\u8350\u5185\u5bb9\uff0c\u963b\u6b62\u7279\u5b9a\u6765\u6e90\u7684\u4fe1\u606f\u3002", "files": [], "tool_calls": [{"id": "222fed6b-c2fc-416d-8e0a-60c2d38a0a67", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\\u963b\\u6b62', 'demand': '\\u65b0\\u4eac\\u62a5'}]\"}"}}]}, {"role": "tool", "text": "{\"profile\": [{\"granularity\": \"TNAME\", \"type\": \"ALL\", \"content\": \"T1486538331796\", \"priority\": -1.0}], \"message\": \"\u5df2\u7ecf\u6839\u636e\u60a8\u7684\u5429\u5490\u8c03\u6574\u4e86\u63a8\u8350\u6a21\u5f0f\uff0c\u73b0\u5728\u60a8\u53ef\u4ee5\u53bb\u4e00\u63a2\u7a76\u7adf\u5566\uff01\"}", "files": [], "tool_calls": [{"id": "222fed6b-c2fc-416d-8e0a-60c2d38a0a67", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\\u963b\\u6b62', 'demand': '\\u65b0\\u4eac\\u62a5'}]\"}"}}]}, {"role": "assistant", "text": "\u6211\u5df2\u7ecf\u5e2e\u60a8\u8bbe\u7f6e\u597d\u4e86\uff0c\u60a8\u5c06\u4e0d\u518d\u770b\u5230\u65b0\u4eac\u62a5\u7684\u76f8\u5173\u4fe1\u606f\u3002", "files": []}, {"role": "user", "text": "\u60f3\u770b\u82f1\u96c4\u8054\u76df", "files": []}, {"role": "assistant", "text": "I can use ai_agent_profile.", "files": [], "tool_calls": [{"id": "8613338c-5e89-4e11-b675-762011a74f7e", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\\u589e\\u52a0', 'demand': '\\u82f1\\u9633\\u8054\\u76df'}]\"}"}}]}, {"role": "tool", "text": "{\"message\": \"\u6536\u5230\u60a8\u7684\u5429\u5490\u4e86\uff0c\u53ef\u8fd9\u4e2a\u8981\u6c42\u597d\u96be\uff0c\u6682\u65f6\u505a\u4e0d\u5230\uff0c\u8bf7\u6362\u4e2a\u8bf4\u6cd5\u8bd5\u8bd5\uff01\"}", "files": [], "tool_calls": [{"id": "8613338c-5e89-4e11-b675-762011a74f7e", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\\u589e\\u52a0', 'demand': '\\u82f1\\u9633\\u8054\\u76df'}]\"}"}}]}, {"role": "assistant", "text": "\u6682\u65f6\u65e0\u6cd5\u8bc6\u522b\u201c\u82f1\u9633\u8054\u76df\u201d\uff0c\u53ef\u80fd\u662f\u60a8\u8f93\u5165\u6709\u8bef\uff0c\u6216\u8005\u7684\u80fd\u529b\u6709\u9650\uff0c\u60a8\u53ef\u4ee5\u5c1d\u8bd5\u6362\u4e2a\u8bf4\u6cd5\u3002\u6bd4\u5982\uff0c\u5982\u679c\u60a8\u60f3\u770b\u82f1\u96c4\u8054\u76df\u7684\u65b0\u95fb\u6216\u8005\u8d5b\u4e8b\u4fe1\u606f\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u8f93\u5165\u201c\u82f1\u96c4\u8054\u76df\u65b0\u95fb\u201d\u6216\u8005\u201c\u82f1\u96c4\u8054\u76df\u8d5b\u4e8b\u201d\u3002", "files": []}, {"role": "user", "text": "\u591a\u63a8\u82f1\u96c4\u8054\u76df", "files": []}, {"role": "assistant", "text": "", "files": [], "tool_calls": [{"id": "call_f640f05c-eb9f-43f0-86ed-1397fabf2c37", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\u589e\u52a0', 'demand': '\u82f1\u9633\u8054\u76df'}]\"}"}}]}, {"role": "tool", "text": "{\"message\": \"\u6536\u5230\u60a8\u7684\u5429\u5490\u4e86\uff0c\u53ef\u8fd9\u4e2a\u8981\u6c42\u597d\u96be\uff0c\u6682\u65f6\u505a\u4e0d\u5230\uff0c\u8bf7\u6362\u4e2a\u8bf4\u6cd5\u8bd5\u8bd5\uff01\"}", "files": [], "tool_calls": [{"id": "call_f640f05c-eb9f-43f0-86ed-1397fabf2c37", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\u589e\u52a0', 'demand': '\u82f1\u9633\u8054\u76df'}]\"}"}}]}]

Database records after prasing

[{'role': 'user', 'text': '不想看新京报', 'files': []}, {'role': 'assistant', 'text': '', 'files': [], 'tool_calls': [{'id': 'call_8a7e093f-8938-4d7c-81ac-65e43aa8fa3b', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'阻止\', \'demand\': \'新京报\'}]"}'}}]}, {'role': 'tool', 'text': '{"profile": [{"granularity": "TNAME", "type": "ALL", "content": "T1486538331796", "priority": -1.0}], "message": "已经根据您 的吩咐调整了推荐模式,现在您可以去一探究竟啦!"}', 'files': [], 'tool_calls': [{'id': 'call_8a7e093f-8938-4d7c-81ac-65e43aa8fa3b', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'阻止\', \'demand\': \'新京报\'}]"}'}}]}]
[{'role': 'user', 'text': '不想看新京报', 'files': []}, {'role': 'assistant', 'text': '用户表达了不想看来自“新京报”的内容,这涉及到调整推荐内容,阻止特定来源的信息。', 'files': [], 'tool_calls': [{'id': 'a7455157-a8ea-4a7c-8d21-529de2fdab0b', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'\\u963b\\u6b62\', \'demand\': \'\\u65b0\\u4eac\\u62a5\'}]"}'}}]}, {'role': 'tool', 'text': '{"profile": [{"granularity": "TNAME", "type": "ALL", "content": "T1486538331796", "priority": -1.0}], "message": "已经根据您的吩咐调整了推荐模式,现在您可以去一探究竟啦!"}', 'files': [], 'tool_calls': [{'id': 'a7455157-a8ea-4a7c-8d21-529de2fdab0b', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'\\u963b\\u6b62\', \'demand\':\'\\u65b0\\u4eac\\u62a5\'}]"}'}}]}, {'role': 'assistant', 'text': '我已经帮您设置好了,您将不再看到新京报的相关信息。', 'files': []}, {'role': 'user', 'text': '想看英雄联盟', 'files': []}, {'role': 'assistant', 'text': '', 'files': [], 'tool_calls': [{'id': 'call_3eb89cec-17f8-4cf6-beb3-f0883b6a1386', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'增加\', \'demand\': \'英阳联盟\'}]"}'}}]}, {'role': 'tool', 'text': '{"message": "收到您的吩咐了,可这个要求好难,暂时做不到,请换个说法试试!"}', 'files': [], 'tool_calls': [{'id': 'call_3eb89cec-17f8-4cf6-beb3-f0883b6a1386', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'增加\', \'demand\': \'英阳联盟\'}]"}'}}]}]
[{'role': 'user', 'text': '不想看新京报', 'files': []}, {'role': 'assistant', 'text': '用户表达了不想看来自“新京报”的内容,这涉及到调整推荐内容,阻止特定来源的信息。', 'files': [], 'tool_calls': [{'id': '222fed6b-c2fc-416d-8e0a-60c2d38a0a67', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'\\u963b\\u6b62\', \'demand\': \'\\u65b0\\u4eac\\u62a5\'}]"}'}}]}, {'role': 'tool', 'text': '{"profile": [{"granularity": "TNAME", "type": "ALL", "content": "T1486538331796", "priority": -1.0}], "message": "已经根据您的吩咐调整了推荐模式,现在您可以去一探究竟啦!"}', 'files': [], 'tool_calls': [{'id': '222fed6b-c2fc-416d-8e0a-60c2d38a0a67', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'\\u963b\\u6b62\', \'demand\': \'\\u65b0\\u4eac\\u62a5\'}]"}'}}]}, {'role': 'assistant', 'text': '我已经帮您设置好了,您将不再看到新京报的相关信息。', 'files': []}, {'role': 'user', 'text': '想看英雄联盟', 'files': []}, {'role': 'assistant', 'text': 'I can use ai_agent_profile.', 'files': [], 'tool_calls': [{'id': '8613338c-5e89-4e11-b675-762011a74f7e', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'\\u589e\\u52a0\', \'demand\': \'\\u82f1\\u9633\\u8054\\u76df\'}]"}'}}]}, {'role': 'tool', 'text': '{"message": "收到您的吩咐了,可这个要求好难,暂时做不到,请换个说法试试!"}', 'files': [], 'tool_calls': [{'id': '8613338c-5e89-4e11-b675-762011a74f7e', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'\\u589e\\u52a0\', \'demand\': \'\\u82f1\\u9633\\u8054\\u76df\'*}]"}'}}]}, {'role': 'assistant', 'text': '暂时无法识别“英阳联盟”,可能是您输入有误。', 'files': []}, {'role': 'user', 'text': '多推英雄联盟', 'files': []}, {'role': 'assistant', 'text': '', 'files': [], 'tool_calls': [{'id': 'call_f640f05c-eb9f-43f0-86ed-1397fabf2c37', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'增加\', \'demand\': \'英阳联盟\'}]"}'}}]}, {'role': 'tool', 'text': '{"message": "收到您的吩咐了,可这个要求好难,暂时做不到,请换个说法试试!"}', 'files': [], 'tool_calls': [{'id': 'call_f640f05c-eb9f-43f0-86ed-1397fabf2c37', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'增加\', \'demand\': \'英阳联盟\'}]"}'}}]}]

✔️ Expected Behavior

"arguments": "{\"preferences\": \"[{'action': '\u963b\u6b62', 'demand': '\u65b0\u4eac\u62a5'}]\"}"}}

Actual Behavior

"arguments": "{\"preferences\": \"[{'action': '\\u963b\\u6b62', 'demand': '\\u65b0\\u4eac\\u62a5'}]\"}"}}
Hello, have you resolved the issue with Chinese characters appearing as garbled text?

Hello, I found that qwen2 has already generated Unicode encoding when calling the lowest level API, which is client.chat.completions, to generate content. When this generated content containing Unicode is passed into subsequent stages as history, it may be due to qwen2's insufficient understanding ability, resulting in garbled content in the end. Therefore, I directly decode the content generated by each "client. chat.completions" so that it does not contain Unicode, and there will be no garbled characters afterwards. You can try.

@lidajiededa commented on GitHub (Sep 5, 2024): > > ### Self Checks > > > > * [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). > > * [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. > > * [x] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). > > * [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) > > * [x] Please do not modify this template :) and fill in all the required fields. > > > > ### Dify version > > 0.6.15 > > ### Cloud or Self Hosted > > Self Hosted (Docker) > > ### Steps to reproduce > > ### Model > > qwen-2-72B > > ### Problems > > During the process of using agents for function calls and multiple rounds of conversations, we found that the latter few rounds of conversations would produce abnormal responses. By examining the database, we found that there is an issue with ("tool_calls" ->"function" ->"arguments") when retrieving history in multiple rounds of conversations. We let the arguments be a json list with 2 attributes -- 'action' and 'demand'. The 'tool_calls' result is rightly shown, but in the second and three rounds of conversation, agent should first get the histroy results. We found that there are '\'s in 'arguments': > > `"arguments": "{\"preferences\": \"[{'action': '\\u963b\\u6b62', 'demand': '\\u65b0\\u4eac\\u62a5'}]\"}"}} ` > > The correct one should be `"arguments": "{"preferences": "[{'action': '\u963b\u6b62', 'demand': '\u65b0\u4eac\u62a5'}]"}"}} > > This situation will lead to abnormal performance of the agent in the later rounds. > > This issue may be caused by encoding problems during the reading and writing of history in multiple rounds of dialogue. > > The following are the database records and the results after decoding. We can see that there are '\'s in the 'arguments', ade there is a problem with the output of the last two rounds, as it outputs' 英阳联盟' instead of '英雄联盟' > > `### Database records > > #### round1 > > `[{"role": "user", "text": "\u4e0d\u60f3\u770b\u65b0\u4eac\u62a5", "files": []}, {"role": "assistant", "text": "", "files": [], "tool_calls": [{"id": "call_8a7e093f-8938-4d7c-81ac-65e43aa8fa3b", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\u963b\u6b62', 'demand': '\u65b0\u4eac\u62a5'}]\"}"}}]}, {"role": "tool", "text": "{\"profile\": [{\"granularity\": \"TNAME\", \"type\": \"ALL\", \"content\": \"T1486538331796\", \"priority\": -1.0}], \"message\": \"\u5df2\u7ecf\u6839\u636e\u60a8\u7684\u5429\u5490\u8c03\u6574\u4e86\u63a8\u8350\u6a21\u5f0f\uff0c\u73b0\u5728\u60a8\u53ef\u4ee5\u53bb\u4e00\u63a2\u7a76\u7adf\u5566\uff01\"}", "files": [], "tool_calls": [{"id": "call_8a7e093f-8938-4d7c-81ac-65e43aa8fa3b", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\u963b\u6b62', 'demand': '\u65b0\u4eac\u62a5'}]\"}"}}]}]` > > #### round2 > > `[{"role": "user", "text": "\u4e0d\u60f3\u770b\u65b0\u4eac\u62a5", "files": []}, {"role": "assistant", "text": "\u7528\u6237\u8868\u8fbe\u4e86\u4e0d\u60f3\u770b\u6765\u81ea\u201c\u65b0\u4eac\u62a5\u201d\u7684\u5185\u5bb9\uff0c\u8fd9\u6d89\u53ca\u5230\u8c03\u6574\u63a8\u8350\u5185\u5bb9\uff0c\u963b\u6b62\u7279\u5b9a\u6765\u6e90\u7684\u4fe1\u606f\u3002", "files": [], "tool_calls": [{"id": "a7455157-a8ea-4a7c-8d21-529de2fdab0b", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\\u963b\\u6b62', 'demand': '\\u65b0\\u4eac\\u62a5'}]\"}"}}]}, {"role": "tool", "text": "{\"profile\": [{\"granularity\": \"TNAME\", \"type\": \"ALL\", \"content\": \"T1486538331796\", \"priority\": -1.0}], \"message\": \"\u5df2\u7ecf\u6839\u636e\u60a8\u7684\u5429\u5490\u8c03\u6574\u4e86\u63a8\u8350\u6a21\u5f0f\uff0c\u73b0\u5728\u60a8\u53ef\u4ee5\u53bb\u4e00\u63a2\u7a76\u7adf\u5566\uff01\"}", "files": [], "tool_calls": [{"id": "a7455157-a8ea-4a7c-8d21-529de2fdab0b", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\\u963b\\u6b62', 'demand': '\\u65b0\\u4eac\\u62a5'}]\"}"}}]}, {"role": "assistant", "text": "\u6211\u5df2\u7ecf\u5e2e\u60a8\u8bbe\u7f6e\u597d\u4e86\uff0c\u60a8\u5c06\u4e0d\u518d\u770b\u5230\u65b0\u4eac\u62a5\u7684\u76f8\u5173\u4fe1\u606f\u3002", "files": []}, {"role": "user", "text": "\u60f3\u770b\u82f1\u96c4\u8054\u76df", "files": []}, {"role": "assistant", "text": "", "files": [], "tool_calls": [{"id": "call_3eb89cec-17f8-4cf6-beb3-f0883b6a1386", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\u589e\u52a0', 'demand': '\u82f1\u9633\u8054\u76df'}]\"}"}}]}, {"role": "tool", "text": "{\"message\": \"\u6536\u5230\u60a8\u7684\u5429\u5490\u4e86\uff0c\u53ef\u8fd9\u4e2a\u8981\u6c42\u597d\u96be\uff0c\u6682\u65f6\u505a\u4e0d\u5230\uff0c\u8bf7\u6362\u4e2a\u8bf4\u6cd5\u8bd5\u8bd5\uff01\"}", "files": [], "tool_calls": [{"id": "call_3eb89cec-17f8-4cf6-beb3-f0883b6a1386", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\u589e\u52a0', 'demand': '\u82f1\u9633\u8054\u76df'}]\"}"}}]}]` > > #### round3 > > `[{"role": "user", "text": "\u4e0d\u60f3\u770b\u65b0\u4eac\u62a5", "files": []}, {"role": "assistant", "text": "\u7528\u6237\u8868\u8fbe\u4e86\u4e0d\u60f3\u770b\u6765\u81ea\u201c\u65b0\u4eac\u62a5\u201d\u7684\u5185\u5bb9\uff0c\u8fd9\u6d89\u53ca\u5230\u8c03\u6574\u63a8\u8350\u5185\u5bb9\uff0c\u963b\u6b62\u7279\u5b9a\u6765\u6e90\u7684\u4fe1\u606f\u3002", "files": [], "tool_calls": [{"id": "222fed6b-c2fc-416d-8e0a-60c2d38a0a67", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\\u963b\\u6b62', 'demand': '\\u65b0\\u4eac\\u62a5'}]\"}"}}]}, {"role": "tool", "text": "{\"profile\": [{\"granularity\": \"TNAME\", \"type\": \"ALL\", \"content\": \"T1486538331796\", \"priority\": -1.0}], \"message\": \"\u5df2\u7ecf\u6839\u636e\u60a8\u7684\u5429\u5490\u8c03\u6574\u4e86\u63a8\u8350\u6a21\u5f0f\uff0c\u73b0\u5728\u60a8\u53ef\u4ee5\u53bb\u4e00\u63a2\u7a76\u7adf\u5566\uff01\"}", "files": [], "tool_calls": [{"id": "222fed6b-c2fc-416d-8e0a-60c2d38a0a67", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\\u963b\\u6b62', 'demand': '\\u65b0\\u4eac\\u62a5'}]\"}"}}]}, {"role": "assistant", "text": "\u6211\u5df2\u7ecf\u5e2e\u60a8\u8bbe\u7f6e\u597d\u4e86\uff0c\u60a8\u5c06\u4e0d\u518d\u770b\u5230\u65b0\u4eac\u62a5\u7684\u76f8\u5173\u4fe1\u606f\u3002", "files": []}, {"role": "user", "text": "\u60f3\u770b\u82f1\u96c4\u8054\u76df", "files": []}, {"role": "assistant", "text": "I can use ai_agent_profile.", "files": [], "tool_calls": [{"id": "8613338c-5e89-4e11-b675-762011a74f7e", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\\u589e\\u52a0', 'demand': '\\u82f1\\u9633\\u8054\\u76df'}]\"}"}}]}, {"role": "tool", "text": "{\"message\": \"\u6536\u5230\u60a8\u7684\u5429\u5490\u4e86\uff0c\u53ef\u8fd9\u4e2a\u8981\u6c42\u597d\u96be\uff0c\u6682\u65f6\u505a\u4e0d\u5230\uff0c\u8bf7\u6362\u4e2a\u8bf4\u6cd5\u8bd5\u8bd5\uff01\"}", "files": [], "tool_calls": [{"id": "8613338c-5e89-4e11-b675-762011a74f7e", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\\u589e\\u52a0', 'demand': '\\u82f1\\u9633\\u8054\\u76df'}]\"}"}}]}, {"role": "assistant", "text": "\u6682\u65f6\u65e0\u6cd5\u8bc6\u522b\u201c\u82f1\u9633\u8054\u76df\u201d\uff0c\u53ef\u80fd\u662f\u60a8\u8f93\u5165\u6709\u8bef\uff0c\u6216\u8005\u7684\u80fd\u529b\u6709\u9650\uff0c\u60a8\u53ef\u4ee5\u5c1d\u8bd5\u6362\u4e2a\u8bf4\u6cd5\u3002\u6bd4\u5982\uff0c\u5982\u679c\u60a8\u60f3\u770b\u82f1\u96c4\u8054\u76df\u7684\u65b0\u95fb\u6216\u8005\u8d5b\u4e8b\u4fe1\u606f\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u8f93\u5165\u201c\u82f1\u96c4\u8054\u76df\u65b0\u95fb\u201d\u6216\u8005\u201c\u82f1\u96c4\u8054\u76df\u8d5b\u4e8b\u201d\u3002", "files": []}, {"role": "user", "text": "\u591a\u63a8\u82f1\u96c4\u8054\u76df", "files": []}, {"role": "assistant", "text": "", "files": [], "tool_calls": [{"id": "call_f640f05c-eb9f-43f0-86ed-1397fabf2c37", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\u589e\u52a0', 'demand': '\u82f1\u9633\u8054\u76df'}]\"}"}}]}, {"role": "tool", "text": "{\"message\": \"\u6536\u5230\u60a8\u7684\u5429\u5490\u4e86\uff0c\u53ef\u8fd9\u4e2a\u8981\u6c42\u597d\u96be\uff0c\u6682\u65f6\u505a\u4e0d\u5230\uff0c\u8bf7\u6362\u4e2a\u8bf4\u6cd5\u8bd5\u8bd5\uff01\"}", "files": [], "tool_calls": [{"id": "call_f640f05c-eb9f-43f0-86ed-1397fabf2c37", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\u589e\u52a0', 'demand': '\u82f1\u9633\u8054\u76df'}]\"}"}}]}]` > > ### Database records after prasing > > `[{'role': 'user', 'text': '不想看新京报', 'files': []}, {'role': 'assistant', 'text': '', 'files': [], 'tool_calls': [{'id': 'call_8a7e093f-8938-4d7c-81ac-65e43aa8fa3b', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'阻止\', \'demand\': \'新京报\'}]"}'}}]}, {'role': 'tool', 'text': '{"profile": [{"granularity": "TNAME", "type": "ALL", "content": "T1486538331796", "priority": -1.0}], "message": "已经根据您 的吩咐调整了推荐模式,现在您可以去一探究竟啦!"}', 'files': [], 'tool_calls': [{'id': 'call_8a7e093f-8938-4d7c-81ac-65e43aa8fa3b', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'阻止\', \'demand\': \'新京报\'}]"}'}}]}]` > > `[{'role': 'user', 'text': '不想看新京报', 'files': []}, {'role': 'assistant', 'text': '用户表达了不想看来自“新京报”的内容,这涉及到调整推荐内容,阻止特定来源的信息。', 'files': [], 'tool_calls': [{'id': 'a7455157-a8ea-4a7c-8d21-529de2fdab0b', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'\\u963b\\u6b62\', \'demand\': \'\\u65b0\\u4eac\\u62a5\'}]"}'}}]}, {'role': 'tool', 'text': '{"profile": [{"granularity": "TNAME", "type": "ALL", "content": "T1486538331796", "priority": -1.0}], "message": "已经根据您的吩咐调整了推荐模式,现在您可以去一探究竟啦!"}', 'files': [], 'tool_calls': [{'id': 'a7455157-a8ea-4a7c-8d21-529de2fdab0b', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'\\u963b\\u6b62\', \'demand\':\'\\u65b0\\u4eac\\u62a5\'}]"}'}}]}, {'role': 'assistant', 'text': '我已经帮您设置好了,您将不再看到新京报的相关信息。', 'files': []}, {'role': 'user', 'text': '想看英雄联盟', 'files': []}, {'role': 'assistant', 'text': '', 'files': [], 'tool_calls': [{'id': 'call_3eb89cec-17f8-4cf6-beb3-f0883b6a1386', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'增加\', \'demand\': \'英阳联盟\'}]"}'}}]}, {'role': 'tool', 'text': '{"message": "收到您的吩咐了,可这个要求好难,暂时做不到,请换个说法试试!"}', 'files': [], 'tool_calls': [{'id': 'call_3eb89cec-17f8-4cf6-beb3-f0883b6a1386', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'增加\', \'demand\': \'英阳联盟\'}]"}'}}]}]` > > `[{'role': 'user', 'text': '不想看新京报', 'files': []}, {'role': 'assistant', 'text': '用户表达了不想看来自“新京报”的内容,这涉及到调整推荐内容,阻止特定来源的信息。', 'files': [], 'tool_calls': [{'id': '222fed6b-c2fc-416d-8e0a-60c2d38a0a67', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'\\u963b\\u6b62\', \'demand\': \'\\u65b0\\u4eac\\u62a5\'}]"}'}}]}, {'role': 'tool', 'text': '{"profile": [{"granularity": "TNAME", "type": "ALL", "content": "T1486538331796", "priority": -1.0}], "message": "已经根据您的吩咐调整了推荐模式,现在您可以去一探究竟啦!"}', 'files': [], 'tool_calls': [{'id': '222fed6b-c2fc-416d-8e0a-60c2d38a0a67', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'\\u963b\\u6b62\', \'demand\': \'\\u65b0\\u4eac\\u62a5\'}]"}'}}]}, {'role': 'assistant', 'text': '我已经帮您设置好了,您将不再看到新京报的相关信息。', 'files': []}, {'role': 'user', 'text': '想看英雄联盟', 'files': []}, {'role': 'assistant', 'text': 'I can use ai_agent_profile.', 'files': [], 'tool_calls': [{'id': '8613338c-5e89-4e11-b675-762011a74f7e', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'\\u589e\\u52a0\', \'demand\': \'\\u82f1\\u9633\\u8054\\u76df\'}]"}'}}]}, {'role': 'tool', 'text': '{"message": "收到您的吩咐了,可这个要求好难,暂时做不到,请换个说法试试!"}', 'files': [], 'tool_calls': [{'id': '8613338c-5e89-4e11-b675-762011a74f7e', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'\\u589e\\u52a0\', \'demand\': \'\\u82f1\\u9633\\u8054\\u76df\'*}]"}'}}]}, {'role': 'assistant', 'text': '暂时无法识别“英阳联盟”,可能是您输入有误。', 'files': []}, {'role': 'user', 'text': '多推英雄联盟', 'files': []}, {'role': 'assistant', 'text': '', 'files': [], 'tool_calls': [{'id': 'call_f640f05c-eb9f-43f0-86ed-1397fabf2c37', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'增加\', \'demand\': \'英阳联盟\'}]"}'}}]}, {'role': 'tool', 'text': '{"message": "收到您的吩咐了,可这个要求好难,暂时做不到,请换个说法试试!"}', 'files': [], 'tool_calls': [{'id': 'call_f640f05c-eb9f-43f0-86ed-1397fabf2c37', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'增加\', \'demand\': \'英阳联盟\'}]"}'}}]}]` > > ### ✔️ Expected Behavior > > `"arguments": "{\"preferences\": \"[{'action': '\u963b\u6b62', 'demand': '\u65b0\u4eac\u62a5'}]\"}"}} ` > > ### ❌ Actual Behavior > > `"arguments": "{\"preferences\": \"[{'action': '\\u963b\\u6b62', 'demand': '\\u65b0\\u4eac\\u62a5'}]\"}"}} ` > > Hello, have you resolved the issue with Chinese characters appearing as garbled text? Hello, I found that qwen2 has already generated Unicode encoding when calling the lowest level API, which is client.chat.completions, to generate content. When this generated content containing Unicode is passed into subsequent stages as history, it may be due to qwen2's insufficient understanding ability, resulting in garbled content in the end. Therefore, I directly decode the content generated by each "client. chat.completions" so that it does not contain Unicode, and there will be no garbled characters afterwards. You can try.
Author
Owner

@FAFUuser commented on GitHub (Sep 5, 2024):

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.6.15

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

Model

qwen-2-72B

Problems

During the process of using agents for function calls and multiple rounds of conversations, we found that the latter few rounds of conversations would produce abnormal responses. By examining the database, we found that there is an issue with ("tool_calls" ->"function" ->"arguments") when retrieving history in multiple rounds of conversations. We let the arguments be a json list with 2 attributes -- 'action' and 'demand'. The 'tool_calls' result is rightly shown, but in the second and three rounds of conversation, agent should first get the histroy results. We found that there are ''s in 'arguments':
"arguments": "{\"preferences\": \"[{'action': '\\u963b\\u6b62', 'demand': '\\u65b0\\u4eac\\u62a5'}]\"}"}}
The correct one should be "arguments": "{"preferences": "[{'action': '\u963b\u6b62', 'demand': '\u65b0\u4eac\u62a5'}]"}"}} This situation will lead to abnormal performance of the agent in the later rounds. This issue may be caused by encoding problems during the reading and writing of history in multiple rounds of dialogue. The following are the database records and the results after decoding. We can see that there are '\'s in the 'arguments', ade there is a problem with the output of the last two rounds, as it outputs' 英阳联盟' instead of '英雄联盟' ### Database records

round1

[{"role": "user", "text": "\u4e0d\u60f3\u770b\u65b0\u4eac\u62a5", "files": []}, {"role": "assistant", "text": "", "files": [], "tool_calls": [{"id": "call_8a7e093f-8938-4d7c-81ac-65e43aa8fa3b", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\u963b\u6b62', 'demand': '\u65b0\u4eac\u62a5'}]\"}"}}]}, {"role": "tool", "text": "{\"profile\": [{\"granularity\": \"TNAME\", \"type\": \"ALL\", \"content\": \"T1486538331796\", \"priority\": -1.0}], \"message\": \"\u5df2\u7ecf\u6839\u636e\u60a8\u7684\u5429\u5490\u8c03\u6574\u4e86\u63a8\u8350\u6a21\u5f0f\uff0c\u73b0\u5728\u60a8\u53ef\u4ee5\u53bb\u4e00\u63a2\u7a76\u7adf\u5566\uff01\"}", "files": [], "tool_calls": [{"id": "call_8a7e093f-8938-4d7c-81ac-65e43aa8fa3b", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\u963b\u6b62', 'demand': '\u65b0\u4eac\u62a5'}]\"}"}}]}]

round2

[{"role": "user", "text": "\u4e0d\u60f3\u770b\u65b0\u4eac\u62a5", "files": []}, {"role": "assistant", "text": "\u7528\u6237\u8868\u8fbe\u4e86\u4e0d\u60f3\u770b\u6765\u81ea\u201c\u65b0\u4eac\u62a5\u201d\u7684\u5185\u5bb9\uff0c\u8fd9\u6d89\u53ca\u5230\u8c03\u6574\u63a8\u8350\u5185\u5bb9\uff0c\u963b\u6b62\u7279\u5b9a\u6765\u6e90\u7684\u4fe1\u606f\u3002", "files": [], "tool_calls": [{"id": "a7455157-a8ea-4a7c-8d21-529de2fdab0b", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\\u963b\\u6b62', 'demand': '\\u65b0\\u4eac\\u62a5'}]\"}"}}]}, {"role": "tool", "text": "{\"profile\": [{\"granularity\": \"TNAME\", \"type\": \"ALL\", \"content\": \"T1486538331796\", \"priority\": -1.0}], \"message\": \"\u5df2\u7ecf\u6839\u636e\u60a8\u7684\u5429\u5490\u8c03\u6574\u4e86\u63a8\u8350\u6a21\u5f0f\uff0c\u73b0\u5728\u60a8\u53ef\u4ee5\u53bb\u4e00\u63a2\u7a76\u7adf\u5566\uff01\"}", "files": [], "tool_calls": [{"id": "a7455157-a8ea-4a7c-8d21-529de2fdab0b", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\\u963b\\u6b62', 'demand': '\\u65b0\\u4eac\\u62a5'}]\"}"}}]}, {"role": "assistant", "text": "\u6211\u5df2\u7ecf\u5e2e\u60a8\u8bbe\u7f6e\u597d\u4e86\uff0c\u60a8\u5c06\u4e0d\u518d\u770b\u5230\u65b0\u4eac\u62a5\u7684\u76f8\u5173\u4fe1\u606f\u3002", "files": []}, {"role": "user", "text": "\u60f3\u770b\u82f1\u96c4\u8054\u76df", "files": []}, {"role": "assistant", "text": "", "files": [], "tool_calls": [{"id": "call_3eb89cec-17f8-4cf6-beb3-f0883b6a1386", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\u589e\u52a0', 'demand': '\u82f1\u9633\u8054\u76df'}]\"}"}}]}, {"role": "tool", "text": "{\"message\": \"\u6536\u5230\u60a8\u7684\u5429\u5490\u4e86\uff0c\u53ef\u8fd9\u4e2a\u8981\u6c42\u597d\u96be\uff0c\u6682\u65f6\u505a\u4e0d\u5230\uff0c\u8bf7\u6362\u4e2a\u8bf4\u6cd5\u8bd5\u8bd5\uff01\"}", "files": [], "tool_calls": [{"id": "call_3eb89cec-17f8-4cf6-beb3-f0883b6a1386", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\u589e\u52a0', 'demand': '\u82f1\u9633\u8054\u76df'}]\"}"}}]}]

round3

[{"role": "user", "text": "\u4e0d\u60f3\u770b\u65b0\u4eac\u62a5", "files": []}, {"role": "assistant", "text": "\u7528\u6237\u8868\u8fbe\u4e86\u4e0d\u60f3\u770b\u6765\u81ea\u201c\u65b0\u4eac\u62a5\u201d\u7684\u5185\u5bb9\uff0c\u8fd9\u6d89\u53ca\u5230\u8c03\u6574\u63a8\u8350\u5185\u5bb9\uff0c\u963b\u6b62\u7279\u5b9a\u6765\u6e90\u7684\u4fe1\u606f\u3002", "files": [], "tool_calls": [{"id": "222fed6b-c2fc-416d-8e0a-60c2d38a0a67", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\\u963b\\u6b62', 'demand': '\\u65b0\\u4eac\\u62a5'}]\"}"}}]}, {"role": "tool", "text": "{\"profile\": [{\"granularity\": \"TNAME\", \"type\": \"ALL\", \"content\": \"T1486538331796\", \"priority\": -1.0}], \"message\": \"\u5df2\u7ecf\u6839\u636e\u60a8\u7684\u5429\u5490\u8c03\u6574\u4e86\u63a8\u8350\u6a21\u5f0f\uff0c\u73b0\u5728\u60a8\u53ef\u4ee5\u53bb\u4e00\u63a2\u7a76\u7adf\u5566\uff01\"}", "files": [], "tool_calls": [{"id": "222fed6b-c2fc-416d-8e0a-60c2d38a0a67", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\\u963b\\u6b62', 'demand': '\\u65b0\\u4eac\\u62a5'}]\"}"}}]}, {"role": "assistant", "text": "\u6211\u5df2\u7ecf\u5e2e\u60a8\u8bbe\u7f6e\u597d\u4e86\uff0c\u60a8\u5c06\u4e0d\u518d\u770b\u5230\u65b0\u4eac\u62a5\u7684\u76f8\u5173\u4fe1\u606f\u3002", "files": []}, {"role": "user", "text": "\u60f3\u770b\u82f1\u96c4\u8054\u76df", "files": []}, {"role": "assistant", "text": "I can use ai_agent_profile.", "files": [], "tool_calls": [{"id": "8613338c-5e89-4e11-b675-762011a74f7e", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\\u589e\\u52a0', 'demand': '\\u82f1\\u9633\\u8054\\u76df'}]\"}"}}]}, {"role": "tool", "text": "{\"message\": \"\u6536\u5230\u60a8\u7684\u5429\u5490\u4e86\uff0c\u53ef\u8fd9\u4e2a\u8981\u6c42\u597d\u96be\uff0c\u6682\u65f6\u505a\u4e0d\u5230\uff0c\u8bf7\u6362\u4e2a\u8bf4\u6cd5\u8bd5\u8bd5\uff01\"}", "files": [], "tool_calls": [{"id": "8613338c-5e89-4e11-b675-762011a74f7e", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\\u589e\\u52a0', 'demand': '\\u82f1\\u9633\\u8054\\u76df'}]\"}"}}]}, {"role": "assistant", "text": "\u6682\u65f6\u65e0\u6cd5\u8bc6\u522b\u201c\u82f1\u9633\u8054\u76df\u201d\uff0c\u53ef\u80fd\u662f\u60a8\u8f93\u5165\u6709\u8bef\uff0c\u6216\u8005\u7684\u80fd\u529b\u6709\u9650\uff0c\u60a8\u53ef\u4ee5\u5c1d\u8bd5\u6362\u4e2a\u8bf4\u6cd5\u3002\u6bd4\u5982\uff0c\u5982\u679c\u60a8\u60f3\u770b\u82f1\u96c4\u8054\u76df\u7684\u65b0\u95fb\u6216\u8005\u8d5b\u4e8b\u4fe1\u606f\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u8f93\u5165\u201c\u82f1\u96c4\u8054\u76df\u65b0\u95fb\u201d\u6216\u8005\u201c\u82f1\u96c4\u8054\u76df\u8d5b\u4e8b\u201d\u3002", "files": []}, {"role": "user", "text": "\u591a\u63a8\u82f1\u96c4\u8054\u76df", "files": []}, {"role": "assistant", "text": "", "files": [], "tool_calls": [{"id": "call_f640f05c-eb9f-43f0-86ed-1397fabf2c37", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\u589e\u52a0', 'demand': '\u82f1\u9633\u8054\u76df'}]\"}"}}]}, {"role": "tool", "text": "{\"message\": \"\u6536\u5230\u60a8\u7684\u5429\u5490\u4e86\uff0c\u53ef\u8fd9\u4e2a\u8981\u6c42\u597d\u96be\uff0c\u6682\u65f6\u505a\u4e0d\u5230\uff0c\u8bf7\u6362\u4e2a\u8bf4\u6cd5\u8bd5\u8bd5\uff01\"}", "files": [], "tool_calls": [{"id": "call_f640f05c-eb9f-43f0-86ed-1397fabf2c37", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\u589e\u52a0', 'demand': '\u82f1\u9633\u8054\u76df'}]\"}"}}]}]

Database records after prasing

[{'role': 'user', 'text': '不想看新京报', 'files': []}, {'role': 'assistant', 'text': '', 'files': [], 'tool_calls': [{'id': 'call_8a7e093f-8938-4d7c-81ac-65e43aa8fa3b', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'阻止\', \'demand\': \'新京报\'}]"}'}}]}, {'role': 'tool', 'text': '{"profile": [{"granularity": "TNAME", "type": "ALL", "content": "T1486538331796", "priority": -1.0}], "message": "已经根据您 的吩咐调整了推荐模式,现在您可以去一探究竟啦!"}', 'files': [], 'tool_calls': [{'id': 'call_8a7e093f-8938-4d7c-81ac-65e43aa8fa3b', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'阻止\', \'demand\': \'新京报\'}]"}'}}]}]
[{'role': 'user', 'text': '不想看新京报', 'files': []}, {'role': 'assistant', 'text': '用户表达了不想看来自“新京报”的内容,这涉及到调整推荐内容,阻止特定来源的信息。', 'files': [], 'tool_calls': [{'id': 'a7455157-a8ea-4a7c-8d21-529de2fdab0b', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'\\u963b\\u6b62\', \'demand\': \'\\u65b0\\u4eac\\u62a5\'}]"}'}}]}, {'role': 'tool', 'text': '{"profile": [{"granularity": "TNAME", "type": "ALL", "content": "T1486538331796", "priority": -1.0}], "message": "已经根据您的吩咐调整了推荐模式,现在您可以去一探究竟啦!"}', 'files': [], 'tool_calls': [{'id': 'a7455157-a8ea-4a7c-8d21-529de2fdab0b', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'\\u963b\\u6b62\', \'demand\':\'\\u65b0\\u4eac\\u62a5\'}]"}'}}]}, {'role': 'assistant', 'text': '我已经帮您设置好了,您将不再看到新京报的相关信息。', 'files': []}, {'role': 'user', 'text': '想看英雄联盟', 'files': []}, {'role': 'assistant', 'text': '', 'files': [], 'tool_calls': [{'id': 'call_3eb89cec-17f8-4cf6-beb3-f0883b6a1386', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'增加\', \'demand\': \'英阳联盟\'}]"}'}}]}, {'role': 'tool', 'text': '{"message": "收到您的吩咐了,可这个要求好难,暂时做不到,请换个说法试试!"}', 'files': [], 'tool_calls': [{'id': 'call_3eb89cec-17f8-4cf6-beb3-f0883b6a1386', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'增加\', \'demand\': \'英阳联盟\'}]"}'}}]}]
[{'role': 'user', 'text': '不想看新京报', 'files': []}, {'role': 'assistant', 'text': '用户表达了不想看来自“新京报”的内容,这涉及到调整推荐内容,阻止特定来源的信息。', 'files': [], 'tool_calls': [{'id': '222fed6b-c2fc-416d-8e0a-60c2d38a0a67', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'\\u963b\\u6b62\', \'demand\': \'\\u65b0\\u4eac\\u62a5\'}]"}'}}]}, {'role': 'tool', 'text': '{"profile": [{"granularity": "TNAME", "type": "ALL", "content": "T1486538331796", "priority": -1.0}], "message": "已经根据您的吩咐调整了推荐模式,现在您可以去一探究竟啦!"}', 'files': [], 'tool_calls': [{'id': '222fed6b-c2fc-416d-8e0a-60c2d38a0a67', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'\\u963b\\u6b62\', \'demand\': \'\\u65b0\\u4eac\\u62a5\'}]"}'}}]}, {'role': 'assistant', 'text': '我已经帮您设置好了,您将不再看到新京报的相关信息。', 'files': []}, {'role': 'user', 'text': '想看英雄联盟', 'files': []}, {'role': 'assistant', 'text': 'I can use ai_agent_profile.', 'files': [], 'tool_calls': [{'id': '8613338c-5e89-4e11-b675-762011a74f7e', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'\\u589e\\u52a0\', \'demand\': \'\\u82f1\\u9633\\u8054\\u76df\'}]"}'}}]}, {'role': 'tool', 'text': '{"message": "收到您的吩咐了,可这个要求好难,暂时做不到,请换个说法试试!"}', 'files': [], 'tool_calls': [{'id': '8613338c-5e89-4e11-b675-762011a74f7e', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'\\u589e\\u52a0\', \'demand\': \'\\u82f1\\u9633\\u8054\\u76df\'*}]"}'}}]}, {'role': 'assistant', 'text': '暂时无法识别“英阳联盟”,可能是您输入有误。', 'files': []}, {'role': 'user', 'text': '多推英雄联盟', 'files': []}, {'role': 'assistant', 'text': '', 'files': [], 'tool_calls': [{'id': 'call_f640f05c-eb9f-43f0-86ed-1397fabf2c37', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'增加\', \'demand\': \'英阳联盟\'}]"}'}}]}, {'role': 'tool', 'text': '{"message": "收到您的吩咐了,可这个要求好难,暂时做不到,请换个说法试试!"}', 'files': [], 'tool_calls': [{'id': 'call_f640f05c-eb9f-43f0-86ed-1397fabf2c37', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'增加\', \'demand\': \'英阳联盟\'}]"}'}}]}]

✔️ Expected Behavior

"arguments": "{\"preferences\": \"[{'action': '\u963b\u6b62', 'demand': '\u65b0\u4eac\u62a5'}]\"}"}}

Actual Behavior

"arguments": "{\"preferences\": \"[{'action': '\\u963b\\u6b62', 'demand': '\\u65b0\\u4eac\\u62a5'}]\"}"}}
Hello, have you resolved the issue with Chinese characters appearing as garbled text?

Hello, I found that qwen2 has already generated Unicode encoding when calling the lowest level API, which is client.chat.completions, to generate content. When this generated content containing Unicode is passed into subsequent stages as history, it may be due to qwen2's insufficient understanding ability, resulting in garbled content in the end. Therefore, I directly decode the content generated by each "client. chat.completions" so that it does not contain Unicode, and there will be no garbled characters afterwards. You can try.

Indeed, when large models generate content, errors may occur. For example, the parameter I entered was “林德气体” but the output it gave was “\u672c\u5706\u6c14\u4f53”, which corresponds to the Chinese “本圆气体”.And there are many more such cases.

Do you have a respective solution strategy for the problem mentioned above?

@FAFUuser commented on GitHub (Sep 5, 2024): > > > ### Self Checks > > > > > > * [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). > > > * [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. > > > * [x] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). > > > * [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) > > > * [x] Please do not modify this template :) and fill in all the required fields. > > > > > > ### Dify version > > > 0.6.15 > > > ### Cloud or Self Hosted > > > Self Hosted (Docker) > > > ### Steps to reproduce > > > ### Model > > > qwen-2-72B > > > ### Problems > > > During the process of using agents for function calls and multiple rounds of conversations, we found that the latter few rounds of conversations would produce abnormal responses. By examining the database, we found that there is an issue with ("tool_calls" ->"function" ->"arguments") when retrieving history in multiple rounds of conversations. We let the arguments be a json list with 2 attributes -- 'action' and 'demand'. The 'tool_calls' result is rightly shown, but in the second and three rounds of conversation, agent should first get the histroy results. We found that there are ''s in 'arguments': > > > `"arguments": "{\"preferences\": \"[{'action': '\\u963b\\u6b62', 'demand': '\\u65b0\\u4eac\\u62a5'}]\"}"}} ` > > > The correct one should be `"arguments": "{"preferences": "[{'action': '\u963b\u6b62', 'demand': '\u65b0\u4eac\u62a5'}]"}"}} This situation will lead to abnormal performance of the agent in the later rounds. This issue may be caused by encoding problems during the reading and writing of history in multiple rounds of dialogue. The following are the database records and the results after decoding. We can see that there are '\'s in the 'arguments', ade there is a problem with the output of the last two rounds, as it outputs' 英阳联盟' instead of '英雄联盟' `### Database records > > > #### round1 > > > `[{"role": "user", "text": "\u4e0d\u60f3\u770b\u65b0\u4eac\u62a5", "files": []}, {"role": "assistant", "text": "", "files": [], "tool_calls": [{"id": "call_8a7e093f-8938-4d7c-81ac-65e43aa8fa3b", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\u963b\u6b62', 'demand': '\u65b0\u4eac\u62a5'}]\"}"}}]}, {"role": "tool", "text": "{\"profile\": [{\"granularity\": \"TNAME\", \"type\": \"ALL\", \"content\": \"T1486538331796\", \"priority\": -1.0}], \"message\": \"\u5df2\u7ecf\u6839\u636e\u60a8\u7684\u5429\u5490\u8c03\u6574\u4e86\u63a8\u8350\u6a21\u5f0f\uff0c\u73b0\u5728\u60a8\u53ef\u4ee5\u53bb\u4e00\u63a2\u7a76\u7adf\u5566\uff01\"}", "files": [], "tool_calls": [{"id": "call_8a7e093f-8938-4d7c-81ac-65e43aa8fa3b", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\u963b\u6b62', 'demand': '\u65b0\u4eac\u62a5'}]\"}"}}]}]` > > > #### round2 > > > `[{"role": "user", "text": "\u4e0d\u60f3\u770b\u65b0\u4eac\u62a5", "files": []}, {"role": "assistant", "text": "\u7528\u6237\u8868\u8fbe\u4e86\u4e0d\u60f3\u770b\u6765\u81ea\u201c\u65b0\u4eac\u62a5\u201d\u7684\u5185\u5bb9\uff0c\u8fd9\u6d89\u53ca\u5230\u8c03\u6574\u63a8\u8350\u5185\u5bb9\uff0c\u963b\u6b62\u7279\u5b9a\u6765\u6e90\u7684\u4fe1\u606f\u3002", "files": [], "tool_calls": [{"id": "a7455157-a8ea-4a7c-8d21-529de2fdab0b", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\\u963b\\u6b62', 'demand': '\\u65b0\\u4eac\\u62a5'}]\"}"}}]}, {"role": "tool", "text": "{\"profile\": [{\"granularity\": \"TNAME\", \"type\": \"ALL\", \"content\": \"T1486538331796\", \"priority\": -1.0}], \"message\": \"\u5df2\u7ecf\u6839\u636e\u60a8\u7684\u5429\u5490\u8c03\u6574\u4e86\u63a8\u8350\u6a21\u5f0f\uff0c\u73b0\u5728\u60a8\u53ef\u4ee5\u53bb\u4e00\u63a2\u7a76\u7adf\u5566\uff01\"}", "files": [], "tool_calls": [{"id": "a7455157-a8ea-4a7c-8d21-529de2fdab0b", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\\u963b\\u6b62', 'demand': '\\u65b0\\u4eac\\u62a5'}]\"}"}}]}, {"role": "assistant", "text": "\u6211\u5df2\u7ecf\u5e2e\u60a8\u8bbe\u7f6e\u597d\u4e86\uff0c\u60a8\u5c06\u4e0d\u518d\u770b\u5230\u65b0\u4eac\u62a5\u7684\u76f8\u5173\u4fe1\u606f\u3002", "files": []}, {"role": "user", "text": "\u60f3\u770b\u82f1\u96c4\u8054\u76df", "files": []}, {"role": "assistant", "text": "", "files": [], "tool_calls": [{"id": "call_3eb89cec-17f8-4cf6-beb3-f0883b6a1386", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\u589e\u52a0', 'demand': '\u82f1\u9633\u8054\u76df'}]\"}"}}]}, {"role": "tool", "text": "{\"message\": \"\u6536\u5230\u60a8\u7684\u5429\u5490\u4e86\uff0c\u53ef\u8fd9\u4e2a\u8981\u6c42\u597d\u96be\uff0c\u6682\u65f6\u505a\u4e0d\u5230\uff0c\u8bf7\u6362\u4e2a\u8bf4\u6cd5\u8bd5\u8bd5\uff01\"}", "files": [], "tool_calls": [{"id": "call_3eb89cec-17f8-4cf6-beb3-f0883b6a1386", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\u589e\u52a0', 'demand': '\u82f1\u9633\u8054\u76df'}]\"}"}}]}]` > > > #### round3 > > > `[{"role": "user", "text": "\u4e0d\u60f3\u770b\u65b0\u4eac\u62a5", "files": []}, {"role": "assistant", "text": "\u7528\u6237\u8868\u8fbe\u4e86\u4e0d\u60f3\u770b\u6765\u81ea\u201c\u65b0\u4eac\u62a5\u201d\u7684\u5185\u5bb9\uff0c\u8fd9\u6d89\u53ca\u5230\u8c03\u6574\u63a8\u8350\u5185\u5bb9\uff0c\u963b\u6b62\u7279\u5b9a\u6765\u6e90\u7684\u4fe1\u606f\u3002", "files": [], "tool_calls": [{"id": "222fed6b-c2fc-416d-8e0a-60c2d38a0a67", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\\u963b\\u6b62', 'demand': '\\u65b0\\u4eac\\u62a5'}]\"}"}}]}, {"role": "tool", "text": "{\"profile\": [{\"granularity\": \"TNAME\", \"type\": \"ALL\", \"content\": \"T1486538331796\", \"priority\": -1.0}], \"message\": \"\u5df2\u7ecf\u6839\u636e\u60a8\u7684\u5429\u5490\u8c03\u6574\u4e86\u63a8\u8350\u6a21\u5f0f\uff0c\u73b0\u5728\u60a8\u53ef\u4ee5\u53bb\u4e00\u63a2\u7a76\u7adf\u5566\uff01\"}", "files": [], "tool_calls": [{"id": "222fed6b-c2fc-416d-8e0a-60c2d38a0a67", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\\u963b\\u6b62', 'demand': '\\u65b0\\u4eac\\u62a5'}]\"}"}}]}, {"role": "assistant", "text": "\u6211\u5df2\u7ecf\u5e2e\u60a8\u8bbe\u7f6e\u597d\u4e86\uff0c\u60a8\u5c06\u4e0d\u518d\u770b\u5230\u65b0\u4eac\u62a5\u7684\u76f8\u5173\u4fe1\u606f\u3002", "files": []}, {"role": "user", "text": "\u60f3\u770b\u82f1\u96c4\u8054\u76df", "files": []}, {"role": "assistant", "text": "I can use ai_agent_profile.", "files": [], "tool_calls": [{"id": "8613338c-5e89-4e11-b675-762011a74f7e", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\\u589e\\u52a0', 'demand': '\\u82f1\\u9633\\u8054\\u76df'}]\"}"}}]}, {"role": "tool", "text": "{\"message\": \"\u6536\u5230\u60a8\u7684\u5429\u5490\u4e86\uff0c\u53ef\u8fd9\u4e2a\u8981\u6c42\u597d\u96be\uff0c\u6682\u65f6\u505a\u4e0d\u5230\uff0c\u8bf7\u6362\u4e2a\u8bf4\u6cd5\u8bd5\u8bd5\uff01\"}", "files": [], "tool_calls": [{"id": "8613338c-5e89-4e11-b675-762011a74f7e", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\\u589e\\u52a0', 'demand': '\\u82f1\\u9633\\u8054\\u76df'}]\"}"}}]}, {"role": "assistant", "text": "\u6682\u65f6\u65e0\u6cd5\u8bc6\u522b\u201c\u82f1\u9633\u8054\u76df\u201d\uff0c\u53ef\u80fd\u662f\u60a8\u8f93\u5165\u6709\u8bef\uff0c\u6216\u8005\u7684\u80fd\u529b\u6709\u9650\uff0c\u60a8\u53ef\u4ee5\u5c1d\u8bd5\u6362\u4e2a\u8bf4\u6cd5\u3002\u6bd4\u5982\uff0c\u5982\u679c\u60a8\u60f3\u770b\u82f1\u96c4\u8054\u76df\u7684\u65b0\u95fb\u6216\u8005\u8d5b\u4e8b\u4fe1\u606f\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u8f93\u5165\u201c\u82f1\u96c4\u8054\u76df\u65b0\u95fb\u201d\u6216\u8005\u201c\u82f1\u96c4\u8054\u76df\u8d5b\u4e8b\u201d\u3002", "files": []}, {"role": "user", "text": "\u591a\u63a8\u82f1\u96c4\u8054\u76df", "files": []}, {"role": "assistant", "text": "", "files": [], "tool_calls": [{"id": "call_f640f05c-eb9f-43f0-86ed-1397fabf2c37", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\u589e\u52a0', 'demand': '\u82f1\u9633\u8054\u76df'}]\"}"}}]}, {"role": "tool", "text": "{\"message\": \"\u6536\u5230\u60a8\u7684\u5429\u5490\u4e86\uff0c\u53ef\u8fd9\u4e2a\u8981\u6c42\u597d\u96be\uff0c\u6682\u65f6\u505a\u4e0d\u5230\uff0c\u8bf7\u6362\u4e2a\u8bf4\u6cd5\u8bd5\u8bd5\uff01\"}", "files": [], "tool_calls": [{"id": "call_f640f05c-eb9f-43f0-86ed-1397fabf2c37", "type": "function", "function": {"name": "ai_agent_profile", "arguments": "{\"preferences\": \"[{'action': '\u589e\u52a0', 'demand': '\u82f1\u9633\u8054\u76df'}]\"}"}}]}]` > > > ### Database records after prasing > > > `[{'role': 'user', 'text': '不想看新京报', 'files': []}, {'role': 'assistant', 'text': '', 'files': [], 'tool_calls': [{'id': 'call_8a7e093f-8938-4d7c-81ac-65e43aa8fa3b', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'阻止\', \'demand\': \'新京报\'}]"}'}}]}, {'role': 'tool', 'text': '{"profile": [{"granularity": "TNAME", "type": "ALL", "content": "T1486538331796", "priority": -1.0}], "message": "已经根据您 的吩咐调整了推荐模式,现在您可以去一探究竟啦!"}', 'files': [], 'tool_calls': [{'id': 'call_8a7e093f-8938-4d7c-81ac-65e43aa8fa3b', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'阻止\', \'demand\': \'新京报\'}]"}'}}]}]` > > > `[{'role': 'user', 'text': '不想看新京报', 'files': []}, {'role': 'assistant', 'text': '用户表达了不想看来自“新京报”的内容,这涉及到调整推荐内容,阻止特定来源的信息。', 'files': [], 'tool_calls': [{'id': 'a7455157-a8ea-4a7c-8d21-529de2fdab0b', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'\\u963b\\u6b62\', \'demand\': \'\\u65b0\\u4eac\\u62a5\'}]"}'}}]}, {'role': 'tool', 'text': '{"profile": [{"granularity": "TNAME", "type": "ALL", "content": "T1486538331796", "priority": -1.0}], "message": "已经根据您的吩咐调整了推荐模式,现在您可以去一探究竟啦!"}', 'files': [], 'tool_calls': [{'id': 'a7455157-a8ea-4a7c-8d21-529de2fdab0b', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'\\u963b\\u6b62\', \'demand\':\'\\u65b0\\u4eac\\u62a5\'}]"}'}}]}, {'role': 'assistant', 'text': '我已经帮您设置好了,您将不再看到新京报的相关信息。', 'files': []}, {'role': 'user', 'text': '想看英雄联盟', 'files': []}, {'role': 'assistant', 'text': '', 'files': [], 'tool_calls': [{'id': 'call_3eb89cec-17f8-4cf6-beb3-f0883b6a1386', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'增加\', \'demand\': \'英阳联盟\'}]"}'}}]}, {'role': 'tool', 'text': '{"message": "收到您的吩咐了,可这个要求好难,暂时做不到,请换个说法试试!"}', 'files': [], 'tool_calls': [{'id': 'call_3eb89cec-17f8-4cf6-beb3-f0883b6a1386', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'增加\', \'demand\': \'英阳联盟\'}]"}'}}]}]` > > > `[{'role': 'user', 'text': '不想看新京报', 'files': []}, {'role': 'assistant', 'text': '用户表达了不想看来自“新京报”的内容,这涉及到调整推荐内容,阻止特定来源的信息。', 'files': [], 'tool_calls': [{'id': '222fed6b-c2fc-416d-8e0a-60c2d38a0a67', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'\\u963b\\u6b62\', \'demand\': \'\\u65b0\\u4eac\\u62a5\'}]"}'}}]}, {'role': 'tool', 'text': '{"profile": [{"granularity": "TNAME", "type": "ALL", "content": "T1486538331796", "priority": -1.0}], "message": "已经根据您的吩咐调整了推荐模式,现在您可以去一探究竟啦!"}', 'files': [], 'tool_calls': [{'id': '222fed6b-c2fc-416d-8e0a-60c2d38a0a67', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'\\u963b\\u6b62\', \'demand\': \'\\u65b0\\u4eac\\u62a5\'}]"}'}}]}, {'role': 'assistant', 'text': '我已经帮您设置好了,您将不再看到新京报的相关信息。', 'files': []}, {'role': 'user', 'text': '想看英雄联盟', 'files': []}, {'role': 'assistant', 'text': 'I can use ai_agent_profile.', 'files': [], 'tool_calls': [{'id': '8613338c-5e89-4e11-b675-762011a74f7e', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'\\u589e\\u52a0\', \'demand\': \'\\u82f1\\u9633\\u8054\\u76df\'}]"}'}}]}, {'role': 'tool', 'text': '{"message": "收到您的吩咐了,可这个要求好难,暂时做不到,请换个说法试试!"}', 'files': [], 'tool_calls': [{'id': '8613338c-5e89-4e11-b675-762011a74f7e', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'\\u589e\\u52a0\', \'demand\': \'\\u82f1\\u9633\\u8054\\u76df\'*}]"}'}}]}, {'role': 'assistant', 'text': '暂时无法识别“英阳联盟”,可能是您输入有误。', 'files': []}, {'role': 'user', 'text': '多推英雄联盟', 'files': []}, {'role': 'assistant', 'text': '', 'files': [], 'tool_calls': [{'id': 'call_f640f05c-eb9f-43f0-86ed-1397fabf2c37', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'增加\', \'demand\': \'英阳联盟\'}]"}'}}]}, {'role': 'tool', 'text': '{"message": "收到您的吩咐了,可这个要求好难,暂时做不到,请换个说法试试!"}', 'files': [], 'tool_calls': [{'id': 'call_f640f05c-eb9f-43f0-86ed-1397fabf2c37', 'type': 'function', 'function': {'name': 'ai_agent_profile', 'arguments': '{"preferences": "[{\'action\': \'增加\', \'demand\': \'英阳联盟\'}]"}'}}]}]` > > > ### ✔️ Expected Behavior > > > `"arguments": "{\"preferences\": \"[{'action': '\u963b\u6b62', 'demand': '\u65b0\u4eac\u62a5'}]\"}"}} ` > > > ### ❌ Actual Behavior > > > `"arguments": "{\"preferences\": \"[{'action': '\\u963b\\u6b62', 'demand': '\\u65b0\\u4eac\\u62a5'}]\"}"}} ` > > > Hello, have you resolved the issue with Chinese characters appearing as garbled text? > > Hello, I found that qwen2 has already generated Unicode encoding when calling the lowest level API, which is client.chat.completions, to generate content. When this generated content containing Unicode is passed into subsequent stages as history, it may be due to qwen2's insufficient understanding ability, resulting in garbled content in the end. Therefore, I directly decode the content generated by each "client. chat.completions" so that it does not contain Unicode, and there will be no garbled characters afterwards. You can try. Indeed, when large models generate content, errors may occur. For example, the parameter I entered was “林德气体” but the output it gave was “\u672c\u5706\u6c14\u4f53”, which corresponds to the Chinese “本圆气体”.And there are many more such cases. Do you have a respective solution strategy for the problem mentioned above?
Author
Owner

@lidajiededa commented on GitHub (Sep 5, 2024):

@FAFUuser In my usage process, this situation usually occurs in multiple rounds of conversations, and there is usually no problem with replying to the first question. But if the answer to the first question includes Unicode, and it is passed into subsequent conversations as history, an error will occur. So my solution is not to let answers containing Unicode be passed into subsequent conversations. Specifically, first determine whether the tool has been called. If it has been called, immediately after generating the answer, decode the Unicode in the answer into Chinese.

@lidajiededa commented on GitHub (Sep 5, 2024): @FAFUuser In my usage process, this situation usually occurs in multiple rounds of conversations, and there is usually no problem with replying to the first question. But if the answer to the first question includes Unicode, and it is passed into subsequent conversations as history, an error will occur. So my solution is not to let answers containing Unicode be passed into subsequent conversations. Specifically, first determine whether the tool has been called. If it has been called, immediately after generating the answer, decode the Unicode in the answer into Chinese.
Author
Owner

@FAFUuser commented on GitHub (Sep 5, 2024):

@lidajiededa Actually, my issue is different although it might seem similar. I encounter garbled text even in the first round of conversation. Thank you very much for the discussion; I've learned a lot.

@FAFUuser commented on GitHub (Sep 5, 2024): @lidajiededa Actually, my issue is different although it might seem similar. I encounter garbled text even in the first round of conversation. Thank you very much for the discussion; I've learned a lot.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#4869