Skip to content

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

Propagate task handoff guidance

Fei24116b50720fb5f3
diff --git a/ds-bot/src/host/browser/session.js b/ds-bot/src/host/browser/session.js
index e623809e..a7aa618b 100644
--- a/ds-bot/src/host/browser/session.js
+++ b/ds-bot/src/host/browser/session.js
@@ -708,7 +708,7 @@ export function createSession({ context, browser, page, botId, userDataDir, cook
onHold?.({ by: 'bot', reason: kind, note: hold.note, ...origin })
const recorded = getHold?.()
const guidance = origin?.callId !== undefined && recorded && recorded.callId === undefined
- ? 'There is no handoff card in this conversation. Tell the user here what you need them to do. After they reply, check with browser_snapshot or call browser_resume.'
+ ? 'There is no handoff card in this conversation. Tell the user here what you need them to do. After they reply, call browser_resume, then browser_snapshot to check the page.'
: 'Call browser_resume when they have finished.'
return `Waiting for the user (${kind}). ${hold.note || 'Ask them to take over.'} ${guidance}`
},
diff --git a/ds-bot/src/host/browser/task.js b/ds-bot/src/host/browser/task.js
index 4540c1ed..1a4108e0 100644
--- a/ds-bot/src/host/browser/task.js
+++ b/ds-bot/src/host/browser/task.js
@@ -3,17 +3,22 @@
import { runToolLoop } from './loop.js'
import { systemPrompt as refsPrompt, toolDefs as refTools } from './refs.js'
-const driverTools = (session, origin) => refTools.map(tool => ({
+const driverTools = (session, origin, handoffs) => refTools.map(tool => ({
name: tool.name,
description: tool.description,
parameters: tool.parameters,
- execute: (args) => tool.execute(args, { session, botId: session.botId, profileDir: session.userDataDir, origin }),
+ execute: async (args) => {
+ const value = await tool.execute(args, { session, botId: session.botId, profileDir: session.userDataDir, origin })
+ if (tool.name === 'browser_handoff') handoffs.push(typeof value === 'string' ? value : String(value?.text ?? ''))
+ return value
+ },
}))
export async function runTask({ session, goal, complete, origin, maxSteps = 8 }) {
if (typeof complete !== 'function') throw new Error('browser_task needs a Bot session model')
+ const handoffs = []
const result = await runToolLoop({
- tools: driverTools(session, origin),
+ tools: driverTools(session, origin, handoffs),
complete,
goal,
system: refsPrompt,
@@ -23,6 +28,8 @@ export async function runTask({ session, goal, complete, origin, maxSteps = 8 })
const text = [
result.answer || '(no answer)',
'',
+ // The outer Bot needs the handoff instructions even if the nested model omits them.
+ ...(handoffs.length > 0 ? ['Handoffs:', handoffs.join('\n'), ''] : []),
result.stopped === 'max-steps' ? `Stopped after ${result.steps} steps.` : `Finished in ${result.steps} steps.`,
'Steps:',
steps || '(none)',
diff --git a/ds-bot/test/browser-handoff.test.js b/ds-bot/test/browser-handoff.test.js
index c180e6ef..499c9796 100644
--- a/ds-bot/test/browser-handoff.test.js
+++ b/ds-bot/test/browser-handoff.test.js
@@ -9,7 +9,7 @@ import { mountBrowserPlugin } from '../src/host/browser/mount.js'
import { createSession } from '../src/host/browser/session.js'
import { toolDefs as refsTools } from '../src/host/browser/refs.js'
import { toolDefs as scriptTools } from '../src/host/browser/script.js'
-import { toolDefs as taskTools } from '../src/host/browser/task.js'
+import { runTask, toolDefs as taskTools } from '../src/host/browser/task.js'
import { REPLY_KIND } from '../src/host/constants.js'
import { handoffReply, historyEntry, install as installParts, readReply, replyText } from '../src/host/parts.js'
import { fakeContext } from './fake-ctx.js'
@@ -136,6 +136,7 @@ test('browser_task forwards its outer call origin to a nested handoff', async ()
const result = await tools.get('browser_task').execute({ goal: 'Sign in' }, { agent: { id: 'b2' }, callId: 'outer-call' })
assert.match(result.text, /Waiting for sign-in/)
+ assert.match(result.text, /Handoffs:\nwaiting/)
assert.deepEqual(holds, [
['b2', { by: 'bot', reason: 'login', note: 'Sign in', callId: 'outer-call', sessionId: 'b2' }],
])
@@ -156,7 +157,7 @@ test('only a handoff raised in the Bot\'s own chat keeps its call and drops the
assert.deepEqual(handoffHold(rt, 'b2', { by: 'bot', reason: 'other', note: '' }), { by: 'bot', reason: 'other', note: '' })
})
-test('a handoff outside the Bot\'s own chat says to ask there instead of waiting for a card', async (t) => {
+test('a handoff outside the Bot\'s own chat gives resume-first guidance, and browser_task returns it', async (t) => {
const { rt, stop } = start()
t.after(stop)
await rt.load()
@@ -180,8 +181,28 @@ test('a handoff outside the Bot\'s own chat says to ask there instead of waiting
const group = makeSession().handoff('login', 'Sign in', { callId: 'call-2', sessionId: 'room-session' })
assert.match(group, /no handoff card in this conversation/)
assert.match(group, /Tell the user here what you need them to do/)
- assert.match(group, /browser_snapshot or call browser_resume/)
+ assert.match(group, /call browser_resume, then browser_snapshot/)
assert.deepEqual(rt.browserChannel.holdOf('b2'), { by: 'bot', reason: 'login', note: 'Sign in' })
+
+ rt.browserChannel.setHold('b2', null)
+ let completions = 0
+ const task = await runTask({
+ session: makeSession(),
+ goal: 'Sign in',
+ origin: { callId: 'call-3', sessionId: 'room-session' },
+ complete: async () => {
+ completions += 1
+ if (completions === 1) {
+ return { choices: [{ message: { tool_calls: [{
+ id: 'inner-call',
+ function: { name: 'browser_handoff', arguments: JSON.stringify({ reason: 'login', note: 'Sign in' }) },
+ }] } }] }
+ }
+ return { choices: [{ message: { content: 'Nested answer' } }] }
+ },
+ })
+ assert.match(task.text, /Nested answer/)
+ assert.ok(task.text.includes(`Handoffs:\n${group}`))
})
test('the channel keeps a handoff\'s call on its hold', async (t) => {