新增: F-15上下文压缩基础(compress_prompt四段式+compress_via_llm+context辅助方法)
This commit is contained in:
@@ -127,3 +127,69 @@ pub(crate) async fn build_system_prompt(state: &AppState, lang: &str) -> String
|
||||
|
||||
prompt
|
||||
}
|
||||
|
||||
/// 上下文压缩 system prompt 模板(F-15 §4.2,纯函数无 IO)。
|
||||
///
|
||||
/// 引导 LLM 把对话压缩为四段式结构化摘要(意图/决策/文件/约束),最大化保留
|
||||
/// 旧消息语义。调用方把返回的 system prompt 放在消息列表首位,后接被压缩的
|
||||
/// active 消息原文(user/assistant/tool)喂给 `provider.complete()`:
|
||||
///
|
||||
/// ```ignore
|
||||
/// let mut msgs = vec![ChatMessage::system(compress_prompt(lang))];
|
||||
/// msgs.extend(active_msgs);
|
||||
/// let resp = provider.complete(CompletionRequest { messages: msgs, .. }).await?;
|
||||
/// ```
|
||||
///
|
||||
/// `lang` 与系统提示词保持一致取值集合("en" 英文,其余一律中文)。
|
||||
//
|
||||
// dead_code:阶段1 基础函数,阶段2 IPC(ai_chat_compress_context)与阶段3 agentic
|
||||
// 自动压缩会经 compress_via_llm 调用本函数。本阶段只暴露 + 单测,不接调用点。
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn compress_prompt(lang: &str) -> &'static str {
|
||||
match lang {
|
||||
"en" => "You are a conversation summarizer. Compress the following conversation \
|
||||
into a structured summary that preserves the essential context for \
|
||||
continuing the work. Output exactly four sections:\n\
|
||||
\n\
|
||||
## Intent\n\
|
||||
The user's core intent and requirements (what they are trying to achieve).\n\
|
||||
\n\
|
||||
## Decisions\n\
|
||||
Key decisions already made (which approach/option was chosen, why alternatives \
|
||||
were rejected).\n\
|
||||
\n\
|
||||
## Files\n\
|
||||
Files modified/created/inspected, with a one-line description of the change in each.\n\
|
||||
\n\
|
||||
## Constraints\n\
|
||||
Important constraints, preferences, or open issues to respect going forward.\n\
|
||||
\n\
|
||||
Rules:\n\
|
||||
- Be concise; prefer bullet points.\n\
|
||||
- Drop small talk and transient pleasantries; keep only technically load-bearing facts.\n\
|
||||
- Preserve file paths, identifiers, and error messages verbatim.\n\
|
||||
- Do NOT invent facts not present in the conversation.\n\
|
||||
- Output the four sections only, no preamble or extra commentary.",
|
||||
_ => "你是对话总结器。请把以下对话压缩为结构化摘要,保留继续推进工作所必需的关键上下文。\
|
||||
严格按以下四段输出:\n\
|
||||
\n\
|
||||
## 意图\n\
|
||||
用户的核心意图和需求(用户想要达成什么)。\n\
|
||||
\n\
|
||||
## 决策\n\
|
||||
已做出的关键决策(选了哪种方案/选项,为何排除其他方案)。\n\
|
||||
\n\
|
||||
## 文件\n\
|
||||
已修改/创建/查看过的文件,每条一行简述其变更内容。\n\
|
||||
\n\
|
||||
## 约束\n\
|
||||
重要约束、偏好或待解决的问题,后续需要继续遵守或留意。\n\
|
||||
\n\
|
||||
要求:\n\
|
||||
- 简洁,优先用要点。\n\
|
||||
- 去掉寒暄、过渡性客套,只保留技术上有价值的事实。\n\
|
||||
- 文件路径、标识符、错误信息等照原样保留。\n\
|
||||
- 不要编造对话中没有的事实。\n\
|
||||
- 只输出上述四段内容,不要前言、解释或额外评论。",
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user