Skip to content

[Feature] 添加 /compact 命令立刻压缩当前上下文 #6793

@2ndelement

Description

@2ndelement

Description / 描述

添加 /compact 命令,用于立刻压缩当前 conversation context,而非等待达到默认的上下文窗口。

实现 /compact 命令,功能包括:

  1. 立刻分析并压缩当前 conversation:执行 /compact 使用预设上下文压缩提示词调用设置的上下文压缩llm压缩完整对话历史
  2. 支持自定义提示词/compact [自定义提示词] 允许用户指定额外压缩指令(注入到预设上下文压缩提示词中)

Use Case / 使用场景

场景 1:长对话压缩(默认 /compact

经过多轮对话后,context 变得很大:

用户:帮我写一个 Python Web 服务器
Bot:[生成代码]

用户:加上路由
Bot:[添加路由]

用户:加上数据库
Bot:[添加数据库]

... (20+ 轮对话后)

执行 /compact

- **压缩前**:8000 tokens
- **压缩后**:

  User requested a Python Web server with routing and database.
  - Framework: Flask
  - Routes: /home, /login, /register
  - Database: SQLite
  Status: Complete and functional.
  • 效果:节省 90%+ context 空间

场景 2:自定义压缩(/compact [提示词]

需要保留特定格式或信息时:

/compact 保留所有代码片段和文件路径

输出:

User building a Python Web server.
- Key files: app.py, routes.py, models.py
- Routes: /home, /login, /register
- Code:
  app = Flask(__name__)


使用场景

  • Debug 多轮尝试后,保留关键问题和解决方案
  • Code review 多轮反馈后,保留核心改动
  • 系统设计多轮讨论后,保留架构决策

Willing to Submit PR? / 是否愿意提交PR?

  • Yes, I am willing to submit a PR. / 是的,我愿意提交 PR。

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:coreThe bug / feature is about astrbot's core, backendenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions