A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Send a report-back report to the conversation the post came from
Fei2411324d39879d6c
diff --git a/ds-bot/src/host/groups.js b/ds-bot/src/host/groups.jsindex ab8364d8..39058633 100644--- a/ds-bot/src/host/groups.js+++ b/ds-bot/src/host/groups.js@@ -1049,7 +1049,7 @@ export function install(rt) {callIn(round, by, note ?? `${sender.name} mentioned you`, sender.id, { ordered })callIn(round, rest, note, undefined, { ordered })if (extra.reportBack) {- (round.reports ??= []).push({ post: { botId: sender.id, name: sender.name, reportBack: true, ...(extra.sub ? { sub: extra.sub } : {}) }, ids: speakers.map(peer => peer.id), from: round.replies.length })+ (round.reports ??= []).push({ post: { botId: sender.id, name: sender.name, reportBack: true, ...(extra.sub ? { sub: extra.sub } : {}), ...(extra.fromRoomId ? { fromRoomId: extra.fromRoomId } : {}) }, ids: speakers.map(peer => peer.id), from: round.replies.length })}return true}@@ -1289,7 +1289,10 @@ export function install(rt) {].filter(Boolean).join('\n\n')// Replies the poster waited for go on with the work it posted for.const work = post.sub === undefined ? undefined : rt.closeWork(post.sub, `Group "${room.name}"`, text)- await rt.deliver({ toId: post.botId, role: 'report', roomId: room.id, text, ...(work ? { work, replyTo: post.sub } : {}) })+ // The report goes back to the conversation the post was written from: its+ // Session in that group when the post came from one, else the own chat.+ const back = rt.roomOf(post.fromRoomId)?.sessions?.[post.botId]+ await rt.deliver({ toId: post.botId, ...(back ? { sessionId: back } : {}), role: 'report', roomId: room.id, text, ...(work ? { work, replyTo: post.sub } : {}) }).catch(error => rt.warn('ds-bot: group report to %s failed: %s', post.name, error))}diff --git a/ds-bot/src/host/tools.js b/ds-bot/src/host/tools.jsindex c8a3a7e9..a967e5bc 100644--- a/ds-bot/src/host/tools.js+++ b/ds-bot/src/host/tools.js@@ -589,7 +589,9 @@ export function install(rt) {const sub = work === undefined ? undefined : randomUUID()if (sub !== undefined) rt.openWork(sub, { from: self, room: room.id, parent: work })try {- await rt.postToRoom(room, sender, long.text, { ...(reportBack ? { reportBack: true } : {}), ...(member ? { member: true } : {}), ...(sub ? { sub } : {}), ...(long.length ? { length: long.length } : {}) }, long.files)+ // A post that wants the replies names the conversation it was written+ // from, so the report comes back there instead of the own chat.+ await rt.postToRoom(room, sender, long.text, { ...(reportBack ? { reportBack: true, ...callerRoom(exec) } : {}), ...(member ? { member: true } : {}), ...(sub ? { sub } : {}), ...(long.length ? { length: long.length } : {}) }, long.files)} catch (failure) {if (sub !== undefined) rt.dropWork(sub)return `Could not post in "${room.name}": ${failure.message}`diff --git a/ds-bot/src/host/turns.js b/ds-bot/src/host/turns.jsindex a4c375ec..ef91d1a8 100644--- a/ds-bot/src/host/turns.js+++ b/ds-bot/src/host/turns.js@@ -635,6 +635,7 @@ export function install(rt) {...(source.stopped ? { stopped: true } : {}),...(source.done ? { done: true } : {}),...(source.askedBy ? { askedBy: source.askedBy } : {}),+ ...(source.fromRoomId ? { fromRoomId: source.fromRoomId } : {}),// A post written into a running round already carries its log seq, or true// when its event needed none; the relay must not write it again....(source.logged !== undefined ? { logged: source.logged } : {}),diff --git a/ds-bot/test/group-work.test.js b/ds-bot/test/group-work.test.jsindex 3d1c19c4..6a91d877 100644--- a/ds-bot/test/group-work.test.js+++ b/ds-bot/test/group-work.test.js@@ -93,12 +93,12 @@ async function start(t, room, services, extraRooms) {}// The user's message in the group, or a Bot's post the group Session took up, and the// round it starts.- const round = (callId, message) => {- emit('r1', 'user/message', message)+ const round = (callId, message, sessionId = 'r1') => {+ emit(sessionId, 'user/message', message)let resultconst stop = new AbortController()t.after(() => stop.abort())- void tool('group_relay', {}, 'r1', { callId, signal: stop.signal }).then((value) => { result = JSON.parse(value) })+ void tool('group_relay', {}, sessionId, { callId, signal: stop.signal }).then((value) => { result = JSON.parse(value) })const read = () => resultreturn read}@@ -330,6 +330,25 @@ test('replies a post waits for are work handed on: the answer to the Bot that asassert.equal(text(host.agentOf('c').calls[0]), '[Reply from Chief]\nWriter 看过了,没问题。\n\n[Handed back to Chief for this work]\n\nGroup "Ops":\nReplies to your post (oldest first):\nWriter: 文档没问题。')})+// Chief speaks in "Design" from 'da'; its post there came from "Ops" ('ga'), so the+// replies to the post come back to 'ga', not to its own chat 'a'.+test('a report-back post a Bot wrote from another group comes back to that conversation', async (t) => {+ const design = { id: 'r2', name: 'Design', members: ['a', 'b'], mode: 'admin', admin: 'b', named: true, sessions: { a: 'da', b: 'db' }, log: [], seq: 0, seen: {} }+ const host = await start(t, {}, undefined, { r2: design })+ const posted = await host.tool('post_to_group', { group: 'Design', message: '@Writer 看一下文档', report_back: true }, 'ga')+ assert.match(posted, /Posted in "Design"/)+ const post = host.agentOf('r2').calls.shift()+ const done = host.round('d1', { content: post.content, source: post.source }, 'r2')+ await settle(() => host.agentOf('db').calls.length === 1)+ host.begin('db')+ host.finish('db', '文档没问题。')+ await settle(() => done() !== undefined)+ // The report arrives in the "Ops" conversation the post was written from.+ await settle(() => host.agentOf('ga').calls.length === 1)+ assert.equal(host.agentOf('a').calls.length, 0)+ assert.match(text(host.agentOf('ga').calls[0]), /^\[Group chat "Design" · replies to your post\]/)+})+test('a member called while still at earlier work lets the round go on at once', async (t) => {const host = await start(t)host.emit('gb', 'turn/start', { turn: 1 })