Skip to content

A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.

Keep a group's work in the group (#165)

Fei2411c7c0d9295bc6
diff --git a/docs/plans/2026-10-07-group-chat.md b/docs/plans/2026-10-07-group-chat.md
index 3edaf541..a0001ed0 100644
--- a/docs/plans/2026-10-07-group-chat.md
+++ b/docs/plans/2026-10-07-group-chat.md
@@ -55,7 +55,13 @@
- 用户新建群且没有附第一句话时,管理员先发一句问候,问这个群要做什么。Main Bot 用工具建群时不发。
- 群公告(最多 2000 字)放进每次发言的提示里。成员最多 12 个,群名不能重复(最长 60 字),没起名的群显示成员名。
- Main Bot 能看到所有群;其他 Bot 只能看到自己所在的群。
-- `message_bot` 发来的消息只进 Bot 自己的私聊;它在群里的工作不受影响。
+- 私聊里用 `message_bot` 发的消息只进对方的私聊;对方在群里的工作不受影响。
+
+### 一件活只有一个地点
+
+- 群里的活只留在群里。在群里用 `message_bot` 叫本群成员,和在回复里写 `@名字` 一样:这句话发到群里,对方在群里做,结果由派活的 Bot 接话,对方的私聊收不到。
+- 在群里用 `message_bot` 叫群外的 Bot,工具拒绝,并提示先把它拉进群(Main Bot 和管理员可以用 `update_group` 加人,群里看得到这一步)。
+- 私聊里用 `post_to_group` 点名了某个 Bot,同一回合再用 `message_bot` 给它派活,工具拒绝:同一件活只走一条路。
## 不做什么
@@ -76,3 +82,4 @@
- 2026-10-12:群里的审批、状态胶囊、超时只算无动静的时间、迟到回复补发(PR #79)。
- 2026-10-13:全团队 Bot 消息上限 40 条(#129)。
- 2026-10-14:干活中的进度发到群里,结果由派活的 Bot 接话(PR #175);群的统一权限(PR #180)。
+- 2026-10-16:群里的活只留在群里:群里的 `message_bot` 只叫本群成员,等同 `@名字`(#165)。
diff --git a/docs/plans/2026-10-07-roles-and-permissions.md b/docs/plans/2026-10-07-roles-and-permissions.md
index d943d1c4..c097de85 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 发消息 |
+| 普通 Bot | 自己 | 改自己的名字、角色、颜色、模型、工作文件夹、指令;给自己挂、摘能力;在群里发言、用 `@` 点名;在私聊里用 `message_bot` 给任何 Bot 发消息(在群里只能叫本群成员,见 [群聊](2026-10-07-group-chat.md)) |
- 可以有多个 Main Bot,至少保留一个。只有用户能设置或取消 Main Bot。
- Main Bot 不能直接删除,要先取消它的 Main Bot 角色。
diff --git a/ds-bot/src/host/prompt.js b/ds-bot/src/host/prompt.js
index 7dc30735..3ab4b475 100644
--- a/ds-bot/src/host/prompt.js
+++ b/ds-bot/src/host/prompt.js
@@ -16,7 +16,7 @@ const TEAM_RULES = [
'- In a group chat, the group sees what you write while you work, not only your final reply. For work that takes more than a quick look, start with one short sentence on what you will do, in the same response as your first tool call. After that, write only when you find something the group should know or finish a part of the work, in a sentence or two, not at every step. End with the result. Simple answers need no updates.',
'- Offer choices with ask_user (a tap-to-answer card) instead of long option lists in text. Calling it ends your turn at once, so write everything you want to say before the call, in the same reply. The answer arrives as the user\'s next message.',
'- update_bot changes your own settings: name, role label, color, model, working folder, or instructions. Leave out bot to change yourself. Use it when the user asks you to change how you are set up, for example to work in a project folder (work_dir, a full path). Only a Main Bot can change other Bots; when another Bot needs changing, ask a Main Bot.',
- '- You may be in group chats with the user and other Bots. You speak in each group from a separate conversation of yours, apart from your own chat with the user. There your turn arrives as a "[Group chat …]" message that shows the speaking order, and your reply is posted to the group. When someone there asks you to do something, do the work in that turn: the group goes on without waiting and sees what you write as you go. Any member can hand work to another with @Name, and the one that asked answers the result. In a group, read_own_chat shows your own chat (the group sees that you looked; share only what the group needs). In your own chat, read_group_chat shows what was said in a group. A group may have an admin, who steers it: the admin can call members with @Name, change the group with update_group, and start a new discussion there with post_to_group.',
+ '- You may be in group chats with the user and other Bots. You speak in each group from a separate conversation of yours, apart from your own chat with the user. There your turn arrives as a "[Group chat …]" message that shows the speaking order, and your reply is posted to the group. When someone there asks you to do something, do the work in that turn: the group goes on without waiting and sees what you write as you go. Any member can hand work to another with @Name, and the one that asked answers the result. Work for a group stays in it: there message_bot reaches only members of that group, as @Name does. In a group, read_own_chat shows your own chat (the group sees that you looked; share only what the group needs). In your own chat, read_group_chat shows what was said in a group. A group may have an admin, who steers it: the admin can call members with @Name, change the group with update_group, and start a new discussion there with post_to_group.',
'- When you need a key, token, or password, call request_secret: the user types it into a secure card and you never see it. Never ask the user to paste one into the chat. Use it through its environment variable ($DSH_SECRET_<NAME> in bash, $env:DSH_SECRET_<NAME> in PowerShell) and never print it. list_secrets shows which keys exist.',
'- web_search results say which search backend answered. If web_search fails, never guess URLs or present pages you remember as search results: use a browser tool if you have one, otherwise tell the user that search is unavailable and the reason it gave.',
'- Your conversations are long-lived. When one grows long, either its older messages are condensed in place into a summary you wrote (a "[Checkpoint N]" message), or it moves on to a fresh part that opens with a handoff note you wrote and your latest messages (a "[Handoff · part N]" message). What leaves your working context stays saved. When you need the exact earlier wording or a detail the summary or note does not show in full (a full path, a figure, every item of a complete list or a final summary), call read_own_chat with words to look for, or with part N to read the note that closed an earlier part; never fill such a detail in from memory. Each line it returns starts with an anchor such as [part 2 #1234 · 10-08 14:22]; pass the anchor as around to read what was said around it.',
@@ -28,7 +28,7 @@ const MAIN_RULES = [
'- You run the user\'s Bot team: you decide who does what, create new Bots, and report back.',
'- When the user wants something that deserves its own ongoing specialist, call create_bot (check list_bots first to avoid duplicates). Give it a short name, a two-to-four character role label, and concrete instructions.',
'- After creating a Bot, tell the user in one line that it is ready, using its exact name.',
- '- Route work to the right Bot with message_bot, then tell the user what you asked and that you will report back.',
+ '- Route work to the right Bot: one Bot\'s task with message_bot, a group\'s task with post_to_group (or @Name when you speak in that group). Send each task one way only, then tell the user what you asked and that you will report back.',
'- If a Bot does not heed your message and must not finish what it is doing, stop_bot ends its turn at once and tells it why; the reply comes back to you.',
'- Every Bot runs on one model of its own (list_bots shows it). Pass model to create_bot or update_bot only when the user names one; list_models gives the provider/model refs.',
'- Use update_bot to rename a Bot, change its role, color, model, working folder, or instructions when the user asks.',
diff --git a/ds-bot/src/host/tools.js b/ds-bot/src/host/tools.js
index 8a6bddf3..c3152a3e 100644
--- a/ds-bot/src/host/tools.js
+++ b/ds-bot/src/host/tools.js
@@ -4,6 +4,7 @@ import { randomUUID } from 'node:crypto'
import { defineTool } from '@deepseek-ai/dsh-tools'
import { COLORS, EXTRA_COLORS, MAX_HOPS, MAX_UNATTENDED_MESSAGES, MAX_UNREAD_REQUESTS, ROOM_BOT_ROUNDS, ROOM_MODES, SOURCE_KIND } from './constants.js'
import { unquote } from './text.js'
+import { mentionSpans } from '../shared/mentions.js'
export const output = { schema: { type: 'string' }, render: (_args, value) => [{ type: 'text', text: String(value) }] }
export const GROUP_REF = { type: 'string', required: true, description: 'Exact group chat name from list_bots' }
@@ -100,9 +101,26 @@ export function install(rt) {
refuse(`Not sent: the team has sent ${MAX_UNATTENDED_MESSAGES} Bot messages since the user last wrote. Stop messaging other Bots and tell the user what is still open.`)
}
+ // Work for a group stays in it: from a group Session, message_bot calls a member there
+ // exactly as an "@Name" line would, and never reaches a Bot outside the group.
+ const callInGroup = async (exec, room, sender, target, message) => {
+ if (!room.members.includes(target.id)) {
+ const add = rt.isMain(sender.id) || rt.isAdminOf(room, sender.id) ? ', or add it yourself with update_group first' : ''
+ refuse(`Not sent: ${target.name} is not in "${room.name}", and work for this group stays in it. Ask the user to add ${target.name} to the group${add}.`)
+ }
+ const call = `@${target.name}`
+ await rt.roomStepText(exec.agent.id, rt.live.get(exec.agent.id)?.info, message.startsWith(call) ? message : `${call} ${message}`, false)
+ return `Called ${target.name} in "${room.name}" with your message, as writing "${call}" there does: it works on it in the group, and you answer its result there. Nothing went to its own chat.`
+ }
+
+ // The Bots each Session's post_to_group called by name in its current turn, so that
+ // turn does not also send them the same work in their own chats.
+ const calledInPosts = new Map()
+ const turnOf = exec => rt.live.get(exec.agent?.id)?.turn
+
ctx.tools.register(defineTool({
name: 'message_bot',
- description: 'Send a message to another Bot on the team. If that Bot is working, it reads your message at its next step and can change course, then answers once that work is done; if it is idle, it starts on it right away. Its reply arrives later as a new message to you; with reply_to "user" it answers the user in its own chat instead.',
+ description: 'Send a message to another Bot on the team. If that Bot is working, it reads your message at its next step and can change course, then answers once that work is done; if it is idle, it starts on it right away. Its reply arrives later as a new message to you; with reply_to "user" it answers the user in its own chat instead. In a group chat it reaches only members of that group, as writing "@Name" there does.',
parameters: {
to: { type: 'string', required: true, description: 'Exact Bot name from list_bots' },
message: { type: 'string', required: true, description: 'Self-contained message; the other Bot cannot see this conversation' },
@@ -125,6 +143,11 @@ export function install(rt) {
const target = rt.findBot(args.to)
if (target === undefined) return `No Bot named ${args.to}. Team: ${Object.values(state.bots).map(bot => bot.name).join(', ')}`
if (target.id === sender.id) return 'You cannot message yourself.'
+ const room = rt.roomOf(rt.groupOwners.get(exec.agent?.id)?.roomId)
+ if (room !== undefined) return callInGroup(exec, room, sender, target, String(args.message ?? '').trim())
+ const posted = calledInPosts.get(exec.agent?.id)
+ const postedIn = posted !== undefined && posted.turn === turnOf(exec) ? posted.calls.get(target.id) : undefined
+ if (postedIn !== undefined) refuse(`Not sent: you called ${target.name} in "${postedIn}" in this turn, and it works on that there. Send each task one way only; to add to it, post in that group.`)
const hop = nextHop(exec)
if (hop > MAX_HOPS) return CHAIN_TOO_LONG
checkUnattended()
@@ -136,7 +159,7 @@ export function install(rt) {
const toUser = args.reply_to === 'user'
const working = rt.live.get(chat)?.turn !== undefined
const steer = args.when !== 'queue' && !toUser
- await rt.deliver({ fromId: sender.id, toId: target.id, text: args.message, role: 'request', hop, steer, ...(toUser ? { audience: 'user' } : callerRoom(exec)) })
+ await rt.deliver({ fromId: sender.id, toId: target.id, text: args.message, role: 'request', hop, steer, ...(toUser ? { audience: 'user' } : {}) })
rt.unattended.sent += 1
const sent = toUser
? `Delivered to ${target.name}. It will answer the user in its own chat; nothing comes back to you, so point the user to ${target.name}'s chat instead of relaying.`
@@ -430,6 +453,14 @@ export function install(rt) {
} catch (failure) {
return `Could not post in "${room.name}": ${failure.message}`
}
+ const named = mentionSpans(text, room.members.map(rt.botOf).filter(Boolean)).flatMap(span => (span.bot ? [span.bot.id] : []))
+ if (named.length > 0) {
+ const turn = turnOf(exec)
+ const earlier = calledInPosts.get(exec.agent?.id)
+ const calls = new Map(earlier !== undefined && earlier.turn === turn ? earlier.calls : [])
+ for (const id of named) calls.set(id, room.name)
+ calledInPosts.set(exec.agent?.id, { turn, calls })
+ }
rt.unattended.sent += 1
return `Posted in "${room.name}". Members reply there, where the user reads them${reportBack ? '; their replies also come back to you as a new message when the round ends' : ', and nothing comes back to you'}.`
},
diff --git a/ds-bot/test/group-work.test.js b/ds-bot/test/group-work.test.js
index 66f9267a..ce313757 100644
--- a/ds-bot/test/group-work.test.js
+++ b/ds-bot/test/group-work.test.js
@@ -148,7 +148,70 @@ test('work past the grace lets the round go on, and the member that asked answer
assert.deepEqual(host.agentOf('gc').calls, [])
})
-test('a Bot\'s post keeps its hop through the round, the member\'s late reply and its own messages', async (t) => {
+// 公开#165: asked in a group to hand out work, Chief sent it with message_bot. Members
+// did it in their own chats, apart from the group (Bots outside the group too), and
+// again when called in the group.
+test('message_bot from a group to one of its members calls it there, as "@Name" would', async (t) => {
+ const host = await start(t)
+ const first = host.round('c1', host.say('@Chief 安排一下文档'))
+ await settle(() => host.agentOf('ga').calls.length === 1)
+ host.begin('ga')
+ const sent = await host.tool('message_bot', { to: 'Writer', message: '把文档整理好' }, 'ga')
+ assert.match(sent, /^Called Writer in "Ops"/)
+ host.finish('ga', '安排好了。')
+ await settle(() => host.agentOf('gb').calls.length === 1)
+ const called = host.begin('gb')
+ assert.equal(called.source.askedBy, 'a')
+ assert.match(text(called), /Chief: @Writer 把文档整理好/)
+ host.finish('gb', '整理好了。')
+ await settle(() => first() !== undefined)
+ assert.deepEqual(kinds(first()), [['message', 'Chief'], ['message', 'Chief'], ['message', 'Writer']])
+ assert.deepEqual([host.agentOf('b').calls, host.agentOf('gc').calls], [[], []])
+})
+
+test('message_bot from a member the round moved on from calls the other member in a round of its own', async (t) => {
+ t.mock.timers.enable({ apis: ['setTimeout'] })
+ const host = await start(t)
+ const first = host.round('c1', host.say('@Writer 整理文档'))
+ await settle(() => host.agentOf('gb').calls.length === 1)
+ host.begin('gb')
+ host.emit('gb', 'tool/call', { callId: 'k1', name: 'write', arguments: '{}' })
+ t.mock.timers.tick(ROOM_WORK_GRACE_MS)
+ await settle(() => first() !== undefined)
+ await host.tool('message_bot', { to: 'Tester', message: '帮我测一下' }, 'gb')
+ await settle(() => host.agentOf('r1').calls.length === 1)
+ const post = host.takePost()
+ assert.deepEqual([post.source.progress, text(post)], [true, '[Group post from Writer]\n@Tester 帮我测一下'])
+ const second = host.round('c2', post)
+ await settle(() => host.agentOf('gc').calls.length === 1)
+ assert.equal(host.begin('gc').source.askedBy, 'b')
+ host.finish('gc', '测过了。')
+ await settle(() => second() !== undefined)
+ assert.deepEqual(host.agentOf('c').calls, [])
+})
+
+test('message_bot from a group does not reach a Bot outside it', async (t) => {
+ const host = await start(t, { members: ['a', 'b'], sessions: { a: 'ga', b: 'gb' } })
+ await assert.rejects(host.tool('message_bot', { to: 'Tester', message: '帮忙测一下' }, 'ga'),
+ { message: 'Not sent: Tester is not in "Ops", and work for this group stays in it. Ask the user to add Tester to the group, or add it yourself with update_group first.' })
+ await assert.rejects(host.tool('message_bot', { to: 'Tester', message: '帮忙测一下' }, 'gb'),
+ { message: 'Not sent: Tester is not in "Ops", and work for this group stays in it. Ask the user to add Tester to the group.' })
+ assert.deepEqual([host.agentOf('c').calls, host.agentOf('r1').calls], [[], []])
+})
+
+test('a Bot a post called by name gets no message_bot in that turn', async (t) => {
+ const host = await start(t)
+ host.emit('a', 'turn/start', { turn: 1 })
+ await host.tool('post_to_group', { group: 'Ops', message: '@Writer 整理文档' }, 'a')
+ await assert.rejects(host.tool('message_bot', { to: 'Writer', message: '整理文档' }, 'a'), /^Error: Not sent: you called Writer in "Ops" in this turn/)
+ assert.deepEqual(host.agentOf('b').calls, [])
+ assert.match(await host.tool('message_bot', { to: 'Tester', message: '准备测试' }, 'a'), /^Delivered to Tester/)
+ host.emit('a', 'turn/end', { turn: 1, reason: { kind: 'completed' } })
+ host.emit('a', 'turn/start', { turn: 2 })
+ assert.match(await host.tool('message_bot', { to: 'Writer', message: '进度如何?' }, 'a'), /^Delivered to Writer/)
+})
+
+test('a Bot\'s post keeps its hop through the round, the members it calls and the member\'s late reply', async (t) => {
t.mock.timers.enable({ apis: ['setTimeout'] })
const host = await start(t)
host.emit('a', 'turn/start', { turn: 1 })
@@ -161,9 +224,11 @@ test('a Bot\'s post keeps its hop through the round, the member\'s late reply an
await settle(() => host.agentOf('gb').calls.length === 1)
assert.equal(host.begin('gb').source.hop, 3)
await host.tool('message_bot', { to: 'Tester', message: '帮我确认一下' }, 'gb')
- assert.equal(host.agentOf('c').calls.at(-1).source.hop, 4)
host.emit('gb', 'tool/call', { callId: 'k1', name: 'pwsh', arguments: '{}' })
t.mock.timers.tick(ROOM_WORK_GRACE_MS)
+ await settle(() => host.agentOf('gc').calls.length === 1)
+ assert.equal(host.begin('gc').source.hop, 3)
+ host.finish('gc', '[PASS]')
await settle(() => first() !== undefined)
host.emit('gb', 'tool/result', { callId: 'k1' })
@@ -274,11 +339,13 @@ test('the late round limit makes a late post quiet', async (t) => {
assert.equal(host.takePost().source.quiet, true)
})
+// Such a message was sent before message_bot from a group stayed in that group.
test('a reply to a message a group Session sent comes back there, and its turn posts in the group', async (t) => {
const host = await start(t)
- await host.tool('message_bot', { to: 'Tester', message: '能跑通吗?' }, 'gb')
- assert.equal(host.begin('c').source.senderRoomId, 'r1')
- host.finish('c', 'ok')
+ host.emit('c', 'turn/start', { turn: 1 })
+ host.emit('c', 'user/message', { content: [{ type: 'text', text: '[Message from Writer]\n能跑通吗?' }], source: { kind: 'bot', role: 'request', exchangeId: 'x1', senderName: 'Writer', senderSessionId: 'b', senderRoomId: 'r1', hop: 1 } })
+ host.emit('c', 'assistant/message', { message: { content: [{ type: 'text', text: 'ok' }] } })
+ host.emit('c', 'turn/end', { turn: 1, reason: { kind: 'completed' } })
await settle(() => host.agentOf('gb').calls.length === 1)
assert.deepEqual(host.agentOf('b').calls, [])
assert.match(text(host.begin('gb')), /^\[Reply from Tester\]\nok/)