Yuxi-Know icon indicating copy to clipboard operation
Yuxi-Know copied to clipboard

Error: 多对话多开的时候,智能体调用工具的时候出现中断不继续执行的问题!

Open wxw-123 opened this issue 5 months ago • 22 comments

09-17 01:01:01 INFO src.agents.common.base:66: content='' additional_kwargs={'tool_calls': [{'index': 0, 'id': None, 'function': {'arguments': 'SELECT', 'name': None}, 'type': None}]} response_metadata={} id='run--2f68bf26-7f58-44d3-8e33-d99029e77753' invalid_tool_calls=[{'name': None, 'args': 'SELECT', 'id': None, 'error': None, 'type': 'invalid_tool_call'}] usage_metadata={'input_tokens': 6425, 'output_tokens': 41, 'total_tokens': 6466, 'input_token_details': {}, 'output_token_details': {}} tool_call_chunks=[{'name': None, 'args': 'SELECT', 'id': None, 'index': 0, 'type': 'tool_call_chunk'}]

09-17 01:01:01 INFO src.agents.common.base:66: content='' additional_kwargs={'tool_calls': [{'index': 0, 'id': None, 'function': {'arguments': ' *', 'name': None}, 'type': None}]} response_metadata={} id='run--2f68bf26-7f58-44d3-8e33-d99029e77753' invalid_tool_calls=[{'name': None, 'args': ' *', 'id': None, 'error': None, 'type': 'invalid_tool_call'}] usage_metadata={'input_tokens': 6425, 'output_tokens': 42, 'total_tokens': 6467, 'input_token_details': {}, 'output_token_details': {}} tool_call_chunks=[{'name': None, 'args': ' *', 'id': None, 'index': 0, 'type': 'tool_call_chunk'}]

09-17 01:01:02 INFO src.agents.common.base:66: content='' additional_kwargs={'tool_calls': [{'index': 0, 'id': None, 'function': {'arguments': ' FROM', 'name': None}, 'type': None}]} response_metadata={} id='run--2f68bf26-7f58-44d3-8e33-d99029e77753' invalid_tool_calls=[{'name': None, 'args': ' FROM', 'id': None, 'error': None, 'type': 'invalid_tool_call'}] usage_metadata={'input_tokens': 6425, 'output_tokens': 43, 'total_tokens': 6468, 'input_token_details': {}, 'output_token_details': {}} tool_call_chunks=[{'name': None, 'args': ' FROM', 'id': None, 'index': 0, 'type': 'tool_call_chunk'}]

09-17 01:01:02 INFO src.agents.common.base:66: content='' additional_kwargs={'tool_calls': [{'index': 0, 'id': None, 'function': {'arguments': ' weather', 'name': None}, 'type': None}]} response_metadata={} id='run--2f68bf26-7f58-44d3-8e33-d99029e77753' invalid_tool_calls=[{'name': None, 'args': ' weather', 'id': None, 'error': None, 'type': 'invalid_tool_call'}] usage_metadata={'input_tokens': 6425, 'output_tokens': 44, 'total_tokens': 6469, 'input_token_details': {}, 'output_token_details': {}} tool_call_chunks=[{'name': None, 'args': ' weather', 'id': None, 'index': 0, 'type': 'tool_call_chunk'}]

09-17 01:01:02 INFO src.agents.common.base:66: content='' additional_kwargs={'tool_calls': [{'index': 0, 'id': None, 'function': {'arguments': '_info', 'name': None}, 'type': None}]} response_metadata={} id='run--2f68bf26-7f58-44d3-8e33-d99029e77753' invalid_tool_calls=[{'name': None, 'args': '_info', 'id': None, 'error': None, 'type': 'invalid_tool_call'}] usage_metadata={'input_tokens': 6425, 'output_tokens': 45, 'total_tokens': 6470, 'input_token_details': {}, 'output_token_details': {}} tool_call_chunks=[{'name': None, 'args': '_info', 'id': None, 'index': 0, 'type': 'tool_call_chunk'}]

