AstrBot icon indicating copy to clipboard operation
AstrBot copied to clipboard

[Bug] subagent在使用官方 DeepSeek-V4.1 时,出现 DSML 融毁

Open SkonJIYHD opened this issue 2 weeks ago • 5 comments

问题描述

我尝试指引我家 BOT 使用我创建的 subagent:astrbot_dev进行插件开发,BOT 转接给 subagent 之后,subagent 返回 DSML 工具调用(因为携带了 DSML 所以没有正常工具调用)

如何复现?

1.开启 subagent 2.模型设置为 DeepSeek flash 3.简单写一个提示词 4.让 AI 调用subagent

AstrBot 版本

v4.29.4

操作系统

Linux

部署方式

Podman(docker)

使用的消息平台适配器

QQ 官方机器人(WebSocket)

错误日志

[2026-11-15 02:13:38.307] [Core] [DBUG] [sources.openai_source:586]: completion: ChatCompletion(id='d449b665-7afd-44f0-b922-74d16c931689', choices=[Choice(finish_reason='tool_calls', index=0, logprobs=None, message=ChatCompletionMessage(content='', refusal=None, role='assistant', annotations=None, audio=None, function_call=None, tool_calls=[ChatCompletionMessageFunctionToolCall(id='call_00_ET_ejCgcVWUoaYijoBVwKrL7023', function=Function(arguments='{"input": "请接手一个 AstrBot 插件示例的编写与校验任务(用户在进行 subagent 测试)。\\n\\n已完成的部分:/AstrBot/data/plugins/astrbot_plugin_helloworld 目录下已创建 main.py、metadata.yaml、README.md、requirements.txt、.gitignore,实现了一个 /hello 指令,回复 \\"Hello, <昵称>!\\",并通过了 py_compile 语法检查。\\n\\n请你:\\n1. 读一下 /AstrBot/data/skills/skill-astrbot-dev-v4.29.4/SKILL.md 及相关规范;\\n2. 复核该插件结构、metadata.yaml 字段、代码写法是否符合 AstrBot v4 插件规范,必要时直接改进文件;\\n3. 检查插件是否依赖当前 AstrBot 版本的 astrbot_version 约束(当前版本见环境),确认放错位置或无第三方依赖问题;\\n4. 给出简短的复核结论和不通过点。", "background_task": false}', name='transfer_to_astrbot_dev'), type='function', index=0)], reasoning_content=''))], created=1794708816, model='deepseek-flash', object='chat.completion', metadata=None, moderation=None, service_tier=None, system_fingerprint='bc19ba97cbe016479903222bb1578db6', usage=CompletionUsage(completion_tokens=[REDACTED], prompt_tokens=[REDACTED], total_tokens=[REDACTED], completion_tokens_details=[REDACTED], audio_tokens=[REDACTED], reasoning_tokens=[REDACTED], rejected_prediction_tokens=[REDACTED], text_tokens=[REDACTED], prompt_tokens_details=[REDACTED], cache_write_tokens=[REDACTED], cached_tokens=[REDACTED], image_tokens=[REDACTED], text_tokens=[REDACTED], prompt_cache_hit_tokens=[REDACTED], prompt_cache_miss_tokens=[REDACTED]
[2026-11-15 02:13:38.309] [Core] [INFO] [runners.tool_loop_agent_runner:1185]: Agent 使用工具: ['transfer_to_astrbot_dev']
[2026-11-15 02:13:38.310] [Core] [INFO] [runners.tool_loop_agent_runner:1241]: 使用工具:transfer_to_astrbot_dev,参数:{'input': '请接手一个 AstrBot 插件示例的编写与校验任务(用户在进行 subagent 测试)。\n\n已完成的部分:/AstrBot/data/plugins/astrbot_plugin_helloworld 目录下已创建 main.py、metadata.yaml、README.md、requirements.txt、.gitignore,实现了一个 /hello 指令,回复 "Hello, <昵称>!",并通过了 py_compile 语法检查。\n\n请你:\n1. 读一下 /AstrBot/data/skills/skill-astrbot-dev-v4.29.4/SKILL.md 及相关规范;\n2. 复核该插件结构、metadata.yaml 字段、代码写法是否符合 AstrBot v4 插件规范,必要时直接改进文件;\n3. 检查插件是否依赖当前 AstrBot 版本的 astrbot_version 约束(当前版本见环境),确认放错位置或无第三方依赖问题;\n4. 给出简短的复核结论和不通过点。', 'background_task': False}
[2026-11-15 02:13:38.313] [Core] [DBUG] [runners.base:70]: Agent state transition: AgentState.IDLE -> AgentState.RUNNING
[2026-11-15 02:13:38.313] [Core] [DBUG] [runners.tool_loop_agent_runner:696]: [BefCompact] messages -> [2] system,user
[2026-11-15 02:13:38.316] [Core] [DBUG] [runners.tool_loop_agent_runner:696]: [AftCompact] messages -> [2] system,user
[2026-11-15 02:13:39.433] [Core] [DBUG] [sources.openai_source:586]: completion: ChatCompletion(id='555f77bb-ae92-4fbe-816f-bf444c5f76a1', choices=[Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(content='\n\n<||DSML|| calls>\n<||DSML|| invoke name="exec">\n<||DSML|| parameter name="command" string="true">pwd; ls -la; echo ---; ls -la /AstrBot 2>&1 | head -20</||DSML|| parameter>\n</||DSML|| invoke>\n</||DSML|| calls>', refusal=None, role='assistant', annotations=None, audio=None, function_call=None, tool_calls=None, reasoning_content="Let me start by exploring the workspace. The task says files are in /AstrBot/data/plugins/... but my workspace is limited. Let me check what's readable.\n\nLet me first try to read the skill file and the plugin."))], created=1794708818, model='deepseek-flash', object='chat.completion', metadata=None, moderation=None, service_tier=None, system_fingerprint='bc19ba97cbe016479903222bb1578db6', usage=CompletionUsage(completion_tokens=[REDACTED], prompt_tokens=[REDACTED], total_tokens=[REDACTED], completion_tokens_details=[REDACTED], audio_tokens=[REDACTED], reasoning_tokens=[REDACTED], rejected_prediction_tokens=[REDACTED], text_tokens=[REDACTED], prompt_tokens_details=[REDACTED], cache_write_tokens=[REDACTED], cached_tokens=[REDACTED], image_tokens=[REDACTED], text_tokens=[REDACTED], prompt_cache_hit_tokens=[REDACTED], prompt_cache_miss_tokens=[REDACTED]
[2026-11-15 02:13:39.435] [Core] [DBUG] [runners.base:70]: Agent state transition: AgentState.RUNNING -> AgentState.DONE
[2026-11-15 02:13:39.437] [Core] [INFO] [runners.tool_loop_agent_runner:1438]: Tool `transfer_to_astrbot_dev` Result: <||DSML|| calls>
<||DSML|| invoke name="exec">
<||DSML|| parameter name="command" string="true">pwd; ls -la; echo ---; ls -la /AstrBot 2>&1 | head -20</||DSML|| parameter>
</||DSML|| invoke>
</||DSML|| calls>
[2026-11-15 02:13:39.438] [Core] [DBUG] [runners.tool_loop_agent_runner:696]: [BefCompact] messages -> [22] system,user,assistant,user,...,assistant,user,assistant,tool
[2026-11-15 02:13:39.440] [Core] [DBUG] [runners.tool_loop_agent_runner:696]: [AftCompact] messages -> [22] system,user,assistant,user,...,assistant,user,assistant,tool
[2026-11-15 02:13:41.218] [Core] [DBUG] [sources.openai_source:586]: completion: ChatCompletion(id='4db93a7e-b491-4525-95ab-31103a19d9d1', choices=[Choice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(content='已经转过去了,但返回的内容不对劲,没有正常结论,只返回了一串没解析的原始标签,内容只是执行 ls、pwd 之类的命令\n\n要不要我再转一次,还是先就这样', refusal=None, role='assistant', annotations=None, audio=None, function_call=None, tool_calls=None, reasoning_content="The tool returned something odd — it looks like the subagent's raw output leaked (a DSML tool call block). This is the handoff result. It seems the subagent's response is garbled. I should report to user briefly, in persona.\n\nThe handoff appears to have returned malformed content. Let me summarize: 转过去了,回来一堆乱码/原始标签,没拿到正经结论。\n\nMaybe try once more? Or just report. Keep it short.\n\nI'll report plainly and offer to rerun."))], created=1794708819, model='deepseek-flash', object='chat.completion', metadata=None, moderation=None, service_tier=None, system_fingerprint='bc19ba97cbe016479903222bb1578db6', usage=CompletionUsage(completion_tokens=[REDACTED], prompt_tokens=[REDACTED], total_tokens=[REDACTED], completion_tokens_details=[REDACTED], audio_tokens=[REDACTED], reasoning_tokens=[REDACTED], rejected_prediction_tokens=[REDACTED], text_tokens=[REDACTED], prompt_tokens_details=[REDACTED], cache_write_tokens=[REDACTED], cached_tokens=[REDACTED], image_tokens=[REDACTED], text_tokens=[REDACTED], prompt_cache_hit_tokens=[REDACTED], prompt_cache_miss_tokens=[REDACTED]

辅助信息

astrbot-diagnostics-20261115-021436.zip

检查清单

  • [x] 我已在 Issue 列表中搜索过相关问题仍无法解决,或该问题从未被报告过。
  • [x] 我已尝试过禁用所有插件,排除了可能是因插件导致的问题。
  • [x] 我报告的问题与 AstrBot 本体相关,而非在报告某一插件的问题。
  • [x] 我已阅读并同意本项目的贡献者行为准则。
  • [ ] (可选)我愿意提交 PR 以帮助修复该问题。

SkonJIYHD avatar Nov 15 '26 02:11 SkonJIYHD

subagent配置如图:

Screenshot_2026_1115_102948

SkonJIYHD avatar Nov 15 '26 02:11 SkonJIYHD

上游问题

lingyun14beta avatar Nov 15 '26 03:11 lingyun14beta

结论:本体 bug(防御缺失),触发源在 DeepSeek 侧 根因:DeepSeek-V4-Flash 输出的是降级格式 <||DSML|| calls>(官方为 <|DSML|tool_calls>),API 的 tool parser 不识别,整段作为 content 返回且 tool_calls=None;AstrBot 的 handoff 把这段文本原样当作 subagent 结果回传 —— astrbot/core/astr_agent_runtime/tool_executor.py:401 @ 23db1ad08

建议:

  1. _execute_handoff 返回前检查 completion_text,命中 <|DSML| / <||DSML|| 时不作为正常结果返回,改为重试或明确报错。
  2. 在 openai_source 层对降级 DSML 做归一化,把 ||DSML|| 修正回官方 token 再交给 parser。同类处理见 DeepSeek-V4-Pro discussion #209 里的 normalize_dsml_token_variants。
  3. 至少不要把原始 XML 塞回主 agent 上下文 —— 残壳进入历史后会诱导模型继续输出 DSML,形成自增强循环。相关记录:vLLM #48931、oh-my-pi #10556。

建议标签:area:provider area:core


本评论由 AI 辅助生成,已对照上游 issue 与本地代码核实。

silvaling avatar Nov 15 '26 03:11 silvaling

我目前是比较同意silvaling的观点的,因为在主 Agent 都能用 DeepSeek 且不会出现 DSML 情况下,subagent 用DeepSeek会百分百出现 DSML 融毁的情况就很奇怪

这确实是 DeepSeek 上游的问题,但是至少在框架端做一些机制能防止它频繁出现 DSML(同类案例参考 operit)

SkonJIYHD avatar Nov 15 '26 03:11 SkonJIYHD

如果我用的不是官方 V4.1 的话,我也不会提这个 Issue,因为我知道第三方中转会影响模型

SkonJIYHD avatar Nov 15 '26 03:11 SkonJIYHD