xiaozhi-esp32-server/main/xiaozhi-server/core/utils
Brad Shannon 31cc365fcd fix(core): guard orphan tool messages in dialogue serialization
The intent REQLLM path (core/handle/intentHandler.py) records a tool result via
`Message(role="tool", content=text)` with no tool_call_id and no preceding
assistant tool_calls. `Dialogue.getMessages` serializes it as a function_response
anyway. When that history is later replayed to an OpenAI-compatible endpoint,
the endpoint derives `function_response.name` by matching the tool_call_id back
to a function_call; with no match the name is empty.

gemini-2.5-flash tolerated the empty name, but gemini-3.5-flash rejects the whole
request with HTTP 400 "GenerateContentRequest.contents[N].parts[0]
.function_response.name: Name cannot be empty", so every affected turn falls back
to "Sorry, the system is busy now." Only tool-using sessions and only the chat
turns that replay the accumulated tool results were affected.

Guard at the serialization boundary in `getMessages`: emit a role="tool" message
as a function_response only when a preceding assistant message carries a matching
tool_call id; otherwise demote it to a plain assistant context line so the turn
survives. Valid tool-call pairs — including empty-string ids that still match —
are unchanged. This defends against any orphan source, not just the intent path.

Adds self-contained regression tests (no conftest required).
2026-07-14 16:09:00 -04:00
..
cache update:常用音频增加缓存,抵御高并发未授权设备访问 2025-12-13 23:10:40 +08:00
asr.py 重新划分目录 (#214) 2025-03-05 23:13:24 +08:00
audioRateController.py fix: 修复流式场景下的误判 2026-03-25 11:07:43 +08:00
auth.py update:优化视觉接口认证校验 2025-06-13 12:53:58 +08:00
context_provider.py update:修改上下文源的device_id 2025-12-08 14:25:11 +08:00
current_time.py fix:修复LLM意图识别 2025-09-11 14:38:27 +08:00
dialogue.py fix(core): guard orphan tool messages in dialogue serialization 2026-07-14 16:09:00 -04:00
gc_manager.py update:减少日志产生 2025-12-01 16:38:10 +08:00
intent.py 本地记忆+意图识别 (#250) 2025-03-09 21:33:45 +08:00
llm.py 重新划分目录 (#214) 2025-03-05 23:13:24 +08:00
memory.py update:合并非tts代码 2025-05-21 13:18:12 +08:00
modules_initialize.py update:python对接声纹识别优化 2025-07-10 15:03:49 +08:00
opus_encoder_utils.py update: 长按设备ASR适配 2025-12-11 17:12:56 +08:00
output_counter.py update:合并非tts代码 2025-05-21 13:18:12 +08:00
p3.py update:流式优化暂不稳定,先回滚到早期代码 2025-08-30 22:59:21 +08:00
prompt_manager.py 同步工具异步化处理 2026-07-07 14:45:50 +08:00
textUtils.py feat: 为多个模块添加类型注解以增强代码可读性 2026-01-25 17:47:52 +08:00
tts.py fix: 调整处理顺序保留英文空格的同时修复markdown被识别为纯ASCII 字符的错误返回 2026-04-17 10:59:29 +08:00
util.py 增加asr初始化ID判断 2026-02-05 15:42:23 +08:00
vad.py update:合并非tts代码 2025-05-21 13:18:12 +08:00
vllm.py update:单模块部署xiaozhi-server,支持mcp调用摄像头识图 2025-06-01 02:26:19 +08:00
voiceprint_provider.py update:修改声纹日志 2025-09-08 09:32:10 +08:00
wakeup_word.py 添加阿里云CosyVoice 和 修复文件编码 2025-09-10 11:17:56 +08:00