refactor: modularize context pipeline and unify system prompt architecture#48
Merged
Conversation
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.
背景
原有 Context 系统混合了承载上下文收集、Transcript 投影、预算压缩和 Prompt 拼装等职责。同时,System Prompt 分散定义在配置加载、Runtime、Local CLI 和 ContextManager 中,存在来源不唯一、覆盖规则不明确的问题。
主要改动
Context 架构拆分
将 Context 模块整理为四个清晰层次:
collector:收集 Memory、Workspace Profile、User Context 和 Context Provider。transcript:维护合法 tool exchange,保留最近完整调用,并归档旧工具结果。budget:负责优先级、Token 预算、压缩决策、压缩和截断。assembly:负责 Context 格式化和最终 LLM Messages 拼装。同时:
ContextManager作为 Agent Runtime facade。ContextEngine、buildRuntimeContext和重复 formatting/compression 兼容层。ContextDocument、BudgetedContext、TranscriptProjection和 retention/source 类型。统一 System Prompt
新增版本化的
SystemPromptService,并将内置 Prompt 集中到唯一来源。标准 Prompt 包含:
核心 Prompt 不允许被外部整体替换。
配置 API 调整
移除:
runtime.systemPromptrun.input.systemPromptDEFAULT_SYSTEM_PROMPTCLI_MARKDOWN_OUTPUT_INSTRUCTIONS新增:
配置和单次运行只能追加补充指令。旧
systemPrompt配置会被明确拒绝。Context 与 Prompt 解耦
ContextDocument不再包含 System Prompt。可观测性
Context diagnostics 新增:
systemPromptVersionsystemPromptTokenssystemPromptSectionTokensBreaking Changes
runtime.systemPrompt。AgentRunInput.systemPrompt。ContextEngine和buildRuntimeContext导出。验证
已通过: