[建议 / Feature] 上下文压缩可编排:Agent 可调用 + 节点边界触发 + 锚点内容保护
Nobody has claimed this yet.
- Dominant language
- No language data
- Stars
- 22
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Description
提交前确认 · Pre-submission checklist
- 我已搜索过现有 issue,确认这不是重复 / I searched existing issues and confirmed this isn't a duplicate.
- 我已阅读 CONTRIBUTING.md / I've read CONTRIBUTING.md.
已搜索并引用相关存量 issue:#114(auto-compact 阈值硬编码)、#161(/compact 触发时机)、#117(compact 后子 Goal 丢失)、#323(Dynamic Context Runtime)。本 issue 的差异化诉求:把「压缩」变成可编排的动作——能由 Agent/工作流在确定性时机主动触发,并在压缩时按规则保护锚点内容不被剔除。
问题类别 · Category
对话 / Agent 交互 · Agent chat(上下文压缩机制的编排能力)
涉及的 Agent 框架 · Agent framework
ZCode Agent(自研)
严重程度 · Severity
影响体验 · Major(功能可用但体验受损 / works but degraded)
使用场景 · Use case
我在 ZCode 上运行多节点开发工作流(dev-workflow DAG:需求 → PRD → 技术方案 → 编码 → 测试 → 验收 → 归档,单次会话连续执行 5~15 个节点)。每个节点之间要传递「下一节点开工资料包」(下一节点任务的完整上下文),但长文档、工具输出、节点记录在长会话中快速挤满上下文。
现状只有两条路,都不够:
- 手动
/compact:时机依赖人盯梢;且客户端会限制触发时机(参考 #161,40%~68% 之间不可触发,也不给提示)。 - 自动 compact:触发阈值硬编码 95%(参考 #114),时机不可配置、不可预知;若压缩发生在节点执行中途,摘要里没有下一节点所需的信息,续跑质量明显下降。
核心痛点:压缩无法成为工作流编排的一环。我希望在「节点收尾」这一确定性时刻主动压缩,让压缩后的摘要恰好服务于下一个节点,而不是由系统在任意时刻被动打断。
建议方案 · Proposal
- Agent 可调用的压缩工具:暴露一个 agent tool(如
session_compact),参数支持:保留最近 N tokens / 自定义摘要指令 / 指定锚定文本块。流程 skill 即可在节点收尾时主动调用——压缩变成工作流的一部分,而不是外部事件。 - 保留锚点(keep-anchors):压缩时按规则保护指定内容永不剔除(如 AGENTS.md 等项目提示词文件、任务清单)。我们项目有硬性约束:项目提示词一旦被读取,任何压缩都不得移除——否则工作流规则会在长任务中途「悄然消失」。
- 触发可配置:
autoCompactTokenLimit按模型/会话配置(同款诉求已在 #114 提出),并支持工作流级触发回调(如节点边界compact.afterNode)。 - 可消费的压缩结果:压缩完成后留下可持久化的摘要文件/接口,方便跨会话续跑时恢复上下文。
预期价值 · Expected value
- 长流程任务(多节点 DAG / 长会话)可稳定连续运行,减少人工盯梢压缩。
- 节点边界压缩后摘要 = 下一节点开工资料包,续跑质量有确定性。
- AGENTS.md 等关键规则永不因压缩丢失(对工作流平台类用户是刚需)。
- 压缩结果可持久化,跨会话续跑不再「重新开讲」。
你认为的优先级 · Your perceived priority
P1(仅供参考,最终由团队评估 / For reference only; final decision is the team's)
你使用的 ZCode 版本 / 环境 · ZCode version / environment
ZCode Desktop 3.8.1(3.8.1.5310),macOS arm64
补充材料 · Additional context
关联 issue:#114 #161 #117 #323。若 #114(阈值可配置)先落地,本 issue 剩余诉求为「Agent/工作流主动触发 + 锚点保护 + 摘要持久化」。
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No repository files, tests, or entry points are named. Start by reviewing related issues #114, #161, #117, and #323, then locate the existing compaction flow and workflow integration points; done should cover agent-triggered compaction, configurable node-boundary triggers, protected anchors, and a consumable persisted result.
Written by the indexing model from the issue text.
Assessment
- Domain
- ai, developer-experience
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100