Skip to content

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

Tell a Bot when its messages sit unread, and stop piling them up

Fei2411543fddf215f2
diff --git a/CHANGELOG.md b/CHANGELOG.md
index be0739b5..0260a7b8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,10 @@ All notable changes to DS Bot are listed here. The format follows [Keep a Change
## [Unreleased]
+### Fixed
+
+- A Bot that messaged a Bot stuck on earlier work was told "Delivered" every time, with no sign that nothing was read. It is now told how many earlier messages wait unread and when the other Bot waits for your approval, and after 10 unread messages `message_bot` fails and tells it to report the stuck Bot to you.
+
## [0.1.4] - 2026-10-13
### Added
diff --git a/ds-bot/src/host/constants.js b/ds-bot/src/host/constants.js
index 7cf5d1bf..42cff582 100644
--- a/ds-bot/src/host/constants.js
+++ b/ds-bot/src/host/constants.js
@@ -21,6 +21,9 @@ export const OCR_CACHE_MAX = 500
export const MAX_AVATAR_IMAGE = 160_000
export const ROUTE = '/api/bot'
export const MAX_HOPS = 6
+// Bot requests a Bot's own chat may hold unread; past this the Bot is most likely
+// stuck, and more messages only pile up behind it.
+export const MAX_UNREAD_REQUESTS = 10
export const MAX_EXCHANGES = 600
export const ROOM_REPLY_TIMEOUT_MS = 240_000
export const SOURCE_KIND = 'bot'
diff --git a/ds-bot/src/host/tools.js b/ds-bot/src/host/tools.js
index ecb47972..500c615f 100644
--- a/ds-bot/src/host/tools.js
+++ b/ds-bot/src/host/tools.js
@@ -2,7 +2,7 @@
// question card. Group rounds and reading chats are in groups.js.
import { randomUUID } from 'node:crypto'
import { defineTool } from '@deepseek-ai/dsh-tools'
-import { COLORS, EXTRA_COLORS, MAX_HOPS, ROOM_BOT_ROUNDS, ROOM_MODES } from './constants.js'
+import { COLORS, EXTRA_COLORS, MAX_HOPS, MAX_UNREAD_REQUESTS, ROOM_BOT_ROUNDS, ROOM_MODES, SOURCE_KIND } from './constants.js'
import { unquote } from './text.js'
export const output = { schema: { type: 'string' }, render: (_args, value) => [{ type: 'text', text: String(value) }] }
@@ -72,6 +72,12 @@ export function install(rt) {
const room = rt.roomOf(rt.groupOwners.get(sessionId)?.roomId)
return room ? `group "${room.name}"` : 'its own chat'
}
+ // Delivered but not read yet: no step or turn has taken them out of the inbox.
+ const unreadRequests = agent => [...(agent.inbox?.nextStep ?? []), ...(agent.inbox?.nextTurn ?? [])]
+ .filter(message => message.source?.kind === SOURCE_KIND && message.source.role === 'request').length
+
+ // A tool that throws shows as failed in the chat, instead of as sent or stopped.
+ const refuse = (message) => { throw new Error(message) }
ctx.tools.register(defineTool({
name: 'message_bot',
@@ -101,8 +107,13 @@ export function install(rt) {
const turn = rt.live.get(exec.agent?.id)
const hop = Math.max(turn?.info?.hop ?? 0, ...(turn?.joined ?? []).map(joined => joined.info?.hop ?? 0))
if (hop >= MAX_HOPS) return 'This chain of Bot messages is already long. Stop here and report to the user instead.'
+ const chat = rt.chatOf(target.id)
+ const unread = unreadRequests(await rt.resolveAgent(chat))
+ if (unread >= MAX_UNREAD_REQUESTS) {
+ refuse(`Not sent: ${target.name} has not read the last ${unread} messages from Bots yet, so it is most likely stuck, for example waiting for the user. Do not send it more; tell the user that ${target.name} is not responding.`)
+ }
const toUser = args.reply_to === 'user'
- const working = rt.live.get(rt.chatOf(target.id))?.turn !== undefined
+ 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)) })
const sent = toUser
@@ -112,18 +123,20 @@ export function install(rt) {
: working
? `Queued for ${target.name}: it reads your message after its current work. Its reply will arrive later as a new message; do not wait for it.`
: `Delivered to ${target.name}. Its reply will arrive later as a new message; do not wait for it.`
+ // "Delivered" only means it is in the inbox; say so when it may sit there a while.
+ const notes = [
+ rt.waitsForApproval?.(chat) ? `${target.name} is waiting for the user's approval, so it reads your message only after the user answers.` : '',
+ unread > 0 ? `${target.name} has not read ${unread === 1 ? 'an earlier message' : `${unread} earlier messages`} from Bots yet.` : '',
+ ].filter(Boolean)
+ const status = notes.length === 0 ? sent : `${sent} ${notes.join(' ')}`
// Messages reach a Bot's own chat only; work in a group goes on without them.
- const groups = activeSessions(target.id).running.filter(sessionId => sessionId !== rt.chatOf(target.id))
- if (groups.length === 0) return sent
+ const groups = activeSessions(target.id).running.filter(sessionId => sessionId !== chat)
+ if (groups.length === 0) return status
const stop = rt.isMain(sender.id) ? ' If it must not go on there, use stop_bot.' : ''
- return `${sent} ${target.name} is also working in ${groups.map(whereOf).join(' and ')}; your message does not reach that work.${stop}`
+ return `${status} ${target.name} is also working in ${groups.map(whereOf).join(' and ')}; your message does not reach that work.${stop}`
},
}))
- // stop_bot throws when it does nothing, so the chat shows the call as failed
- // instead of "Stopped".
- const refuse = (message) => { throw new Error(message) }
-
ctx.tools.register(defineTool({
name: 'stop_bot',
description: 'Main Bot only. Stop another Bot\'s running turn immediately — when it must not finish a dangerous action and a message_bot warning is not enough. Its queued messages are dropped with the turn. It is then told why in a new turn, whose reply comes back to you.',
diff --git a/ds-bot/test/bot-messages.test.js b/ds-bot/test/bot-messages.test.js
index c77973cf..961b718b 100644
--- a/ds-bot/test/bot-messages.test.js
+++ b/ds-bot/test/bot-messages.test.js
@@ -187,6 +187,32 @@ test('a request steered into a running turn is recorded once and answered in a t
assert.deepEqual((await exchanges()).map(entry => entry.role), ['request', 'reply'])
})
+test('message_bot names the messages a Bot has not read yet, and stops sending to a stuck Bot', async (t) => {
+ const { ctx, agentOf, emit, tool, exchanges, stop } = await start(team())
+ t.after(stop)
+ // Writer's turn waits on something and never reaches its next step.
+ const writer = agentOf('b')
+ writer.steer = (message) => { writer.calls.push(['steer', message]); writer.inbox.nextStep.push(message) }
+ emit('b', 'turn/start', { turn: 1 })
+
+ const first = await tool('message_bot', { to: 'Writer', message: 'task 1' }, 'a')
+ assert.equal(first, 'Delivered to Writer while it is working: it reads your message at its next step and answers once that work is done. Its reply will arrive later as a new message; do not wait for it.')
+ assert.match(await tool('message_bot', { to: 'Writer', message: 'task 2' }, 'a'), /Writer has not read an earlier message from Bots yet\.$/)
+ for (let index = 3; index <= 10; index += 1) await tool('message_bot', { to: 'Writer', message: `task ${index}` }, 'a')
+ assert.match(await tool('message_bot', { to: 'Writer', message: 'task 10b' }, 'a').catch(error => error.message), /^Not sent: Writer has not read the last 10 messages from Bots yet/)
+ assert.equal(writer.calls.length, 10)
+ assert.equal((await exchanges()).length, 10)
+
+ // Once a step takes them up, messages go through again.
+ writer.inbox.nextStep.length = 0
+ assert.match(await tool('message_bot', { to: 'Writer', message: 'task 11' }, 'a'), /^Delivered to Writer while it is working/)
+
+ // An approval the Bot waits for holds its messages too.
+ writer.inbox.nextStep.length = 0
+ for (const listener of ctx.listeners.get('approval/request')) void listener({ agent: { session: { id: 'b' } }, toolName: 'bash', reason: 'rm' }, () => new Promise(() => {}))
+ assert.match(await tool('message_bot', { to: 'Writer', message: 'task 12' }, 'a'), /Writer is waiting for the user's approval, so it reads your message only after the user answers\.$/)
+})
+
test('a non-Main Bot can steer a message to a Main Bot', async (t) => {
const { agents, tool, stop } = await start(team())
t.after(stop)