Skip to content

DeepSeek!

Choose a tag to compare

@knoop7 knoop7 released this 27 May 15:19

将每轮动态上下文(频道信息、语言偏好、话题提示、历史摘要)从系统 prompt 前缀中剥离,移入用户消息体。系统前缀在整个对话窗口内完全稳定不变,DeepSeek 前缀缓存命中率从 0% 提升至接近 100%。

  • 首次对话冷启动无缓存,正常计费
  • 第二轮起命中前缀缓存,输入 token 费用降低约 90%
  • 长对话窗口(10+ 轮工具调用)预计单窗口节省约 20 元
  • 其他支持前缀缓存的 AI 服务(Claude、ChatGPT、MiMo等)同样受益
  • 新增 prefix fingerprint 追踪机制

39 项修复与改进

WebSocket 实时流

  1. 修复 get_runtime_store 未导入导致的 NameError 崩溃
  2. 新增 live_turn_snapshot 接口返回活跃回合状态及时间戳
  3. 新增 subscribe_live_stream 支持刷新后事件缓冲重放
  4. 对话任务 detach 化:浏览器断连不再中断后端推理
  5. 添加 stream_end 哨兵事件标记对话完成
  6. 刷新后自动重连活跃流式回合
  7. 修复管道事件中空 delta 的无效转发
  8. 内部 LLM 模式下跳过管道事件转发避免重复

状态栏时钟

  1. 两个时钟(窗口时间 / 回合时间)改为实时计算
  2. 冻结在结束时刻不再偷跑
  3. 新增后端轮询探测:即使事件丢失也能正确停表
  4. 从后端恢复 turn_start_timewindow_start_time 精确续接
  5. 后端存储 turn_start_times / window_start_times per conversation

工具系统

  1. GetSkillIndex 工具执行器 fallback 查找修复(不再返回 Unknown tool)
  2. GetDateTimeGetSkillIndexHassGetDateTime 加入官方意图白名单
  3. 移除 HassToggle(已被原生覆盖无需白名单)
  4. 运行时工具列表缓存化避免重复构建
  5. 插件工具排序保证确定性

前端 UI

  1. 屏蔽 .claw-md h1-h6 大写加粗渲染问题
  2. 工具卡片颜色统一为灰色(流式和刷新后一致)
  3. 关闭连续对话时不注入 DOM 到官方默认气泡
  4. 修复 claw-ta-card / claw-ta-panel 被 em 样式意外覆盖

Agent 容错与错误处理

  1. 新增瞬态错误关键词库(断连/超时/502/503/429 等)
  2. 新增不可用错误关键词库(not found / not loaded 等)
  3. 瞬态错误后保留已有部分输出而非全部丢弃
  4. 新增 agent 错误自修复机制(自动 reload 集成后重试)
  5. 错误信息美化格式化输出给用户
  6. 对话结束时清理 live_response_parts 避免内存泄漏

Prompt 架构重构

  1. build_base_prompt 拆分为稳定前缀 + 动态 build_turn_context_prompt
  2. 频道检测(语音/IM/手机/桌面)抽取为独立函数
  3. 动态上下文通过 <turn-context> XML 标签包裹注入用户消息
  4. 历史摘要、配置审批、IM 审批 prompt 移至动态段
  5. 动态段有独立 budget 上限(8000 字符)避免挤占前缀

对话历史与状态

  1. 新增 mark_turn_in_progress / clear_in_progress 实时标记
  2. /stop 命令增强:扫描所有 detached task 并取消
  3. /stop 清理 live event buffer 和 in-progress 标记
  4. chat_history_api 新增 display_depth 参数支持
  5. 自适应记忆增加 graph cleanup hooks

其他

  1. Hook 事件系统新增 UserPromptSubmit 钩子支持请求拦截

Core Architecture Change

Moved per-turn dynamic context (channel info, language preference, topic hints, history summary) out of the system prompt prefix and into the user message body. The system prefix is now completely stable across the entire conversation window, boosting DeepSeek prefix cache hit rate from 0% to near 100%.

  • First-turn cold start incurs no cache, billed normally
  • Second turn onward hits prefix cache, reducing input token cost by ~90%
  • Long conversation windows (10+ tool call rounds) expected to save ~20 CNY per window
  • Other prefix-cache-capable AI services (Claude, ChatGPT, MiMo, etc.) benefit equally
  • Added prefix fingerprint tracking mechanism

39 Fixes & Improvements

WebSocket Real-time Streaming

  1. Fixed get_runtime_store NameError crash due to missing import
  2. Added live_turn_snapshot endpoint returning active turn state and timestamps
  3. Added subscribe_live_stream with event buffer replay after refresh
  4. Conversation tasks detach-ified: browser disconnect no longer aborts backend inference
  5. Added stream_end sentinel event to mark conversation completion
  6. Auto-reconnect to active streaming turn after refresh
  7. Fixed invalid forwarding of empty deltas in pipeline events
  8. Skipped pipeline event forwarding in internal LLM mode to prevent duplication

Status Bar Clocks

  1. Both clocks (window time / turn time) now calculate in real time
  2. Frozen at end moment, no longer creeping forward
  3. Added backend polling probe: stops correctly even if events are lost
  4. Restores turn_start_time and window_start_time from backend for precise resumption
  5. Backend stores turn_start_times / window_start_times per conversation

Tool System

  1. Fixed GetSkillIndex tool executor fallback lookup (no longer returns "Unknown tool")
  2. Added GetDateTime, GetSkillIndex, HassGetDateTime to official intent whitelist
  3. Removed HassToggle (already natively covered, no whitelist needed)
  4. Runtime tool list cached to avoid repeated construction
  5. Plugin tool ordering made deterministic

Frontend UI

  1. Suppressed .claw-md h1-h6 uppercase bold rendering issue
  2. Unified tool card color to gray (consistent between streaming and post-refresh)
  3. Prevented DOM injection into official default bubble when continuous conversation is off
  4. Fixed claw-ta-card / claw-ta-panel being accidentally overridden by em styles

Agent Resilience & Error Handling

  1. Added transient error keyword library (disconnect / timeout / 502 / 503 / 429, etc.)
  2. Added unavailable error keyword library (not found / not loaded, etc.)
  3. Retains partial existing output after transient errors instead of discarding everything
  4. Added agent error self-healing mechanism (auto reload integration then retry)
  5. Error messages formatted and beautified for user display
  6. Cleans up live_response_parts at conversation end to prevent memory leak

Prompt Architecture Refactor

  1. Split build_base_prompt into stable prefix + dynamic build_turn_context_prompt
  2. Extracted channel detection (voice / IM / mobile / desktop) into standalone function
  3. Dynamic context injected into user message wrapped by <turn-context> XML tag
  4. History summary, config approval, IM approval prompts moved to dynamic segment
  5. Dynamic segment has independent budget cap (8000 chars) to avoid crowding prefix

Conversation History & State

  1. Added mark_turn_in_progress / clear_in_progress real-time markers
  2. Enhanced /stop command: scans all detached tasks and cancels them
  3. /stop cleans up live event buffer and in-progress markers
  4. chat_history_api added display_depth parameter support
  5. Adaptive memory added graph cleanup hooks

Misc

  1. Hook event system added UserPromptSubmit hook for request interception

Full Changelog: v8.7.0...v8.8.0