A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Follow a PTC program's sub-calls in a Bot's work status
Fei2411a1f5dc7a8771
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex be0739b5..f5a27527 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++- With the `ptc` agent preset, the team view and a Bot's character show the tool the Bot runs from its code, an approval card says what that tool does, and a question card asked from code is kept in chat search and in the next part of the chat. In a group chat, a member that only reads the chat or checks the team no longer leaves the round as if it had gone off to work.+## [0.1.4] - 2026-10-13### Addeddiff --git a/ds-bot/src/host/parts.js b/ds-bot/src/host/parts.jsindex de23473c..69f838ed 100644--- a/ds-bot/src/host/parts.js+++ b/ds-bot/src/host/parts.js@@ -90,8 +90,9 @@ export function historyEntry(event, group) {const text = textOf(event.data?.message?.content)return text === '' ? undefined : { answer: true, text }}- // Cards only show in an own chat.- if (event.type === 'tool/call' && event.data?.name === 'ask_user' && !group) {+ // Cards only show in an own chat. A PTC program's sub-call asks too.+ const asks = (event.type === 'tool/call' || event.type === 'tool/ptc-dispatch-start') && event.data?.name === 'ask_user'+ if (asks && !group) {const text = cardText(event.data.arguments)return text === '' ? undefined : { answer: true, text }}diff --git a/ds-bot/src/host/turns.js b/ds-bot/src/host/turns.jsindex 80fcf66a..450191e9 100644--- a/ds-bot/src/host/turns.js+++ b/ds-bot/src/host/turns.js@@ -40,6 +40,10 @@ export const stripWrittenCalls = text => text.replace(/<function=[\w.-]+>[\s\S]*?(?:<\/function>|$)/g, '').trim()+// Under DSH's PTC presentation the model calls only this tool; the program's sub-calls+// are the tools it really runs.+const PROGRAM_TOOL = 'run_code'+const RETRY_TEXT = 'Your last reply wrote a tool call as plain text (<tool_call>…), so it did not run and nothing happened. Call the tool through the tool interface now, then reply as you meant to.'export function install(rt) {@@ -120,6 +124,22 @@ export function install(rt) {else next[id] = valueactivity = next}+ // The newest call still running, a program's sub-calls included, is what the Session+ // is doing.+ const showCall = (id, entry) => {+ const name = [...(entry.calls?.values() ?? [])].at(-1)?.name+ entry.tool = name+ if (name !== undefined) setActivity(id, name === 'ask_user' ? undefined : activityOf(name))+ else if (entry.turn !== undefined) setActivity(id, 'thinking')+ }+ const startCall = (id, entry, callId, name, args) => {+ if (typeof callId === 'string') (entry.calls ??= new Map()).set(callId, { name, args })+ showCall(id, entry)+ }+ const endCall = (id, entry, callId) => {+ entry.calls?.delete(callId)+ showCall(id, entry)+ }const markExchangeTurn = (sessionId, turn) => {const turns = state.exchangeTurns[sessionId] ??= []@@ -211,7 +231,7 @@ export function install(rt) {// the command, path or address it acts on.const callDetail = (sessionId, callId) => {let args- try { args = JSON.parse(live.get(sessionId)?.calls?.get(callId) ?? '{}') } catch { args = {} }+ try { args = JSON.parse(live.get(sessionId)?.calls?.get(callId)?.args ?? '{}') } catch { args = {} }const first = keys => keys.map(key => args?.[key]).find(value => typeof value === 'string' && value.trim() !== '')const text = first(['description', 'justification'])const code = first(['command', 'cmd', 'file_path', 'path', 'url', 'query'])@@ -245,16 +265,22 @@ export function install(rt) {switch (event.type) {case 'tool/call': {const name = String(event.data?.name ?? '')- setActivity(id, name === 'ask_user' ? undefined : activityOf(name))- entry.tool = name+ startCall(id, entry, event.data?.callId, name, String(event.data?.arguments ?? ''))+ // A program is as quick as the tools it runs, so its sub-calls decide.+ if (rt.groupOwners.has(id) && name !== PROGRAM_TOOL) rt.workRoomTurn?.(id, name)+ break+ }+ case 'tool/ptc-dispatch-start': {+ const name = String(event.data?.name ?? '')+ startCall(id, entry, event.data?.subCallId, name, JSON.stringify(event.data?.arguments ?? {}))if (rt.groupOwners.has(id)) rt.workRoomTurn?.(id, name)- if (typeof event.data?.callId === 'string') (entry.calls ??= new Map()).set(event.data.callId, String(event.data.arguments ?? ''))break}+ case 'tool/ptc-dispatch':+ endCall(id, entry, event.data?.subCallId)+ breakcase 'tool/result':- if (entry.turn !== undefined) setActivity(id, 'thinking')- entry.tool = undefined- entry.calls?.delete(event.data?.callId)+ endCall(id, entry, event.data?.callId)breakcase 'turn/start':setActivity(id, 'thinking')diff --git a/ds-bot/test/group-status.test.js b/ds-bot/test/group-status.test.jsindex 7b763538..03b2a582 100644--- a/ds-bot/test/group-status.test.js+++ b/ds-bot/test/group-status.test.js@@ -248,3 +248,49 @@ test('a member that fails after the round moved on shows the failure in the grouassert.deepEqual(round.failed, ['Writer'])assert.equal(host.agentOf('gb').calls.length, 1)})++// Under PTC the model calls run_code, and the program dispatches the real tools.+const program = (emit, sessionId, callId, code = 'await main()') => emit(sessionId, 'tool/call', { callId, name: 'run_code', arguments: JSON.stringify({ code }) })+const dispatch = (emit, sessionId, parentCallId, n, name, args = {}) => {+ const subCallId = `${parentCallId}:ptc:${n}`+ emit(sessionId, 'tool/ptc-dispatch-start', { rootCallId: parentCallId, parentCallId, subCallId, name, arguments: args })+ return () => emit(sessionId, 'tool/ptc-dispatch', { rootCallId: parentCallId, parentCallId, subCallId, name, arguments: args, isError: false, content: [] })+}++test('a Bot running a PTC program shows the tool the program is in', async (t) => {+ const host = await start()+ t.after(host.stop)+ const now = async () => {+ const { value } = await host.call('state', {})+ return [value.activity.b, value.work.bots.b?.tool]+ }+ host.emit('b', 'turn/start', { turn: 1 })+ program(host.emit, 'b', 'k1')+ assert.deepEqual(await now(), ['working', 'run_code'])+ const messaged = dispatch(host.emit, 'b', 'k1', 1, 'message_bot', { to: 'Chief', message: 'Done?' })+ assert.deepEqual(await now(), ['sending', 'message_bot'])+ const read = dispatch(host.emit, 'b', 'k1', 2, 'read_group_chat', { group: 'Ops' })+ assert.deepEqual(await now(), ['searching', 'read_group_chat'])+ read()+ assert.deepEqual(await now(), ['sending', 'message_bot'])+ messaged()+ assert.deepEqual(await now(), ['working', 'run_code'])+ dispatch(host.emit, 'b', 'k1', 3, 'ask_user', { question: 'Ship it?', options: [{ label: 'Yes' }] })()+ assert.deepEqual(await now(), ['working', 'run_code'])+ host.emit('b', 'tool/result', { callId: 'k1' })+ assert.deepEqual(await now(), ['thinking', undefined])+})++test('an approval asked inside a PTC program shows what that call does', async (t) => {+ const host = await start()+ t.after(host.stop)+ const result = await openTurn(t, host)+ program(host.emit, 'gb', 'k1')+ dispatch(host.emit, 'gb', 'k1', 1, 'pwsh', { command: 'Copy-Item a.md E:/docs', description: 'Copy the doc' })+ void host.askApproval('gb', { callId: 'k1:ptc:1' })+ await settle(() => result() !== undefined)+ const { value } = await host.call('state', {})+ const [approval] = value.work.approvals+ assert.deepEqual(approval.detail, { text: 'Copy the doc', code: 'Copy-Item a.md E:/docs' })+ assert.equal(value.work.bots.b.tool, 'pwsh')+})diff --git a/ds-bot/test/group-work.test.js b/ds-bot/test/group-work.test.jsindex db1376af..20c93bc9 100644--- a/ds-bot/test/group-work.test.js+++ b/ds-bot/test/group-work.test.js@@ -173,6 +173,47 @@ test('a quick team tool does not let the round go on', async (t) => {assert.deepEqual(kinds(result()), [['message', 'Writer']])})+// Under PTC the model calls run_code, and the program dispatches the real tools.+const dispatch = (emit, sessionId, parentCallId, n, name) => {+ const subCallId = `${parentCallId}:ptc:${n}`+ emit(sessionId, 'tool/ptc-dispatch-start', { rootCallId: parentCallId, parentCallId, subCallId, name, arguments: {} })+ return () => emit(sessionId, 'tool/ptc-dispatch', { rootCallId: parentCallId, parentCallId, subCallId, name, arguments: {}, isError: false, content: [] })+}++test('a PTC program that runs only team tools does not let the round go on', async (t) => {+ t.mock.timers.enable({ apis: ['setTimeout'] })+ const host = await start(t)+ const result = host.round('c1', host.say('@Writer 群里刚才说了什么?'))+ await settle(() => host.agentOf('gb').calls.length === 1)+ host.begin('gb')+ host.emit('gb', 'tool/call', { callId: 'k1', name: 'run_code', arguments: '{"code":"await read_group_chat({})"}' })+ dispatch(host.emit, 'gb', 'k1', 1, 'read_group_chat')()+ dispatch(host.emit, 'gb', 'k1', 2, 'list_bots')()+ host.emit('gb', 'tool/result', { callId: 'k1' })+ t.mock.timers.tick(ROOM_WORK_GRACE_MS * 2)+ await settle(() => true)+ assert.equal(result(), undefined)+ host.finish('gb', '在讨论文档的结构。')+ await settle(() => result() !== undefined)+ assert.deepEqual(kinds(result()), [['message', 'Writer']])+})++test('work inside a PTC program lets the round go on after the grace', async (t) => {+ t.mock.timers.enable({ apis: ['setTimeout'] })+ const host = await start(t)+ const result = host.round('c1', host.say('@Writer 整理文档'))+ await settle(() => host.agentOf('gb').calls.length === 1)+ host.begin('gb')+ host.emit('gb', 'tool/call', { callId: 'k1', name: 'run_code', arguments: '{}' })+ dispatch(host.emit, 'gb', 'k1', 1, 'read_group_chat')()+ dispatch(host.emit, 'gb', 'k1', 2, 'write')+ const { value } = await host.call('state', {})+ assert.deepEqual(value.work.rooms.r1.map(entry => [entry.botId, entry.tool]), [['b', 'write']])+ t.mock.timers.tick(ROOM_WORK_GRACE_MS)+ await settle(() => result() !== undefined)+ assert.deepEqual(kinds(result()), [['working', 'Writer']])+})+test('work the user asked for is left for the user to read, and the user\'s message resets the late limit', async (t) => {t.mock.timers.enable({ apis: ['setTimeout'] })const host = await start(t, { lateRounds: ROOM_LATE_ROUNDS - 1 })diff --git a/ds-bot/test/history.test.js b/ds-bot/test/history.test.jsindex 75d3a74d..1aa08dbc 100644--- a/ds-bot/test/history.test.js+++ b/ds-bot/test/history.test.js@@ -21,6 +21,10 @@ test('historyEntry keeps answers, user and Bot messages, and skips setup', () =>const ask = { type: 'tool/call', data: { name: 'ask_user', arguments: { question: 'Q', options: [{ label: 'A' }] } } }assert.deepEqual(historyEntry(ask, false), { answer: true, text: '[Question card] Q\nOptions: A' })assert.equal(historyEntry(ask, true), undefined)+ const asked = { type: 'tool/ptc-dispatch-start', data: { parentCallId: 'k1', subCallId: 'k1:ptc:1', name: 'ask_user', arguments: { question: 'Q', options: [{ label: 'A' }] } } }+ assert.deepEqual(historyEntry(asked, false), { answer: true, text: '[Question card] Q\nOptions: A' })+ assert.equal(historyEntry(asked, true), undefined)+ assert.equal(historyEntry({ ...asked, type: 'tool/ptc-dispatch' }, false), undefined)assert.deepEqual(historyEntry(said('hello', { kind: 'user' }), false), { answer: false, who: 'user', text: 'hello', keepAnswers: true })assert.deepEqual(historyEntry(said('[Reply from W]\nok', { kind: 'bot', role: 'reply' }), false), { answer: false, who: 'bot', text: '[Reply from W]\nok', keepAnswers: true })assert.deepEqual(historyEntry(said('[Bot team setup]\nhi', { kind: 'bot', role: 'kickoff' }), false), { answer: false, who: 'bot', text: '', keepAnswers: false })