Skip to main content

Module compact

Module compact 

Source

Re-exports§

pub use super::policy::KEY_TOOL_NAMES as BUILTIN_EXEMPT_TOOLS;

Structs§

AutoCompactParams
auto_compact 的只读参数(messages 作为被操作对象单独传递)
CompactConfig
Context compact 配置
CompactResult
auto_compact 执行结果
InvokedSkill
记录一次技能调用的完整信息(用于 auto_compact 后恢复)

Functions§

auto_compact
Layer 2: auto_compact - 保存 transcript + LLM 摘要 + 替换消息
build_invoked_skills_attachment
构建 auto_compact 后需恢复的技能附件内容 按最近调用时间排序,总预算 COMPACT_SKILL_TOKEN_BUDGET tokens, 每个技能截断到 COMPACT_SKILL_PER_SKILL_TOKEN_BUDGET tokens
estimate_tokens
粗略估算 messages 的 token 数(~4 chars per token)
extract_recent_user_messages
提取最近 N 条 user 消息原文(不限于未被回复的)。 从末尾向前扫描,取最后 count 条 role=user 的消息,保留原始顺序。 用于 auto_compact 场景:压缩后必须保留用户最近的消息原文, 否则 LLM 只能看到摘要而丢失用户的精确措辞和当前任务意图。
is_exempt_tool
判断工具名是否应被豁免(KeyTool + 用户扩展清单)
micro_compact
Layer 1: micro_compact - 替换旧 tool result 为占位符,保留最近 keep_recent 个
new_invoked_skills_map
创建空的 InvokedSkillsMap
record_skill_invocation
记录一次技能调用(由 LoadSkill 工具执行后调用)

Type Aliases§

InvokedSkillsMap
会话内已调用技能的共享状态(Agent 线程写入,auto_compact 读取) 使用 Arc<Mutex> 以便跨线程共享