feat(acp): 模型驱动上下文压缩机制(双机制并存 + 可恢复) - #228
Open
aurevian-biz wants to merge 9 commits into
Open
Conversation
- 会话层与任务层按租户阈值注入 advisory nudge(非强制,紧急升级文案) - RealUsageMeter 读取 LLM 真实 input_tokens,缺失时回退估算并标记 estimated - 估算永不参与记账,账本防负数(上游 issue OpenBMB#54 回归防护)
- 会话层 acp_ops 参数安全解析(int/top_k 校验、缺参拒绝、异常防滞留崩溃循环) - 内核新增 to_state/from_state 官方序列化 API,消除会话层/任务层重复实现 - checkpoint 驱逐后 decompress 返回结构化错误而非静默删除摘要块 - usage 观察按 session 作用域 + TTL,消除跨会话污染与陈旧滞留 - 任务层 originals 上限(CAP=5)与帧隔离(任务层 acp_ops 不流入会话层) - ACP→legacy 切换排除已压缩消息,避免二次摘要 - 阈值跨字段校验(min≤max≤emergency)+ 前端空值/范围/顺序校验 - 会话层 acp_ops 通道可见性(prompt 指引 + session nudge 注入任务 payload) - 补 16 个测试(全链路、错误路径、迁移回归)
合并 OpenBMB/StaffDeck main 侧 6 个 commits(b472ac4 Codex/team taskframe orchestration、9cc1840 feat(runtime): configure conversation compaction 等)。 9cc1840 将 legacy 压缩全部参数(context_token_budget/context_compaction_trigger_ratio/context_recent_round_limit/context_long_summary_token_budget/context_medium_summary_token_budget/context_allowed_roles/context_long_summary_prefix/context_medium_summary_prefix)做成 UIConfig 可配置字段,与 ACP 机制选择+阈值字段不撞名,设计共存: - agent_loop.py:保留 _get_context_compression_mode(ACP)与 _get_conversation_context_settings(legacy 参数)双方法;_conversation_context 按 mode 路由,legacy 分支传入 settings - conversation_context.py:build_conversation_context 兼容 settings + compression_mode 双参数(自动合并) - 测试/前端冲突语义合并,双方功能全部保留 验证:test_conversation_context+test_ui_config 47 passed、RuntimeSettingsPage.test.tsx 14 passed、npm build 通过
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
引入 ACP(主动上下文压缩,模型驱动)作为可选压缩机制,与现有固定阈值压缩双机制并存。此前会话层固定 32k token 阈值 + 二次 LLM 摘要、任务层 6 条+40 上限+receipt 降级,均为「固定阈值 + 破坏性丢弃」;ACP 让模型自主决定压缩时机与内容,压缩结果可 checkpoint 恢复、可分层层蒸馏、可词法检索。
参考实现 billion-context-dsh(DeepSeek Harness 插件)深度绑定 DSH 无法直接移植,故将框架无关的 acp-kernel 内核以 Python 重写接入 Harness v2。
主要变更
backend/app/core/acp/,纯标准库):blocks/checkpoint/tiers/nudge/search/status/pricing/engine 10 模块,4 个操作(compress/decompress/search_context/status),AcpLedger 记账防负数(上游 issue feat(general-skills): 通用技能对齐 Agent Skills 官方规范(frontmatter 校验/标准导出/allowed-tools 门控) #54 教训),词干化+CJK bigram 字符 n-gram 检索设计决策
_is_history_summary_message请求层保护不破坏测试
Post-Deploy Monitoring
No additional operational monitoring required — ACP_ENABLED feature flag 默认关闭,legacy 路径零行为变化;启用 ACP 的租户按现有 execution record 观测,nudge/压缩事件在日志与 context_state 中可见。上线后建议观察启用租户的压缩触发率与 decompress/search 找回命中率(go/no-go 验收项)。
Known Residuals