What happened / 发生了什么
使用 DeepSeek Reasoner 模型开启工具调用时,报 400 错误导致对话失败:
Error code: 400 - {'error': {'message': 'Invalid assistant message: content or tool_calls must be set'}}
原因是 openai_source.py 的 _query_stream 方法缺少空 assistant 消息过滤逻辑。DeepSeek Reasoner 工具调用时只返回 reasoning_content 无 completion_text,序列化后 content 为空,触发 DeepSeek 严格校验。_query 在 #7202 已有修复,但 _query_stream 未同步,且 _query 也未覆盖 content == [] 的情况。
Reproduce / 如何复现?
1.Provider 设置为 DeepSeek,模型选择 deepseek-reasoner
2.开启工具调用功能
3.发送消息触发工具调用
4.调用完成后再次发送任意对话信息
5.400报错
AstrBot version, deployment method (e.g., Windows Docker Desktop deployment), provider used, and messaging platform used. / AstrBot 版本、部署方式(如 Windows Docker Desktop 部署)、使用的提供商、使用的消息平台适配器
win10 AstrBotv4.23.2
OS
Windows
Logs / 报错日志
[2026-04-22 13:49:47.185] [Core] [INFO] [core.event_bus:61]: [default] [default(aiocqhttp)] 凌/qq号: 你好
[2026-04-22 13:49:47.223] [Core] [INFO] [astrbot_plugin_qq_group_sign.main:376]: 成功捕获 aiocqhttp 机器人实例,后台 API 调用已启用。
[2026-04-22 13:49:47.589] [Core] [WARN] [v4.23.2] [runners.tool_loop_agent_runner:510]: Chat Model deepseek/deepseek-reasoner request error: Error code: 400 - {'error': {'message': 'Invalid assistant message: content or tool_calls must be set', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_request_error'}}
Traceback (most recent call last):
File "C:\Users\Administrator\Desktop\chatbot\AstrBotLauncher-0.2.0\AstrBot\astrbot\core\agent\runners\tool_loop_agent_runner.py", line 465, in iter_llm_responses_with_fallback
async for attempt in retrying:
File "C:\Users\Administrator\Desktop\chatbot\AstrBotLauncher-0.2.0\AstrBot\venv\Lib\site-packages\tenacity\asyncio_init.py", line 166, in anext
do = await self.iter(retry_state=self.retry_state)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Administrator\Desktop\chatbot\AstrBotLauncher-0.2.0\AstrBot\venv\Lib\site-packages\tenacity\asyncio_init.py", line 153, in iter
result = await action(retry_state)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Administrator\Desktop\chatbot\AstrBotLauncher-0.2.0\AstrBot\venv\Lib\site-packages\tenacity_utils.py", line 99, in inner
return call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Administrator\Desktop\chatbot\AstrBotLauncher-0.2.0\AstrBot\venv\Lib\site-packages\tenacity_init_.py", line 400, in
self._add_action_func(lambda rs: rs.outcome.result())
^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python311\Lib\concurrent\futures_base.py", line 449, in result
return self.__get_result()
^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python311\Lib\concurrent\futures_base.py", line 401, in __get_result
raise self._exception
File "C:\Users\Administrator\Desktop\chatbot\AstrBotLauncher-0.2.0\AstrBot\astrbot\core\agent\runners\tool_loop_agent_runner.py", line 469, in _iter_llm_responses_with_fallback
async for resp in self._iter_llm_responses(
File "C:\Users\Administrator\Desktop\chatbot\AstrBotLauncher-0.2.0\AstrBot\astrbot\core\agent\runners\tool_loop_agent_runner.py", line 429, in _iter_llm_responses
async for resp in stream: # type: ignore
File "C:\Users\Administrator\Desktop\chatbot\AstrBotLauncher-0.2.0\AstrBot\astrbot\core\provider\sources\openai_source.py", line 1235, in text_chat_stream
) = await self._handle_api_error(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Administrator\Desktop\chatbot\AstrBotLauncher-0.2.0\AstrBot\astrbot\core\provider\sources\openai_source.py", line 1109, in _handle_api_error
raise e
File "C:\Users\Administrator\Desktop\chatbot\AstrBotLauncher-0.2.0\AstrBot\astrbot\core\provider\sources\openai_source.py", line 1222, in text_chat_stream
async for response in self._query_stream(payloads, func_tool):
File "C:\Users\Administrator\Desktop\chatbot\AstrBotLauncher-0.2.0\AstrBot\astrbot\core\provider\sources\openai_source.py", line 622, in _query_stream
stream = await self.client.chat.completions.create(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Administrator\Desktop\chatbot\AstrBotLauncher-0.2.0\AstrBot\venv\Lib\site-packages\openai\resources\chat\completions\completions.py", line 2678, in create
return await self._post(
^^^^^^^^^^^^^^^^^
File "C:\Users\Administrator\Desktop\chatbot\AstrBotLauncher-0.2.0\AstrBot\venv\Lib\site-packages\openai_base_client.py", line 1881, in post
return await self.request(cast_to, opts, stream=stream, stream_cls=stream_cls)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Administrator\Desktop\chatbot\AstrBotLauncher-0.2.0\AstrBot\venv\Lib\site-packages\openai_base_client.py", line 1666, in request
raise self._make_status_error_from_response(err.response) from None
openai.BadRequestError: Error code: 400 - {'error': {'message': 'Invalid assistant message: content or tool_calls must be set', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_request_error'}}
[2026-04-22 13:49:47.755] [Core] [INFO] [respond.stage:183]: Prepare to send - 凌/qq号: [ComponentType.Node]
Are you willing to submit a PR? / 你愿意提交 PR 吗?
Code of Conduct
What happened / 发生了什么
使用 DeepSeek Reasoner 模型开启工具调用时,报 400 错误导致对话失败:
Error code: 400 - {'error': {'message': 'Invalid assistant message: content or tool_calls must be set'}}
原因是 openai_source.py 的 _query_stream 方法缺少空 assistant 消息过滤逻辑。DeepSeek Reasoner 工具调用时只返回 reasoning_content 无 completion_text,序列化后 content 为空,触发 DeepSeek 严格校验。_query 在 #7202 已有修复,但 _query_stream 未同步,且 _query 也未覆盖 content == [] 的情况。
Reproduce / 如何复现?
1.Provider 设置为 DeepSeek,模型选择 deepseek-reasoner
2.开启工具调用功能
3.发送消息触发工具调用
4.调用完成后再次发送任意对话信息
5.400报错
AstrBot version, deployment method (e.g., Windows Docker Desktop deployment), provider used, and messaging platform used. / AstrBot 版本、部署方式(如 Windows Docker Desktop 部署)、使用的提供商、使用的消息平台适配器
win10 AstrBotv4.23.2
OS
Windows
Logs / 报错日志
[2026-04-22 13:49:47.185] [Core] [INFO] [core.event_bus:61]: [default] [default(aiocqhttp)] 凌/qq号: 你好
[2026-04-22 13:49:47.223] [Core] [INFO] [astrbot_plugin_qq_group_sign.main:376]: 成功捕获 aiocqhttp 机器人实例,后台 API 调用已启用。
[2026-04-22 13:49:47.589] [Core] [WARN] [v4.23.2] [runners.tool_loop_agent_runner:510]: Chat Model deepseek/deepseek-reasoner request error: Error code: 400 - {'error': {'message': 'Invalid assistant message: content or tool_calls must be set', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_request_error'}}
Traceback (most recent call last):
File "C:\Users\Administrator\Desktop\chatbot\AstrBotLauncher-0.2.0\AstrBot\astrbot\core\agent\runners\tool_loop_agent_runner.py", line 465, in iter_llm_responses_with_fallback
async for attempt in retrying:
File "C:\Users\Administrator\Desktop\chatbot\AstrBotLauncher-0.2.0\AstrBot\venv\Lib\site-packages\tenacity\asyncio_init.py", line 166, in anext
do = await self.iter(retry_state=self.retry_state)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Administrator\Desktop\chatbot\AstrBotLauncher-0.2.0\AstrBot\venv\Lib\site-packages\tenacity\asyncio_init.py", line 153, in iter
result = await action(retry_state)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Administrator\Desktop\chatbot\AstrBotLauncher-0.2.0\AstrBot\venv\Lib\site-packages\tenacity_utils.py", line 99, in inner
return call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Administrator\Desktop\chatbot\AstrBotLauncher-0.2.0\AstrBot\venv\Lib\site-packages\tenacity_init_.py", line 400, in
self._add_action_func(lambda rs: rs.outcome.result())
^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python311\Lib\concurrent\futures_base.py", line 449, in result
return self.__get_result()
^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python311\Lib\concurrent\futures_base.py", line 401, in __get_result
raise self._exception
File "C:\Users\Administrator\Desktop\chatbot\AstrBotLauncher-0.2.0\AstrBot\astrbot\core\agent\runners\tool_loop_agent_runner.py", line 469, in _iter_llm_responses_with_fallback
async for resp in self._iter_llm_responses(
File "C:\Users\Administrator\Desktop\chatbot\AstrBotLauncher-0.2.0\AstrBot\astrbot\core\agent\runners\tool_loop_agent_runner.py", line 429, in _iter_llm_responses
async for resp in stream: # type: ignore
File "C:\Users\Administrator\Desktop\chatbot\AstrBotLauncher-0.2.0\AstrBot\astrbot\core\provider\sources\openai_source.py", line 1235, in text_chat_stream
) = await self._handle_api_error(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Administrator\Desktop\chatbot\AstrBotLauncher-0.2.0\AstrBot\astrbot\core\provider\sources\openai_source.py", line 1109, in _handle_api_error
raise e
File "C:\Users\Administrator\Desktop\chatbot\AstrBotLauncher-0.2.0\AstrBot\astrbot\core\provider\sources\openai_source.py", line 1222, in text_chat_stream
async for response in self._query_stream(payloads, func_tool):
File "C:\Users\Administrator\Desktop\chatbot\AstrBotLauncher-0.2.0\AstrBot\astrbot\core\provider\sources\openai_source.py", line 622, in _query_stream
stream = await self.client.chat.completions.create(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Administrator\Desktop\chatbot\AstrBotLauncher-0.2.0\AstrBot\venv\Lib\site-packages\openai\resources\chat\completions\completions.py", line 2678, in create
return await self._post(
^^^^^^^^^^^^^^^^^
File "C:\Users\Administrator\Desktop\chatbot\AstrBotLauncher-0.2.0\AstrBot\venv\Lib\site-packages\openai_base_client.py", line 1881, in post
return await self.request(cast_to, opts, stream=stream, stream_cls=stream_cls)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Administrator\Desktop\chatbot\AstrBotLauncher-0.2.0\AstrBot\venv\Lib\site-packages\openai_base_client.py", line 1666, in request
raise self._make_status_error_from_response(err.response) from None
openai.BadRequestError: Error code: 400 - {'error': {'message': 'Invalid assistant message: content or tool_calls must be set', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_request_error'}}
[2026-04-22 13:49:47.755] [Core] [INFO] [respond.stage:183]: Prepare to send - 凌/qq号: [ComponentType.Node]
Are you willing to submit a PR? / 你愿意提交 PR 吗?
Code of Conduct