Skip to content

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

Show refused interrupts and stops as failed; keep interrupts in earlier parts

FeiZhuLulu8d28e85093c6
diff --git a/ds-bot/client.js b/ds-bot/client.js
index 373b5b3a..60a04a5b 100644
--- a/ds-bot/client.js
+++ b/ds-bot/client.js
@@ -418,6 +418,7 @@ var ZH = {
"Reply from": "收到回复:",
"Message from": "收到消息:",
"Stopped by": "叫停者:",
+ "Interrupt from": "收到插话:",
"{count} messages with": "{count} 条消息,来自",
"Routine started": "例行任务开始",
Update: "更新",
@@ -3863,7 +3864,8 @@ function EarlierParts({ sessionId, roster, actions }) {
case "event": {
if (row.role === "report") return (0, import_react6.createElement)(GroupEvent, { key, prefix: t("Replies from"), room: roster.roomsById[row.roomId], name: t("a group chat"), roster, actions });
const other = roster.byId[row.botId] ?? { id: row.botId, name: row.name ?? t("a Bot"), color: "gray" };
- return (0, import_react6.createElement)(EventLine, { key, prefix: row.role === "stopped" ? t("Stopped by") : row.role === "reply" ? t("Reply from") : t("Message from"), bots: [other], onOpen: () => {
+ const prefix = { stopped: t("Stopped by"), interrupt: t("Interrupt from"), reply: t("Reply from") }[row.role] ?? t("Message from");
+ return (0, import_react6.createElement)(EventLine, { key, prefix, bots: [other], onOpen: () => {
if (selfId && other.id) actions.openExchange(selfId, other.id);
} });
}
@@ -3928,7 +3930,7 @@ function TriggerCell({ node, sessionId, useRoster, useSessions, useTurnClock, us
if (!bots.some((bot) => bot.id === peer.id)) bots.push(peer);
}
return (0, import_react6.createElement)(EventLine, {
- prefix: source.role === "stopped" ? t("Stopped by") : count > 1 ? t("{count} messages with", { count }) : t("Message from"),
+ prefix: source.role === "stopped" ? t("Stopped by") : source.role === "interrupt" ? t("Interrupt from") : count > 1 ? t("{count} messages with", { count }) : t("Message from"),
bots,
onOpen: (bot) => actions.openExchange(selfId, bot.id)
});
diff --git a/ds-bot/src/client/cells.js b/ds-bot/src/client/cells.js
index 4f40ba07..3cf9d3b6 100644
--- a/ds-bot/src/client/cells.js
+++ b/ds-bot/src/client/cells.js
@@ -247,7 +247,8 @@ function EarlierParts({ sessionId, roster, actions }) {
case 'event': {
if (row.role === 'report') return h(GroupEvent, { key, prefix: t('Replies from'), room: roster.roomsById[row.roomId], name: t('a group chat'), roster, actions })
const other = roster.byId[row.botId] ?? { id: row.botId, name: row.name ?? t('a Bot'), color: 'gray' }
- return h(EventLine, { key, prefix: row.role === 'stopped' ? t('Stopped by') : row.role === 'reply' ? t('Reply from') : t('Message from'), bots: [other], onOpen: () => { if (selfId && other.id) actions.openExchange(selfId, other.id) } })
+ const prefix = { stopped: t('Stopped by'), interrupt: t('Interrupt from'), reply: t('Reply from') }[row.role] ?? t('Message from')
+ return h(EventLine, { key, prefix, bots: [other], onOpen: () => { if (selfId && other.id) actions.openExchange(selfId, other.id) } })
}
default: return null
}
@@ -321,7 +322,7 @@ export function TriggerCell({ node, sessionId, useRoster, useSessions, useTurnCl
if (!bots.some(bot => bot.id === peer.id)) bots.push(peer)
}
return h(EventLine, {
- prefix: source.role === 'stopped' ? t('Stopped by') : count > 1 ? t('{count} messages with', { count }) : t('Message from'),
+ prefix: source.role === 'stopped' ? t('Stopped by') : source.role === 'interrupt' ? t('Interrupt from') : count > 1 ? t('{count} messages with', { count }) : t('Message from'),
bots,
onOpen: bot => actions.openExchange(selfId, bot.id),
})
diff --git a/ds-bot/src/client/i18n.js b/ds-bot/src/client/i18n.js
index edf3121d..da31d7de 100644
--- a/ds-bot/src/client/i18n.js
+++ b/ds-bot/src/client/i18n.js
@@ -372,6 +372,7 @@ const ZH = {
'Reply from': '收到回复:',
'Message from': '收到消息:',
'Stopped by': '叫停者:',
+ 'Interrupt from': '收到插话:',
'{count} messages with': '{count} 条消息,来自',
'Routine started': '例行任务开始',
Update: '更新',
diff --git a/ds-bot/src/host/parts.js b/ds-bot/src/host/parts.js
index 28e90e51..d43413ef 100644
--- a/ds-bot/src/host/parts.js
+++ b/ds-bot/src/host/parts.js
@@ -864,7 +864,7 @@ export function install(rt) {
} else if (source?.kind === REPLY_KIND) {
const reply = readReply(textOf(event.data.content))
if (reply !== undefined) items.push({ kind: 'answer', questions: reply.questions, answers: reply.answers, time: event.time })
- } else if (source?.kind === SOURCE_KIND && source.handoff !== true && ['request', 'reply', 'report', 'stopped'].includes(source.role)) {
+ } else if (source?.kind === SOURCE_KIND && source.handoff !== true && ['request', 'reply', 'report', 'interrupt', 'stopped'].includes(source.role)) {
items.push({ kind: 'event', role: source.role, botId: source.senderSessionId ?? null, name: source.senderName ?? null, roomId: source.roomId ?? null, time: event.time })
}
}
diff --git a/ds-bot/src/host/tools.js b/ds-bot/src/host/tools.js
index d41c5c29..4c6a1368 100644
--- a/ds-bot/src/host/tools.js
+++ b/ds-bot/src/host/tools.js
@@ -99,6 +99,9 @@ export function install(rt) {
const room = rt.roomOf(rt.groupOwners.get(sessionId)?.roomId)
return room ? `group "${room.name}"` : 'its own chat'
}
+ // interrupt_bot and stop_bot throw when they do nothing, so the chat shows the call
+ // as failed instead of "Interrupted" or "Stopped".
+ const refuse = (message) => { throw new Error(message) }
ctx.tools.register(defineTool({
name: 'interrupt_bot',
@@ -111,12 +114,12 @@ export function install(rt) {
async execute(args, exec) {
await rt.load()
const sender = callerBot(exec)
- if (sender === undefined || !rt.isMain(sender.id)) return 'Only a Main Bot can interrupt other Bots.'
+ if (sender === undefined || !rt.isMain(sender.id)) refuse('Only a Main Bot can interrupt other Bots.')
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 interrupt yourself.'
+ if (target === undefined) refuse(`No Bot named ${args.to}. Team: ${Object.values(state.bots).map(bot => bot.name).join(', ')}`)
+ if (target.id === sender.id) refuse('You cannot interrupt yourself.')
const text = String(args.message ?? '').trim()
- if (text === '') return 'Write a message to send.'
+ if (text === '') refuse('Write a message to send.')
const { running, idle } = activeSessions(target.id)
const sessions = idle ? [rt.chatOf(target.id)] : running
for (const [index, sessionId] of sessions.entries()) {
@@ -139,12 +142,12 @@ export function install(rt) {
async execute(args, exec) {
await rt.load()
const sender = callerBot(exec)
- if (sender === undefined || !rt.isMain(sender.id)) return 'Only a Main Bot can stop other Bots.'
+ if (sender === undefined || !rt.isMain(sender.id)) refuse('Only a Main Bot can stop other Bots.')
const target = rt.findBot(args.bot)
- if (target === undefined) return `No Bot named ${args.bot}. Team: ${Object.values(state.bots).map(bot => bot.name).join(', ')}`
- if (target.id === sender.id) return 'You cannot stop yourself.'
+ if (target === undefined) refuse(`No Bot named ${args.bot}. Team: ${Object.values(state.bots).map(bot => bot.name).join(', ')}`)
+ if (target.id === sender.id) refuse('You cannot stop yourself.')
const { running } = activeSessions(target.id)
- if (running.length === 0) return `${target.name} is not running right now, so there is nothing to stop. Use message_bot to reach it, or interrupt_bot once it is running.`
+ if (running.length === 0) refuse(`${target.name} is not running right now, so there is nothing to stop. Use message_bot to reach it, or interrupt_bot once it is running.`)
for (const sessionId of running) {
const agent = await rt.resolveAgent(sessionId)
agent.cancel({ kind: 'hook', reason: 'ds-bot/stopped' })
diff --git a/ds-bot/test/interrupt.test.js b/ds-bot/test/interrupt.test.js
index ba5de442..9dc1e8bb 100644
--- a/ds-bot/test/interrupt.test.js
+++ b/ds-bot/test/interrupt.test.js
@@ -6,6 +6,7 @@ import { test } from 'node:test'
import { apply } from '../index.js'
import { fakeContext } from './fake-ctx.js'
import { install as installTurns } from '../src/host/turns.js'
+import { install as installParts } from '../src/host/parts.js'
import { SOURCE_KIND } from '../src/host/constants.js'
// A two-Bot team, optionally with b in a group Session 'gb' of room 'Ops'.
@@ -131,10 +132,13 @@ test('interrupt_bot and stop_bot belong to a Main Bot', async (t) => {
const { agents, tool, stop } = await start(team())
t.after(stop)
- assert.equal(await tool('interrupt_bot', { to: 'Writer', message: 'x' }, 'b'), 'Only a Main Bot can interrupt other Bots.')
- assert.equal(await tool('stop_bot', { bot: 'Writer' }, 'b'), 'Only a Main Bot can stop other Bots.')
- assert.equal(await tool('interrupt_bot', { to: 'Chief', message: 'x' }, 'a'), 'You cannot interrupt yourself.')
- assert.equal(await tool('stop_bot', { bot: 'Chief' }, 'a'), 'You cannot stop yourself.')
+ // A refusal fails the call, so the chat does not show it as done.
+ await assert.rejects(tool('interrupt_bot', { to: 'Writer', message: 'x' }, 'b'), { message: 'Only a Main Bot can interrupt other Bots.' })
+ await assert.rejects(tool('stop_bot', { bot: 'Writer' }, 'b'), { message: 'Only a Main Bot can stop other Bots.' })
+ await assert.rejects(tool('interrupt_bot', { to: 'Chief', message: 'x' }, 'a'), { message: 'You cannot interrupt yourself.' })
+ await assert.rejects(tool('stop_bot', { bot: 'Chief' }, 'a'), { message: 'You cannot stop yourself.' })
+ await assert.rejects(tool('interrupt_bot', { to: 'Nobody', message: 'x' }, 'a'), /No Bot named Nobody/)
+ await assert.rejects(tool('interrupt_bot', { to: 'Writer', message: ' ' }, 'a'), { message: 'Write a message to send.' })
assert.deepEqual(agents.get('b')?.calls ?? [], [])
})
@@ -142,7 +146,8 @@ test('stop_bot cancels the running turns and tells the Bot why in a new turn', a
const { agents, emit, tool, stop } = await start(team({ group: true }))
t.after(stop)
- assert.match(await tool('stop_bot', { bot: 'Writer' }, 'a'), /not running/)
+ await assert.rejects(tool('stop_bot', { bot: 'Writer' }, 'a'), /not running/)
+ assert.deepEqual(agents.get('b')?.calls ?? [], [])
emit('b', 'turn/start', { turn: 1 })
emit('gb', 'turn/start', { turn: 1 })
@@ -231,3 +236,26 @@ test('a stopped notice routes the acknowledgement back like a request', () => {
assert.equal(delivered[0].replyTo, 's1')
assert.equal(delivered[0].text, 'understood')
})
+
+test('an earlier part keeps the interrupt that its Bot answered', async () => {
+ const writer = { id: 'b', name: 'Writer', createdAt: 1, sessionId: 'b2', segments: [{ sessionId: 'b1', endedAt: 2 }] }
+ const events = [
+ { type: 'user/message', seq: 1, time: 10, data: { turn: 1, content: [{ type: 'text', text: '[Interrupt from Chief]\nDo not delete that' }], source: replySource('interrupt') } },
+ { type: 'assistant/message', seq: 2, time: 11, data: { turn: 1, message: { content: [{ type: 'text', text: 'Understood, I stopped.' }] } } },
+ ]
+ const rt = {
+ ctx: { on() {}, effect() {}, get() {}, sessionController: { page: async () => ({ records: events.map(event => ({ event })), hasMore: false }) } },
+ config: {},
+ state: { exchangeTurns: {} },
+ chatOwners: new Map([['b2', 'b']]),
+ pastOwners: new Map([['b1', { botId: 'b' }]]),
+ botOf: id => (id === 'b' ? writer : undefined),
+ roomOf: () => undefined,
+ chatOf: () => 'b2',
+ resolveAgent: async id => ({ session: { id, seq: 3 } }),
+ }
+ installParts(rt)
+ const { items } = await rt.earlierPage('b2')
+ assert.deepEqual(items.map(item => [item.kind, item.role ?? item.text]), [['event', 'interrupt'], ['bot', 'Understood, I stopped.']])
+ assert.equal(items[0].botId, 'a')
+})