09-17 01:01:02 INFO src.agents.common.base:66: content='' additional_kwargs={'tool_calls': [{'index': 0, 'id': None, 'function': {'arguments': ' LIM', 'name': None}, 'type': None}]} response_metadata={} id='run--2f68bf26-7f58-44d3-8e33-d99029e77753' invalid_tool_calls=[{'name': None, 'args': ' LIM', 'id': None, 'error': None, 'type': 'invalid_tool_call'}] usage_metadata={'input_tokens': 6425, 'output_tokens': 46, 'total_tokens': 6471, 'input_token_details': {}, 'output_token_details': {}} tool_call_chunks=[{'name': None, 'args': ' LIM', 'id': None, 'index': 0, 'type': 'tool_call_chunk'}]

09-17 01:01:02 INFO src.agents.common.base:66: content='' additional_kwargs={'tool_calls': [{'index': 0, 'id': None, 'function': {'arguments': 'IT', 'name': None}, 'type': None}]} response_metadata={} id='run--2f68bf26-7f58-44d3-8e33-d99029e77753' invalid_tool_calls=[{'name': None, 'args': 'IT', 'id': None, 'error': None, 'type': 'invalid_tool_call'}] usage_metadata={'input_tokens': 6425, 'output_tokens': 47, 'total_tokens': 6472, 'input_token_details': {}, 'output_token_details': {}} tool_call_chunks=[{'name': None, 'args': 'IT', 'id': None, 'index': 0, 'type': 'tool_call_chunk'}]

09-17 01:01:02 INFO src.agents.common.base:66: content='' additional_kwargs={'tool_calls': [{'index': 0, 'id': None, 'function': {'arguments': ' ', 'name': None}, 'type': None}]} response_metadata={} id='run--2f68bf26-7f58-44d3-8e33-d99029e77753' invalid_tool_calls=[{'name': None, 'args': ' ', 'id': None, 'error': None, 'type': 'invalid_tool_call'}] usage_metadata={'input_tokens': 6425, 'output_tokens': 48, 'total_tokens': 6473, 'input_token_details': {}, 'output_token_details': {}} tool_call_chunks=[{'name': None, 'args': ' ', 'id': None, 'index': 0, 'type': 'tool_call_chunk'}]

09-17 01:01:02 INFO src.agents.common.base:66: content='' additional_kwargs={'tool_calls': [{'index': 0, 'id': None, 'function': {'arguments': '5', 'name': None}, 'type': None}]} response_metadata={} id='run--2f68bf26-7f58-44d3-8e33-d99029e77753' invalid_tool_calls=[{'name': None, 'args': '5', 'id': None, 'error': None, 'type': 'invalid_tool_call'}] usage_metadata={'input_tokens': 6425, 'output_tokens': 49, 'total_tokens': 6474, 'input_token_details': {}, 'output_token_details': {}} tool_call_chunks=[{'name': None, 'args': '5', 'id': None, 'index': 0, 'type': 'tool_call_chunk'}]

