← 返回 Skills 市场
zhoujj8009

Auto Summarization Loop

作者 zhoujj8009 · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ✓ 安全检测通过
240
总下载
1
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install auto-summarization-loop
功能描述
自动摘要循环:为长对话 AI 角色实现自动上下文管理。用于: (1) 建立多级记忆架构(核心记忆/工作记忆/长期记忆) (2) 实现滑动窗口与双水位线触发策略 (3) 异步后台压缩流程设计 (4) Persona 机器人的结构化摘要输出 适用场景:需要处理长对话、降低 API 成本、避免上下文溢出的 AI 应用
使用说明 (SKILL.md)

Auto-Summarization Loop - 自动摘要循环

为高拟真度 AI 角色实现自动上下文管理的完整方案。

核心架构

┌─────────────────────────────────────────────────────────────┐
│                    Prompt 构建结构                           │
├─────────────────────────────────────────────────────────────┤
│  [System Prompt]  ← 核心记忆 (永不压缩)                       │
│  ─────────────────────────────────────────────────────────  │
│  【历史摘要】  ← 长期记忆 (压缩后的摘要)                        │
│  【用户档案】  ← 结构化用户信息                                │
│  ─────────────────────────────────────────────────────────  │
│  [近期消息]    ← 工作记忆 (保留最近 N 条)                      │
│  ─────────────────────────────────────────────────────────  │
│  [用户新消息]  ← 当前输入                                     │
└─────────────────────────────────────────────────────────────┘

快速使用

1. 引入核心模块

from scripts.memory_manager import (
    AutoSummarizationLoop, 
    MemoryConfig, 
    MemoryBlock,
    TriggerType
)

2. 初始化配置

config = MemoryConfig(
    max_tokens=200000,           # 最大上下文限制
    soft_limit_ratio=0.7,       # 70% 时异步压缩
    hard_limit_ratio=0.9,        # 90% 时同步拦截
    working_messages=20,        # 保留最近 20 条
    summary_max_tokens=2000,    # 摘要最大长度
    summarize_fn=your_summarize_func  # 摘要生成函数
)

3. 处理对话

manager = AutoSummarizationLoop(config)
memory = MemoryBlock(
    core_memory="你是埃隆·马斯克...",
    working_memory=[],
    long_term_summary=""
)

# 检查触发
trigger = manager.check_watermark(memory.working_memory)

# 触发压缩
if trigger != TriggerType.NORMAL:
    await manager.handle_trigger(trigger, memory)

# 构建 Prompt
prompt = manager.build_prompt(user_message, memory)

触发策略

阈值 状态 动作
\x3C 70% 正常 继续
70-90% 软限制 后台异步压缩
> 90% 硬限制 同步拦截压缩

摘要生成函数示例

async def summarize_fn(old_text: str, old_summary: str, max_tokens: int) -> dict:
    prompt = f"""请总结以下对话...

旧摘要:{old_summary}

{old_text}

输出 JSON:{{"summary": "...", "user_facts": {{}}}}"""

    result = await call_model(prompt, model="mini")
    return json.loads(result)

提示词模板详见 references/summary_prompts.md

存储结构

session/
├── core_memory      # System Prompt
├── working_memory   # 最近消息 (JSON 数组)
├── long_term_summary # 压缩后的摘要
├── user_facts       # 用户档案
└── last_update      # 最后更新时间

与大模型集成

async def chat(session_id: str, user_message: str):
    session = load_session(session_id)
    
    # 检查是否需要压缩
    trigger = manager.check_watermark(session.working_memory)
    if trigger != TriggerType.NORMAL:
        await manager.handle_trigger(trigger, session)
    
    # 构建消息
    messages = manager.build_prompt(user_message, session)
    
    # 调用大模型
    response = await call_api(messages)
    
    # 保存到工作记忆
    session.working_memory.append({"role": "user", "content": user_message})
    session.working_memory.append({"role": "assistant", "content": response})
    
    save_session(session_id, session)
    return response

Persona 机器人特别提示

