Skip to content

feat: 手动触发 DMN、备忘录回读与记忆列表分页 - #4

Merged
JohnRichard4096 merged 6 commits into
mainfrom
feat/manual-dmn-memo-view
Oct 18, 2026
Merged

JohnRichard4096 merged 6 commits into
mainfrom
feat/manual-dmn-memo-view

Conversation

@AmriaLin

@AmriaLin AmriaLin commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

变更内容

1. /memory dmn — 手动触发潜意识调度

  • SubconsciousRunner.trigger_now():取消已排的 date 任务,取消上一次手动任务,用 create_task 立即跑一轮
  • 任务引用保存在 _manual_task,避免被 GC 回收;stop() 一并取消
  • 命令入口 /memory dmn(别名 run、触发),仅超级用户可用,runner 未启动时返回明确提示

2. /memory memo — 查看备忘录

  • 以合并转发形式发送,直接复用 amrita.utils.send.send_forward_msg
  • 内容按行装箱,单行超过 600 字才按句切开,不从句子中间截断
  • 接口不可用时退回纯文本分段发送,不影响命令完成

3. read_memo / append_memo 工具

备忘录常驻注入系统提示,但 LLM 拿不到原文,也无法只补一条规则。

  • read_memo:只读,返回全文、字数与 empty 标志
  • append_memo:在末尾追加一段,与原文以换行分隔,仍受 memo_max_chars 上限约束;整篇重写仍走 update_memo

4. 记忆列表分页

  • AsyncUserMemory.get_all_notes 增加 limit / offset,透传给 chroma 的 get
  • list_memory 工具新增 offset,limit 默认 10、上限 50,返回 total / has_more / next_offset,不再整库拉取后切片
  • /memory user|group list [页码] 每页 10 条,显示页码并提示下一页

说明

  • 文档只更新了 README(仓库内没有 docs 与 docs/zh)
  • 命令与工具注册在启动时完成,需要重启 bot 生效

Summary by Sourcery

Enable on-demand subconscious runs, memo access and incremental updates, and efficient paginated memory browsing.

New Features:

  • Add privileged commands for manually triggering subconscious scheduling and viewing the current-scope memo.
  • Add memo read and append tools for inspecting and incrementally updating memo content.
  • Add paginated memory listing for chat commands and LLM tools.

Enhancements:

  • Track manually triggered subconscious runs and include their token usage in target-user statistics.
  • Provide fallback text delivery when memo forwarding is unavailable.

Build:

  • Bump the plugin version to 0.7.0.

Documentation:

  • Update the README with the new memo tools and memory commands.

@sourcery-ai

sourcery-ai Bot commented Oct 17, 2026

Copy link
Copy Markdown

Sorry @AmriaLin, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 24 minutes by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Oct 17, 2026

Copy link
Copy Markdown

Reviewer's Guide

本 PR 增加了潜意识调度的超级用户手动触发、备忘录的合并转发与全文回读工具,并将记忆列表从本地切片改为基于 Chroma limit/offset 的分页,同时更新命令和工具文档。

Sequence diagram for manual subconscious scheduling

sequenceDiagram
    actor Superuser
    participant Matcher
    participant Runner as SubconsciousRunner
    participant Scheduler
    participant Task as asyncio.Task

    Superuser->>Matcher: /memory dmn
    Matcher->>Runner: trigger_now()
    Runner->>Scheduler: remove_job(_job_id)
    Runner->>Task: asyncio.create_task(_run())
    Runner-->>Matcher: trigger_now() completes
    Matcher-->>Superuser: 已触发,潜意识将在后台跑一轮
    Task->>Runner: _run()
Loading

Sequence diagram for memo viewing and fallback delivery

sequenceDiagram
    actor User
    participant Matcher
    participant Memo as get_memo()
    participant Bot

    User->>Matcher: /memory memo
    Matcher->>Memo: get_memo(scope_id)
    Memo-->>Matcher: memo content
    Matcher->>Bot: send_group_forward_msg or send_private_forward_msg
    alt forward API fails
        Bot-->>Matcher: exception
        Matcher->>Matcher: send(content)
    end
    Matcher-->>User: memo chunks labeled by segment
Loading

Sequence diagram for paginated memory listing

sequenceDiagram
    actor User
    participant Matcher
    participant Memory as AsyncUserMemory
    participant Chroma

    User->>Matcher: /memory user list page
    Matcher->>Memory: count_user_notes(partition_id)
    Memory->>Chroma: count()
    Chroma-->>Memory: total
    Matcher->>Memory: get_all_notes(limit=10, offset=page offset)
    Memory->>Chroma: get(limit, offset)
    Chroma-->>Memory: page of notes
    Memory-->>Matcher: IDs, documents, metadatas
    Matcher-->>User: page results and next-page hint
Loading

File-Level Changes

Change Details Files
增加潜意识调度的一次性手动触发能力,并通过命令入口限制超级用户访问。
  • 取消已排程任务和正在执行的手动任务后创建后台任务
  • 保存手动任务引用,并在停止 runner 时取消
  • 新增 /memory dmn、run、触发 命令及未启动提示
amrita_plugin_memory/rethinking/runner.py
amrita_plugin_memory/matchers.py
新增备忘录命令展示与 LLM 原文读取能力,并为转发失败提供降级路径。
  • 按 600 字拆分备忘录并按群聊或私聊调用合并转发 API
  • 转发失败时回退为纯文本发送
  • 新增 read_memo 工具返回全文、字数和空内容标志
amrita_plugin_memory/matchers.py
amrita_plugin_memory/tools.py
README.md
将记忆查询改为后端原生分页,并同步扩展工具和用户命令的分页元数据。
  • 为 Chroma 查询透传 limit 和 offset
  • list_memory 增加参数校验、总数及下一页信息,避免整库加载
  • `/memory user
group list` 改为每页 10 条并显示页码和下一页提示

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

- /memory dmn 手动触发潜意识调度(仅超级用户)
- /memory memo 以合并转发查看当前作用域备忘录
- 新增 read_memo 工具,返回备忘录全文与字数
- list_memory 支持 offset 分页,单页上限 50,不再全量拉取
- /memory user|group list 支持页码翻页
@AmriaLin
AmriaLin force-pushed the feat/manual-dmn-memo-view branch from 511e404 to 44e5d57 Compare October 17, 2026 12:22
AmriaLin and others added 5 commits October 17, 2026 12:27
备忘录只支持整篇替换时,补一条规则要重写全文,容易丢内容。append_memo 在末尾追加并以换行分隔,仍受 memo_max_chars 约束。
trigger_now 之前只查 runner 是否存在,配置关掉时提示含糊;改为先读 subconscious.enabled 与 target_user_id。另外本轮 token 原先只进全局 InsightsModel,现同步累加到目标用户元数据,与用户自身对话的统计口径一致。
原先固定 600 字硬切,会把句子和规则从中间劈开。改为按行装箱、超长行按句切,发送直接复用 amrita.utils.send.send_forward_msg,去掉自写的合并转发调用与段号前缀。
nonebot.get_bot 返回内部 Bot 类型,Pyright 在 CI 上会报 reportArgumentType,
这里取到的本来就是 OneBot V11 适配器实例,用 cast 收窄类型即可。
@JohnRichard4096
JohnRichard4096 merged commit e41121c into main Oct 18, 2026
3 checks passed
@JohnRichard4096
JohnRichard4096 deleted the feat/manual-dmn-memo-view branch October 18, 2026 03:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants