fix(agent): deepseek thinking replay twilight - #1182
Merged
chen-ran merged 2 commits intoSep 8, 2026
Conversation
DeepSeek 思考模式在请求携带 tools 时校验最后一条 user 消息之后的每条 assistant tool-call 消息:缺少 reasoning_content 键返回 400 "The reasoning_content in the thinking mode must be passed back to the API", 空字符串可通过。运行中的步骤由 DeepSeek 服务端按 tool_call id 补齐, 因此只有 ask_user / 工具审批续跑回放持久化历史时触发。 Twilight 主线 18a9879(felinics/twilight felinics#48)在 DeepSeek / Kimi compat 下 为缺少 reasoning part 的 tool-call assistant 消息补 reasoning_content: "", 并把响应中的空 reasoning_content 记录为 reasoning block。Memoh 已按官方 base URL 或 chat_completions_compat 配置解析 DeepSeek compat,因此本仓库 只需升级依赖:3e7b614 -> 18a9879。 验证:通过 NewSDKChatModel 构造 deepseek-v4-flash 模型,回放 "assistant tool-call(无 reasoning)→ tool result" 历史并携带 tools 发起 请求。旧版 Twilight 下 DoGenerate 与 DoStream 均返回上述 400;修复版 两者均返回 200 并生成回答。
工具审批 / ask_user 续跑的请求不携带当前用户消息,持久化历史整体落入 history 槽位,工具交互裁剪策略(消息数超过阈值时生效)会剥掉挂起步骤的 tool call、tool result 和 reasoning。结果有两个:模型看不到工具结果, 续跑后重新发起同一个工具调用;请求以一条没有 reasoning_content 的 assistant 文本消息结尾,DeepSeek 思考模式返回 400 "The reasoning_content in the thinking mode must be passed back to the API"。 Twilight 侧只为带 tool_calls 的 assistant 消息补 reasoning_content, 覆盖不到这种被剥空的尾部消息;ask_user 续跑不受影响,因为 ask_user 的 调用与结果在裁剪时被显式保留。 修复:applyToolExchangePolicy 在没有当前用户消息槽位、且历史最后一条是 tool result 或仍带 tool call 的 assistant 消息时,将最后一条 user 之后 的尾部视为进行中的轮次,不做裁剪。以 assistant 文本结束的历史轮次仍按 原逻辑裁剪;正常轮次始终带有当前用户消息槽位,行为不变。 同时在 ask_user / 工具审批续跑循环中记录 native error 事件的原始文本, publicAgentStreamEvent 之前只留下 agent.response_interrupted 这一稳定码。 验证:dev 环境 deepseek-v4-flash,长历史 session 内触发 exec 审批并批准。 修复前续跑请求尾部为纯文本 assistant,返回 400;修复后请求尾部包含带 reasoning_content 与 tool_calls 的 assistant 消息和 tool result, run 正常 completed,模型基于工具结果作答。
chen-ran
approved these changes
Sep 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
upstream : felinics/twilight#48
fix #1176