生成摘要时确保包含:

  1. 用户事实档案 - 姓名、地点、职业、偏好
  2. 对话事件线 - 按时间顺序的关键事件
  3. 已达成的共识 - 用户确认过的结论
  4. 待跟进事项 - 未完成的任务

这样大模型在读取摘要时能更精准地把握用户特征。

安全使用建议
This skill appears coherent and self-contained for building summarization/memory management. Before installing: (1) verify how call_api/call_model and summarize_fn are implemented by your host — ensure they do not send data to external endpoints you don't control; (2) decide where session/ data will be stored and whether it may contain sensitive PII (long-term summary may accumulate personal data); (3) replace example persona strings (e.g., impersonating real persons) with acceptable system prompts if needed; (4) if you connect a real LLM provider, only provide credentials to the host runtime (not embedded in the skill) and audit those calls; (5) review the included test script (it adjusts sys.path) before running in production. Overall the skill is internally consistent but you should confirm the host's model-calling and storage implementations before use.
功能分析
Type: OpenClaw Skill Name: auto-summarization-loop Version: 1.0.0 The skill bundle provides a legitimate framework for managing long-context AI conversations through an automated summarization loop. The core logic in `scripts/memory_manager.py` implements a sliding window and watermark-based trigger system to compress conversation history into 'long-term memory' and 'user facts' using user-provided callbacks. No evidence of data exfiltration, malicious execution, or harmful prompt injection was found; the code and documentation (SKILL.md) are entirely consistent with the stated purpose of optimizing API costs and context window usage.
能力评估
Purpose & Capability
Name/description describe multi-level memory and summary-trigger behaviors and the included Python module (memory_manager.py) implements exactly that: token estimation, watermark triggers, async/sync summarization, prompt construction and storage layout. No unrelated capabilities (cloud access, SSH, system-level config) are requested.
Instruction Scope
SKILL.md focuses on building prompts, triggering summaries, and integrating a user-supplied summarize_fn / call_api. It does not instruct reading arbitrary system files or exfiltrating data. It references session storage paths (a session/ structure) and calls like call_api/call_model which are placeholders — the skill expects the host to implement actual model calls.
Install Mechanism
No install spec or external downloads are provided; the skill is instruction-first with two local Python source files. There are no remote URLs, package installs, or archive extractions that would present an installation risk.
Credentials
The skill declares no required environment variables, credentials, or config paths. The code likewise does not read environment secrets or request API keys; model/API integration points are left to the host and therefore do not demand credentials from the skill itself.
Persistence & Privilege
always is false and the skill does not request persistent system-wide privileges. It stores session data in a local session/ structure (documented) and does not modify other skills or global agent settings.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install auto-summarization-loop
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /auto-summarization-loop 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
Auto-Summarization Loop v1.0.0 - Implements automatic context management for long AI conversations with a multi-level memory structure (core, working, long-term). - Supports sliding window and dual watermark strategies for triggering asynchronous or synchronous compression. - Provides structured persona summary output including user facts and key events. - Designed for AI apps to reduce API costs and avoid context overflow. - Includes example code for integration and summary generation.
元数据
Slug auto-summarization-loop
版本 1.0.0
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 1
常见问题

Auto Summarization Loop 是什么?

自动摘要循环:为长对话 AI 角色实现自动上下文管理。用于: (1) 建立多级记忆架构(核心记忆/工作记忆/长期记忆) (2) 实现滑动窗口与双水位线触发策略 (3) 异步后台压缩流程设计 (4) Persona 机器人的结构化摘要输出 适用场景:需要处理长对话、降低 API 成本、避免上下文溢出的 AI 应用. 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 240 次。

如何安装 Auto Summarization Loop?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install auto-summarization-loop」即可一键安装,无需额外配置。

Auto Summarization Loop 是免费的吗?

是的,Auto Summarization Loop 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

Auto Summarization Loop 支持哪些平台?

Auto Summarization Loop 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 Auto Summarization Loop?

由 zhoujj8009(@zhoujj8009)开发并维护,当前版本 v1.0.0。

💬 留言讨论