Skip to content

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

Wait for Bot capabilities before first requests

lulu feizhuf29078390bab
diff --git a/ds-bot/dev/smoke.mjs b/ds-bot/dev/smoke.mjs
index 806495c5..b84606c0 100644
--- a/ds-bot/dev/smoke.mjs
+++ b/ds-bot/dev/smoke.mjs
@@ -333,6 +333,14 @@ await step('Chief sees its attached MCP and skill', () => send(chief().id, 'Chec
?? expect(latestReminder(body).includes(skillName) && latestReminder(body).includes(skillDescription), `skill catalog entry missing from ${path}`)
})
+const capabilityRoom = await api('create-room', { name: 'Capability smoke', members: [chief().id, botNamed('Coder').id], admin: chief().id })
+await step('Chief first group turn sees its attached MCP and skill', () => send(capabilityRoom.id, 'Check your available capabilities.'), () => {
+ const { body, path } = tapBody('Chief')
+ const tools = (body.tools ?? []).map(tool => tool.name)
+ return expect(tools.includes(`mcp__${echoName}__echo`), `MCP tool missing from the first group request in ${path}`)
+ ?? expect(latestReminder(body).includes(skillName) && latestReminder(body).includes(skillDescription), `skill catalog entry missing from the first group request in ${path}`)
+})
+
await step('Coder does not inherit Chief capabilities', () => send(botNamed('Coder').id, 'Check your available capabilities.'), () => {
const { body, path } = tapBody('Coder')
const tools = (body.tools ?? []).map(tool => tool.name)
diff --git a/ds-bot/src/host/channel.js b/ds-bot/src/host/channel.js
index 98963190..251636a0 100644
--- a/ds-bot/src/host/channel.js
+++ b/ds-bot/src/host/channel.js
@@ -254,6 +254,7 @@ export function install(rt) {
// Claim the question before queueing so a second answer is refused.
delete state.questions[sessionId]
try {
+ await rt.ensureCapabilities(sessionId)
const agent = await rt.resolveAgent(sessionId)
agent.followup(createUserMessage({ content: [{ type: 'text', text: reply.text }], source: reply.source }))
await ctx.sessions.flush(agent.session)
@@ -271,6 +272,7 @@ export function install(rt) {
// A Bot id or an earlier part of its own chat means the current part.
const past = rt.pastOwners.get(body.sessionId)
const sessionId = rt.botOf(body.sessionId) ? rt.chatOf(body.sessionId) : past && past.roomId === undefined ? rt.chatOf(past.botId) : body.sessionId
+ await rt.ensureCapabilities(sessionId)
await ctx.sessionController.prompt({
requestId: randomUUID(),
sessionId,
diff --git a/ds-bot/src/host/delivery.js b/ds-bot/src/host/delivery.js
index 50c656ec..77af9d7d 100644
--- a/ds-bot/src/host/delivery.js
+++ b/ds-bot/src/host/delivery.js
@@ -54,7 +54,9 @@ export function install(rt) {
state.exchanges.push({ id: exchangeId, from: fromId, to: toId, text, role, time: Date.now(), ...(replyTo ? { replyTo } : {}), ...(audience === 'user' ? { audience } : {}) })
void rt.save().catch(() => {})
}
- const agent = await resolveAgent(sessionId ?? rt.chatOf(toId))
+ const targetSessionId = sessionId ?? rt.chatOf(toId)
+ await rt.ensureCapabilities(targetSessionId)
+ const agent = await resolveAgent(targetSessionId)
// A steered message cuts into a running turn at its next step; a follow-up
// queues for the next turn (see turns.js for how each is routed).
const message = createUserMessage({
diff --git a/ds-bot/src/host/groups.js b/ds-bot/src/host/groups.js
index 2bc942e7..3c439078 100644
--- a/ds-bot/src/host/groups.js
+++ b/ds-bot/src/host/groups.js
@@ -109,7 +109,10 @@ export function install(rt) {
async function groupSessionFor(room, member) {
room.sessions ??= {}
const known = room.sessions[member.id]
- if (known !== undefined) return { id: known, brief: undefined }
+ if (known !== undefined) {
+ await rt.ensureCapabilities(known)
+ return { id: known, brief: undefined }
+ }
const id = await rt.createSession(`${member.name} · ${room.name}`)
room.sessions[member.id] = id
rt.groupOwners.set(id, { botId: member.id, roomId: room.id })
@@ -122,6 +125,7 @@ export function install(rt) {
await rt.applyPermission(member, id)
.catch(error => rt.warn('ds-bot: permission for %s in %s not applied: %s', member.name, room.name, error))
await rt.save()
+ await rt.ensureCapabilities(id)
return { id, brief: await rt.ownChatBrief(member) }
}
diff --git a/ds-bot/src/host/parts.js b/ds-bot/src/host/parts.js
index aa847431..de23473c 100644
--- a/ds-bot/src/host/parts.js
+++ b/ds-bot/src/host/parts.js
@@ -641,6 +641,7 @@ export function install(rt) {
async function forward(owner, messages) {
const target = currentOf(owner)
if (target === undefined || messages.length === 0) return
+ await rt.ensureCapabilities(target)
const agent = await rt.resolveAgent(target)
for (const message of messages) {
const copy = createUserMessage({ content: message.content, ...(message.source ? { source: message.source } : {}) })
@@ -770,6 +771,7 @@ export function install(rt) {
const resume = job.resume || job.overflow
const text = handoffPackage({ room, segment, lines: carried, number: number + 1, resume, overflow: job.overflow, failed: job.failed, bare: job.bare })
freshParts.set(freshId, estimateTokens(text))
+ await rt.ensureCapabilities(freshId)
const fresh = await rt.resolveAgent(freshId)
fresh.followup(createUserMessage({ content: [{ type: 'text', text }], source: handoffSource(job, resume) }))
await ctx.sessions.flush(fresh.session)
diff --git a/ds-bot/test/rounds.test.js b/ds-bot/test/rounds.test.js
index 79c83297..55666e63 100644
--- a/ds-bot/test/rounds.test.js
+++ b/ds-bot/test/rounds.test.js
@@ -4,7 +4,7 @@ import { mkdtempSync, readFileSync, rmSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { test } from 'node:test'
-import { apply } from '../index.js'
+import { createRuntime } from '../index.js'
import { fakeContext } from './fake-ctx.js'
// A fake team of two Bots in one group; member answers are played back through the
@@ -71,7 +71,7 @@ function start() {
route = options
return register(options)
}
- apply(ctx, { home })
+ const rt = createRuntime(ctx, { home })
const call = async (endpoint, payload) => {
const response = await route.fetch(new Request('http://localhost/api/bot', { method: 'POST', body: JSON.stringify({ endpoint, payload }) }))
return response.json()
@@ -101,7 +101,7 @@ function start() {
ctx.dispose()
rmSync(home, { recursive: true, force: true, maxRetries: 5 })
}
- return { call, emit, userMessage, compose, relay, inboxOf, answer, stop, sent, ctx, home }
+ return { call, emit, userMessage, compose, relay, inboxOf, answer, stop, sent, ctx, home, rt }
}
const settle = () => new Promise(resolve => setTimeout(resolve, 20))
@@ -115,6 +115,34 @@ const waitFor = async (check) => {
}
const turnFor = (sent, ...earlier) => waitFor(() => sent.find(entry => !earlier.includes(entry) && entry.message.source.role === 'room'))
+test('a new group Session waits for capabilities before its first member prompt', async (t) => {
+ const { call, emit, userMessage, relay, answer, stop, sent, rt } = start()
+ t.after(stop)
+ const room = await team(call, sent)
+ await emit(room.id, userMessage('Start'))
+
+ let release
+ let markStarted
+ const gate = new Promise(resolve => { release = resolve })
+ const started = new Promise(resolve => { markStarted = resolve })
+ rt.ensureCapabilities = async sessionId => {
+ markStarted(sessionId)
+ await gate
+ }
+ const running = relay(room.id, 'first-turn')
+ const sessionId = await started
+ assert.equal(sent.length, 0)
+ release()
+
+ const first = await turnFor(sent)
+ assert.equal(first.sessionId, sessionId)
+ await answer(first.sessionId, first.message.source.exchangeId, 'Chief ready.', 1)
+ const second = await turnFor(sent, first)
+ assert.ok(second)
+ await answer(second.sessionId, second.message.source.exchangeId, 'Writer ready.', 2)
+ await running
+})
+
async function team(call, sent) {
const chief = (await call('state', {})).value.mainBotId
const writer = (await call('create-bot', { name: 'Writer' })).value