09-17 01:01:02 INFO src.agents.common.base:66: content='' additional_kwargs={'tool_calls': [{'index': 0, 'id': None, 'function': {'arguments': '\', 'name': None}, 'type': None}]} response_metadata={} id='run--2f68bf26-7f58-44d3-8e33-d99029e77753' invalid_tool_calls=[{'name': None, 'args': '\', 'id': None, 'error': None, 'type': 'invalid_tool_call'}] usage_metadata={'input_tokens': 6425, 'output_tokens': 50, 'total_tokens': 6475, 'input_token_details': {}, 'output_token_details': {}} tool_call_chunks=[{'name': None, 'args': '\', 'id': None, 'index': 0, 'type': 'tool_call_chunk'}]

09-17 01:01:02 INFO src.agents.common.base:66: content='' additional_kwargs={'tool_calls': [{'index': 0, 'id': None, 'function': {'arguments': '"', 'name': None}, 'type': None}]} response_metadata={} id='run--2f68bf26-7f58-44d3-8e33-d99029e77753' invalid_tool_calls=[{'name': None, 'args': '"', 'id': None, 'error': None, 'type': 'invalid_tool_call'}] usage_metadata={'input_tokens': 6425, 'output_tokens': 51, 'total_tokens': 6476, 'input_token_details': {}, 'output_token_details': {}} tool_call_chunks=[{'name': None, 'args': '"', 'id': None, 'index': 0, 'type': 'tool_call_chunk'}]

09-17 01:01:03 INFO src.agents.common.base:66: content='' additional_kwargs={'tool_calls': [{'index': 0, 'id': None, 'function': {'arguments': '}', 'name': None}, 'type': None}]} response_metadata={} id='run--2f68bf26-7f58-44d3-8e33-d99029e77753' invalid_tool_calls=[{'name': None, 'args': '}', 'id': None, 'error': None, 'type': 'invalid_tool_call'}] usage_metadata={'input_tokens': 6425, 'output_tokens': 52, 'total_tokens': 6477, 'input_token_details': {}, 'output_token_details': {}} tool_call_chunks=[{'name': None, 'args': '}', 'id': None, 'index': 0, 'type': 'tool_call_chunk'}]

09-17 01:01:03 INFO src.agents.common.base:66: content='' additional_kwargs={'tool_calls': [{'index': 0, 'id': None, 'function': {'arguments': '""', 'name': None}, 'type': None}]} response_metadata={} id='run--2f68bf26-7f58-44d3-8e33-d99029e77753' invalid_tool_calls=[{'name': None, 'args': '""', 'id': None, 'error': None, 'type': 'invalid_tool_call'}] usage_metadata={'input_tokens': 6425, 'output_tokens': 53, 'total_tokens': 6478, 'input_token_details': {}, 'output_token_details': {}} tool_call_chunks=[{'name': None, 'args': '""', 'id': None, 'index': 0, 'type': 'tool_call_chunk'}]

09-17 01:01:03 INFO src.agents.common.base:66: content='' additional_kwargs={} response_metadata={'finish_reason': 'tool_calls', 'model_name': 'deepseek-ai/DeepSeek-V3.1'} id='run--2f68bf26-7f58-44d3-8e33-d99029e77753' usage_metadata={'input_tokens': 6425, 'output_tokens': 53, 'total_tokens': 6478, 'input_token_details': {}, 'output_token_details': {}}

09-17 01:01:04 INFO: 172.18.0.7:34316 - "GET /api/chat/agent/ChatbotAgent/history?thread_id=fd236128-9630-43cc-aad5-454f153e4dfa HTTP/1.1" 200

09-17 01:01:06 INFO: 127.0.0.1:52774 - "GET /api/system/health HTTP/1.1" 200

我在调用工具的时候出现中断 这是日志:

问题分析

工具调用被分割:AI 试图调用一个工具(可能是 SQL 查询工具),但工具调用被分割成了多个小块:

SELECT

*

FROM

weather

_info

LIM

IT

5

等等...

最终形成的无效调用:这些片段组合起来应该是 SELECT * FROM weather_info LIMIT 5,但由于被分割调用,系统无法识别为一个有效的工具调用。

根本原因:这可能是由于:

工具调用的格式不正确

模型输出格式与工具期望的格式不匹配

工具调用解析器配置问题

wxw-123 avatar Sep 18 '25 11:09 wxw-123

目前这种情况时而出现 时而没有 请问如何解决呢

wxw-123 avatar Sep 18 '25 11:09 wxw-123

你好,这个我在使用中无法复现。对于日志中提到的这个片段的问题,这个是正常的,工具的调用本身也是字符串,是按照token流式输出的。

xerrors avatar Sep 18 '25 12:09 xerrors

您的意思是这个 出现的概率是正常的吗

wxw-123 avatar Sep 18 '25 12:09 wxw-123

就是可不可以加一个过滤呢 把转义符合过滤掉

wxw-123 avatar Sep 18 '25 12:09 wxw-123

Image

wxw-123 avatar Sep 18 '25 12:09 wxw-123

您的意思是这个 出现的概率是正常的吗

并不是,我的意思是,分段输出调用是正常的,但是拼在一起有问题的话,这个是不正常的。只是我没有办法复现出来

xerrors avatar Sep 18 '25 12:09 xerrors

Image Image

wxw-123 avatar Sep 18 '25 12:09 wxw-123

刚刚又出现了 我使用的是DeepSeekV3.1

wxw-123 avatar Sep 18 '25 12:09 wxw-123

"mysql": { "command": "npx", "args": ["-y", "@benborla29/[email protected]"], "env": { "MYSQL_HOST": "host.docker.internal", "MYSQL_PORT": "3306", "MYSQL_USER": "root", "MYSQL_PASS": "123456", "MYSQL_DB": "weather_data" }, "transport": "stdio" }

这个是我的数据库MCP

wxw-123 avatar Sep 18 '25 12:09 wxw-123

Image Image

限定之后就可以

wxw-123 avatar Sep 18 '25 12:09 wxw-123

您的意思是这个 出现的概率是正常的吗

并不是,我的意思是,分段输出调用是正常的,但是拼在一起有问题的话,这个是不正常的。只是我没有办法复现出来

这个会不会是概率问题呢

wxw-123 avatar Sep 18 '25 12:09 wxw-123

作者你测试的时候 需要复现这种bug场景的时候 可以这样 :

用我的这个MCP服务 然后同时几个用户 进行数据查询 给他一些问题 让他执行数据分析智能体 查询数据库 大约 四五个用户 同时请求 可能会出现 我之前就是这样发现这个问题的

wxw-123 avatar Sep 18 '25 12:09 wxw-123

复现了,对话管理的问题

xerrors avatar Sep 18 '25 13:09 xerrors

但是转义字符没有复现,只是出现了对话混乱的问题

xerrors avatar Sep 18 '25 13:09 xerrors

分两部分:

  • [ ] 多 conversation 的合并问题(导致多个 DeepSeek-V3.1 出现)
  • [ ] 多线程情况下每个 conversation 的独立需要确认

xerrors avatar Sep 18 '25 13:09 xerrors

但是转义字符没有复现,只是出现了对话混乱的问题

中断的时候的前几秒 调用工具的时候 参数后面就有转义字符 我查询相关资料 说是因为被识别为字符串了 而不是一个json

wxw-123 avatar Sep 18 '25 13:09 wxw-123

复现了,对话管理的问题

然后其实我单开一个的时候也会出现这种问题 上面的截图 就是我单个用户的情况

wxw-123 avatar Sep 18 '25 13:09 wxw-123

希望作者可以处理一下 这个bug

wxw-123 avatar Sep 18 '25 13:09 wxw-123

经过多次尝试,认为是模型或者 LangChain 的问题,我更换模型后没有再复现过,比如 model_name 字段,项目本身没有对其做额外的处理,不会出现字段重复的情况。

可以尝试下其他模型是否会出现此问题 @wxw-123

xerrors avatar Sep 18 '25 15:09 xerrors

经过多次尝试,认为是模型或者 LangChain 的问题,我更换模型后没有再复现过,比如 model_name 字段,项目本身没有对其做额外的处理,不会出现字段重复的情况。

可以尝试下其他模型是否会出现此问题 @wxw-123

作者你是试的目前DeepSeek系列的模型,发现才会出现此类问题吗?换成其他的模型就没有在出现此类问题了?

wxw-123 avatar Sep 18 '25 15:09 wxw-123

希望作者 可以多测试一下 望解决这个大bug 因为后续可能会经常调用MCP进行外部工具使用

wxw-123 avatar Sep 18 '25 15:09 wxw-123

我也测试了几次 换了qwen模型 智普的 也有类似的故障出现

wxw-123 avatar Sep 18 '25 15:09 wxw-123