A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Document group memory
Fei2411cfe7323746e4
diff --git a/README.md b/README.mdindex b75a2f23..7040e160 100644--- a/README.md+++ b/README.md@@ -66,6 +66,8 @@ DS Bot has group chats. A group chat is a great way to get several bots to workAny bot can hand work to another bot with @. That bot does the work on its own, and the group goes on. While it works, it keeps the group posted, and the group, the sidebar and its own chat show what it is doing. When it is done, it posts the result in the group, and the bot that asked for the work answers. To stop the work, open the group's details.+A group chat has its own memory. What you tell the group stays in the group: its members use it there, and your other chats and the bots outside the group do not see it. You can manage it in the group's details.+### Capabilitiesdiff --git a/README.zh.md b/README.zh.mdindex b19edc14..1854b48c 100644--- a/README.zh.md+++ b/README.zh.md@@ -66,6 +66,8 @@ ds bot 拥有群聊功能。群聊是非常好的多 bot 协作方式,但它任何 bot 都可以用 @ 把活派给另一个 bot。接活的 bot 自己去做,群聊照常进行。它干活时会在群里同步进度,群聊、侧边栏和它自己的聊天里也能看到它在做什么。做完后,它把结果发到群里,由派活的 bot 接着回应。要停下它的工作,打开群聊详情。+群聊有自己的记忆。你在群里交代的事留在群里:群成员在这个群里会用到,你的其他对话和群外的 bot 都看不到。你可以在群聊详情里管理它。+### 能力diff --git a/docs/plans/2026-10-07-roles-and-permissions.md b/docs/plans/2026-10-07-roles-and-permissions.mdindex c097de85..ddebee7c 100644--- a/docs/plans/2026-10-07-roles-and-permissions.md+++ b/docs/plans/2026-10-07-roles-and-permissions.md@@ -21,7 +21,7 @@| 用户 | 全部 | 一切操作,包括设置、取消 Main Bot,设置 Bot 和群的沙盒权限 || Main Bot | 整个团队 | 建 Bot(`create_bot`)、改任何 Bot(`update_bot`)、停止别的 Bot 正在跑的回合(`stop_bot`);建群、改任何群、删群、往任何群发言;写团队记忆,按用户要求读写某个 Bot 的记忆;给任何 Bot 挂、摘能力 || 群管理员 | 自己管的群 | 改自己的群(改名、公告、成员、管理员、回答方式),往自己的群发言,写团队记忆。不能删群,不能改群的工作文件夹 |-| 普通 Bot | 自己 | 改自己的名字、角色、颜色、模型、工作文件夹、指令;给自己挂、摘能力;在群里发言、用 `@` 点名;在私聊里用 `message_bot` 给任何 Bot 发消息(在群里只能叫本群成员,见 [群聊](2026-10-07-group-chat.md)) |+| 普通 Bot | 自己 | 改自己的名字、角色、颜色、模型、工作文件夹、指令;给自己挂、摘能力;在群里发言、用 `@` 点名;在私聊里用 `message_bot` 给任何 Bot 发消息(在群里只能叫本群成员,见 [群聊](2026-10-07-group-chat.md));在群里读写这个群的记忆(见 [上下文与记忆](2026-10-09-context-and-memory.md)) |- 可以有多个 Main Bot,至少保留一个。只有用户能设置或取消 Main Bot。- Main Bot 不能直接删除,要先取消它的 Main Bot 角色。diff --git a/docs/plans/2026-10-09-context-and-memory.md b/docs/plans/2026-10-09-context-and-memory.mdindex 7eab5d94..b9548ecd 100644--- a/docs/plans/2026-10-09-context-and-memory.md+++ b/docs/plans/2026-10-09-context-and-memory.md@@ -1,6 +1,6 @@# 上下文与记忆:对话分段、上下文管家、记忆-- 日期:2026-10-08 定记忆,2026-10-09 定分段和管家+- 日期:2026-10-08 定记忆,2026-10-09 定分段和管家,2026-10-17 加群记忆- 相关:#122(会话换代)、#151(群内共享记忆)、#214(已保存的记忆在已开着的会话里不生效)- 代码:`ds-bot/src/host/steward.js`、`parts.js`、`memory.js`、`chat-index.js`,`read_own_chat` 在 `groups.js`@@ -81,11 +81,12 @@ Bot 是长期的:用户和一个 Bot 聊几周、几个月,上下文一定| 位置 | 内容 ||---|---|| `bots/<botId>/` | 每个 Bot 自己的 `MEMORY.md` 和主题文件 |+| `groups/<群 id>/` | 群记忆:这个群的成员共享,只在这个群里读 || `team/` | 团队记忆,所有 Bot 都读 || `journal.jsonl` | 每一次改动,带改动前后的那一行 || `snapshots/` | 每个 Session 冻结的记忆段 |-| `summaries/` | 记忆面板给每个 Bot 的摘要 |-| `archive/` | 已删除 Bot 的记忆,整份 |+| `summaries/` | 记忆面板给每个 Bot、每个群的摘要 |+| `archive/` | 已删除 Bot 和已删除群的记忆,整份 |**格式**:沿用 [AgentMemoryRepo](https://github.com/AgentMemoryRepo/agentmemoryrepo) 的 Markdown 格式。一行一条,行尾带 `[source: …; added: …]` 这样的元数据;`MEMORY.md` 的 `## Index` 用 `[[主题]]` 链接主题文件。@@ -93,18 +94,21 @@ Bot 是长期的:用户和一个 Bot 聊几周、几个月,上下文一定**谁能做什么**:-| | 自己的记忆 | 团队记忆 | 别的 Bot 的记忆 |-|---|---|---|---|-| 普通 Bot | 读、写 | 读 | 不能读,用 `message_bot` 问对方 |-| 群管理员 | 读、写 | 读、写 | 不能读 |-| Main Bot | 读、写 | 读、写 | 读、写(用户要求时) |-| 用户(记忆面板) | 全部 | 全部 | 全部 |+| | 自己的记忆 | 群记忆 | 团队记忆 | 别的 Bot 的记忆 |+|---|---|---|---|---|+| 普通 Bot | 读、写 | 所在群的:在这个群里读、写 | 读 | 不能读,用 `message_bot` 问对方 |+| 群管理员 | 读、写 | 同上 | 读、写 | 不能读 |+| Main Bot | 读、写 | 同上,不在群里就不能读 | 读、写 | 读、写(用户要求时) |+| 用户(记忆面板) | 全部 | 全部 | 全部 | 全部 |++群里说的话留在群里:群记忆只进这个群成员的群会话,不进他们的私聊,也不进别的群和群外的 Bot。成员被移出群后,就读不到、也写不了这个群的记忆。**怎么写进去**:-- Bot 用 `remember` / `forget`。这两个工具检查谁能写哪里、大小限制,并且拒绝看起来像密钥的内容。-- **记忆整理**:一段对话空闲后,由 Bot 自己的模型读这段对话里新增的内容,像人谈完话后那样保留、修改或删除条目。用户说的话保留得最完整。整理一次只跑一个,所以同一个群的成员能看到彼此的改动。-- 记忆面板:显示 Bot 的模型写的摘要和所有条目,用户可以问、可以直接改。+- Bot 用 `remember` / `forget`。这两个工具检查谁能写哪里、大小限制,并且拒绝看起来像密钥的内容。在私聊里默认写自己的记忆;在群里默认写这个群的记忆,`scope: "own"` 写自己的,`scope: "team"` 写团队的(有权限时)。+- **记忆整理**:一段对话空闲后,由模型读这段对话里新增的内容,像人谈完话后那样保留、修改或删除条目。用户说的话保留得最完整。私聊由 Bot 自己的模型整理,写进它自己的记忆;群聊按群整理一次(不是每个成员各整理一次),用群管理员的模型(没有管理员时用第一个成员的),只写进群记忆,不写个人记忆和团队记忆。整理一次只跑一个。+- 记忆面板:显示模型写的摘要和所有条目,用户可以问、可以直接改。Bot 的面板显示它自己的记忆和团队记忆;群的面板(群详情里的「记忆」)只显示群记忆。+- 删除群时,群记忆整份移到 `archive/`,成员的群会话里冻结的记忆段一起作废。- 三条路走同一个写入路径,一次只写一个,由持有团队的那个进程写。- 历史不用 git:文件原地修改,`journal.jsonl` 记下每次改动替换了什么。@@ -112,7 +116,8 @@ Bot 是长期的:用户和一个 Bot 聊几周、几个月,上下文一定- 每个 Session 第一次渲染时把记忆段冻结下来,之后提示词保持逐字节不变,提供方的前缀缓存才能命中。换到新段,或者做了检查点(检查点本来就会打破缓存),会重新冻结。- 所以一段对话开始之后才保存的条目,不会出现在这段的提示词里。提示词要求 Bot:在回答「不知道」之前先调用 `recall`。`recall` 能查到最新的条目。-- `recall` 不带参数时,列出各处存了什么;带 `query` 时搜索;带 `topic` 时整份读一个主题。默认查自己的和团队的。+- `recall` 不带参数时,列出各处存了什么;带 `query` 时搜索;带 `topic` 时整份读一个主题。默认查自己的和团队的,在群里再加上这个群的。+- 群会话的记忆段把群记忆放在最后,前面和私聊的记忆段一样,尽量多地共用前缀缓存。## 不做什么@@ -128,7 +133,6 @@ Bot 是长期的:用户和一个 Bot 聊几周、几个月,上下文一定- 已经开着的会话看不到之后保存的记忆,只能靠 Bot 调 `recall`(#214 在讨论是否改变这一点)。- 和[愿景](../vision.zh.md)第 3 条的差距:- 愿景要求 Bot 之间的记忆互相只读,现在普通 Bot 不能读别的 Bot 的记忆。- - 愿景要求群聊记忆共享,现在没有群记忆,只有团队记忆(#151)。- 愿景要求目标驱动地完成工作,现在 Bot 会话里关掉了 DSH 的 goal(见 [DSH 让步总账](2026-10-13-dsh-concessions.md))。- 「Bot 开一个全新的会话、保留身份」(相当于 /new)还没有(#122)。@@ -136,3 +140,4 @@ Bot 是长期的:用户和一个 Bot 聊几周、几个月,上下文一定- 2026-10-08:定记忆的格式、存放和「整理不用 git」。- 2026-10-09:分段从「到线就换段」改为「管家判断压缩还是换段」;所有线改为跟着模型走。+- 2026-10-17:加群记忆(#151)。之前群里学到的东西只能进团队记忆,所有 Bot 都读,群外新建的 Bot 也会带上;现在群聊按群整理,只写群记忆。diff --git a/ds-bot/README.md b/ds-bot/README.mdindex 13ac307b..66242eb1 100644--- a/ds-bot/README.md+++ b/ds-bot/README.md@@ -23,7 +23,7 @@ Tested with dsh `0.2.0-rc.2` (Web and Desktop) on Linux.| Member | Speak in the group and `@` another member |- **Long chats stay inside the model's window**: dsh's own compaction never runs on a Bot's Session. When a turn ends past the check line (a share of the model's context window), a small separate model call, the context steward, reads the latest messages of the chat and decides once. If the work is still under way, the chat is condensed in place into a checkpoint: a handoff summary plus your recent messages word for word. If the work has reached a stopping point, the Bot writes a handoff note and continues in a new part. Either way you still see one chat, with no marker. Earlier parts and condensed messages stay searchable in a full-text index (`node:sqlite` FTS5) through `read_own_chat`.-- **Memory**: each Bot keeps notes across all its conversations, and the team shares one more. See [Memory](#memory).+- **Memory**: each Bot keeps notes across all its conversations, each group chat keeps its own for its members, and the team shares one more. See [Memory](#memory).- **Web search**: see [Web search](#web-search).- **Bot browser (dsh Desktop only)**: see [Bot browser](#bot-browser).- **Images**: for a model that cannot read images, a vision model first turns the image into text.@@ -93,22 +93,22 @@ Model providers are set up with dsh's `llm-pi-ai` plugin in `cordis.patch.yml`.A Bot remembers what should last beyond one conversation: your preferences, decisions, corrections and facts it should not ask again. Memory is plain Markdown in the [Agent Memory Repo](https://github.com/AgentMemoryRepo/agentmemoryrepo) format: one entry per line, ending in `[source: …; added: …]`.-After each turn, a memory review reads what is new in the Bot's chat (and in each group, per member) and keeps, updates or removes entries itself, so memory does not depend on the Bot deciding to call `remember`. It keeps only what you say, writes entries in your language, and refuses keys, passwords and ID numbers.+After each turn, a memory review reads what is new in the conversation and keeps, updates or removes entries itself, so memory does not depend on the Bot deciding to call `remember`. A Bot's own chat is reviewed by its model into its own memory; a group chat is reviewed once for the whole group, by the admin's model (or the first member's), into the group memory only. It keeps only what you say, writes entries in your language, and refuses keys, passwords and ID numbers.-- **Two scopes**: each Bot has its own memory, and the team memory is read by every Bot. A Bot writes its own. Main Bots and group admins (of any group) also write the team memory; a Main Bot can read and change another Bot's memory when you ask.-- **Tools**: `remember` saves an entry or replaces one (`replace`), `forget` removes one, and `recall` searches every entry, reads a topic whole, or lists what is saved. The Bot adds the source (a part anchor such as `part 2 #1234`, which `read_own_chat` opens) and the date; a Bot that writes for others is named with `by:`.+- **Three scopes**: each Bot has its own memory; each group chat has a group memory, which its members read in that group only (not in their own chats, and not in other groups); and the team memory is read by every Bot. A Bot writes its own, and any member writes its group's memory from the group. Main Bots and group admins (of any group) also write the team memory; a Main Bot can read and change another Bot's memory when you ask.+- **Tools**: `remember` saves an entry or replaces one (`replace`), `forget` removes one, and `recall` searches every entry, reads a topic whole, or lists what is saved. In a Bot's own chat they use its own memory by default; in a group chat, the group memory (`scope: "own"` for the Bot's own). The Bot adds the source (a part anchor such as `part 2 #1234`, which `read_own_chat` opens, or the group and the time) and the date; a Bot that writes for others is named with `by:`.- **Files**: `MEMORY.md` holds what every conversation needs, and details go in topic files linked from its `## Index` as `[[topic]]`.-- **In the prompt**: both `MEMORY.md` files go into the Bot's system prompt. The section is frozen when a Session starts, so the provider's prompt cache holds; a change shows from the next part or checkpoint, and `recall` finds it at once.+- **In the prompt**: the Bot's own and the team's `MEMORY.md` go into the Bot's system prompt, and in a group Session the group's after them. The section is frozen when a Session starts, so the provider's prompt cache holds; a change shows from the next part or checkpoint, and `recall` finds it at once.- **Fixed sizes**: an entry has at most 300 characters, a `MEMORY.md` 4,000, a topic 16,000, and a scope 40 topics. A save past a limit fails and says how to make room.- **Safety**: memory is data, not instructions. An entry that looks like a key or token is refused, and a Bot is told not to save what a web page, file or tool result asks it to remember.-- **History**: files change in place, and `journal.jsonl` keeps every change with the line before and after. When a Bot is deleted, its memory moves to `archive/`.+- **History**: files change in place, and `journal.jsonl` keeps every change with the line before and after. When a Bot or a group chat is deleted, its memory moves to `archive/`.-**The memory panel**: the Bot's details panel has a Memory row with the entry count; Manage opens the memory panel.+**The memory panel**: the details panel of a Bot, and of a group chat, has a Memory row with the entry count; Manage opens the memory panel. A Bot's panel shows its own memory and the team memory; a group's shows the group memory.-- **Memory summary**: the Bot's model writes a short summary in prose from every entry, in the interface language. It is written again when the entries change, and the ⋯ menu can regenerate it.+- **Memory summary**: a model writes a short summary in prose from every entry, in the interface language: the Bot's, or for a group its admin's. It is written again when the entries change, and the ⋯ menu can regenerate it.- **All entries**: the ⋯ menu lists every entry by scope and topic, with its date and author, and the size of each `MEMORY.md`. Remove takes two clicks.- **Ask or update**: ask what the Bot remembers, or tell it what to add, correct or remove. One model call answers from the entries only, and its changes go through the same checks as the tools.-- A line in the chat ("Memory updated") shows when a Bot changes memory and opens the panel. When memory changes in the background, the Bot's capsule at the top of its chat stretches to say "Memory updated" for a moment; clicking it opens the memory panel.+- A line in the chat ("Memory updated") shows when a Bot changes memory and opens the panel. When memory changes in the background, the capsule at the top of the chat (the Bot's, or the group's) stretches to say "Memory updated" for a moment; clicking it opens the memory panel.A read-only dsh (see [Data and backups](#data-and-backups)) shows memory but cannot change it.@@ -194,7 +194,7 @@ Files in `bot/`:| `state.lock` | The dsh that is using this data (pid and host). It is removed when that dsh exits. || `chat-index.sqlite` | Full-text index of older chat parts (`read_own_chat`); rebuilt if deleted || `usage.sqlite` | Token counts for the Usage page; rebuilt from the Session logs if deleted, losing only the calls outside the logs and the names of deleted Bots |-| `memory/` | Memory (see [Memory](#memory)): `bots/<id>/` and `team/` (`MEMORY.md` and topics), `journal.jsonl` (every change), `snapshots/` (the section each Session froze), `summaries/` (the panel's summary; safe to delete), `reviewed.json` (how far the memory review has read) and `archive/` (deleted Bots) |+| `memory/` | Memory (see [Memory](#memory)): `bots/<id>/`, `groups/<id>/` and `team/` (`MEMORY.md` and topics), `journal.jsonl` (every change), `snapshots/` (the section each Session froze), `summaries/` (the panel's summary; safe to delete), `reviewed.json` (how far the memory review has read) and `archive/` (deleted Bots and group chats) || `ocr.json` | Cache of image text; safe to delete || `workspace` | The team workspace: the working folder of every Bot without one of its own (`config.workspace` changes it) || `secrets.json` | Saved secrets. Treat backups of it like passwords. |