返回顶部
a

auto-summarization-loop自动摘要循环

|

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
194
下载量
免费
免费
1
收藏
概述
安装方式
版本历史

auto-summarization-loop

Auto-Summarization Loop - 自动摘要循环

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

核心架构

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

快速使用

1. 引入核心模块

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

2. 初始化配置

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

3. 处理对话

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

检查触发

trigger = manager.checkwatermark(memory.workingmemory)

触发压缩

if trigger != TriggerType.NORMAL: await manager.handle_trigger(trigger, memory)

构建 Prompt

prompt = manager.buildprompt(usermessage, memory)

触发策略

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

摘要生成函数示例

python
async def summarizefn(oldtext: str, oldsummary: str, maxtokens: 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 数组)
├── longtermsummary # 压缩后的摘要
├── user_facts # 用户档案
└── last_update # 最后更新时间

与大模型集成

python
async def chat(sessionid: str, usermessage: str):
session = loadsession(sessionid)

# 检查是否需要压缩
trigger = manager.checkwatermark(session.workingmemory)
if trigger != TriggerType.NORMAL:
await manager.handle_trigger(trigger, session)

# 构建消息
messages = manager.buildprompt(usermessage, session)

# 调用大模型
response = await call_api(messages)

# 保存到工作记忆
session.workingmemory.append({role: user, content: usermessage})
session.working_memory.append({role: assistant, content: response})

savesession(sessionid, session)
return response

Persona 机器人特别提示

生成摘要时确保包含:

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

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

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 auto-summarization-loop-1776276613 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 auto-summarization-loop-1776276613 技能

通过命令行安装

skillhub install auto-summarization-loop-1776276613

下载

⬇ 下载 auto-summarization-loop v1.0.0(免费)

文件大小: 9.62 KB | 发布时间: 2026-4-17 14:09

v1.0.0 最新 2026-4-17 14:09
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.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部