A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Refuse Agent Teams tools in Bot Sessions
AdamPlatin123d9f73d1da694
diff --git a/docs/plans/2026-10-10-bot-runtime.md b/docs/plans/2026-10-10-bot-runtime.mdindex 7da8aa97..ebfc98f7 100644--- a/docs/plans/2026-10-10-bot-runtime.md+++ b/docs/plans/2026-10-10-bot-runtime.md@@ -19,7 +19,7 @@- 只有一个 Bot 预设:DS Bot 的 Bot 内核加 DSH 的标准 harness(`standard`),不改造。- 这个预设归 DS Bot 所有:新建的 Bot 会话、群会话和对话分段都显式用 `standard`,**不跟随**用户在 DSH 里设的「新任务默认」。DSH 里没有可用的 `standard` 时,才交给 DSH 决定。- Bot 的工具只挂在 Bot 的作用域里,不出现在普通 DSH 会话中。-- Bot 的私聊和群会话里拿掉三类 DSH 工具,以及 DSH 为它们写进系统提示的用法说明:提问工具 `ask_user_question`(Bot 用自己的 `ask_user`);goal 工具(Bot 不跑 goal);委派工具(`subagent`、`subagent_fork`、`workflow` 等)和子代理控制工具(`send_message`、`interrupt_agent`、`list_agents`)。万一仍有调用进来,会被拒绝,并提示 Bot 自己做,或把活交给别的 Bot。不是 Bot 的 DSH 会话照旧。+- Bot 的私聊和群会话里拿掉三类 DSH 工具,以及 DSH 为它们写进系统提示的用法说明:提问工具 `ask_user_question`(Bot 用自己的 `ask_user`);goal 工具(Bot 不跑 goal);委派工具(`subagent`、`subagent_fork`、`workflow` 等)、子代理控制工具(`send_message`、`interrupt_agent`、`list_agents`)和 Agent Teams 的队友工具(`spawn_teammate`、`wait_agent`、`team_task_*`,连同它的 `team:policy` 说明)。DSH 注册在 Agent 自身作用域里的工具(`subagent` 和 Agent Teams 的工具)拿不掉:DSH 0.2.2 起仍会出现在工具列表里,只靠拒绝挡住调用。万一仍有调用进来,会被拒绝,并提示 Bot 自己做,或把活交给别的 Bot。不是 Bot 的 DSH 会话照旧。- 要并行,就让几个 Bot 同时干:`message_bot` 派活,群里 `@` 点名(见 [Bot 之间派活](2026-10-16-bot-handoffs.md)、[群聊](2026-10-07-group-chat.md))。Bot 不派 DSH 子代理:子代理跑起来用户看不到、停不到,换段时会被连带取消,结论丢失(#463、#788)。- 以前在 PTC 预设下建的群会话只能调用 `run_code`,DS Bot 为它们单独处理群的接力;新的群会话都用标准预设(#37、#168)。diff --git a/ds-bot/src/host/tools.js b/ds-bot/src/host/tools.jsindex 951adc91..d9f55eb8 100644--- a/ds-bot/src/host/tools.js+++ b/ds-bot/src/host/tools.js@@ -18,19 +18,22 @@ const BLOCKING_QUESTION_TOOL = 'ask_user_question'const GOAL_TOOLS = ['create_goal', 'update_goal', 'get_goal']// DSH's delegation tools start child agents the user cannot watch or stop, and they// end with the conversation part that started them; Bots hand work to other Bots.-const DELEGATION_TOOLS = ['subagent', 'subagent_fork', 'subagent_codex', 'subagent_claude_code', 'list_subagent_models', 'send_message', 'interrupt_agent', 'list_agents', 'workflow', 'ralph']+// Agent Teams' teammates are such children too (#973).+const DELEGATION_TOOLS = ['subagent', 'subagent_fork', 'subagent_codex', 'subagent_claude_code', 'list_subagent_models', 'send_message', 'interrupt_agent', 'list_agents', 'workflow', 'ralph', 'spawn_teammate', 'wait_agent', 'team_task_create', 'team_task_get', 'team_task_list', 'team_task_update']// restrict() refuses a whole list when one name is registered in the Agent's own// scope, so each group is masked on its own.const HIDDEN_TOOL_GROUPS = [[BLOCKING_QUESTION_TOOL, ...GOAL_TOOLS], DELEGATION_TOOLS]const HIDDEN_TOOLS = HIDDEN_TOOL_GROUPS.flat()-// The guidance DSH writes into the prompt for the hidden tools.-const HIDDEN_SECTIONS = new Set([...HIDDEN_TOOLS.map(name => `tool:${name}`), 'tool:goal'])+// The guidance DSH writes into the prompt for the hidden tools. Agent Teams makes+// every root Session a Team Lead and tells it to spawn teammates in `team:policy`;+// its `team:identity` context is required, so DSH puts it back after any filter.+const HIDDEN_SECTIONS = new Set([...HIDDEN_TOOLS.map(name => `tool:${name}`), 'tool:goal', 'team:policy'])const GOAL_REFUSAL = 'Bot chats do not run /goal. To give a group a goal, use Set a goal in its + menu.'// DSH 0.2.2's schedule tools can deliver to a new Session, which is outside the team and// has no Bot; a Bot's tasks deliver to its own chat, which DS Bot moves on with each part.const SCHEDULE_TARGET_TOOLS = ['schedule_create', 'schedule_edit']const SCHEDULE_TARGET_REFUSAL = 'A Bot’s scheduled tasks run in its own chat. Use target "this_session".'-const DELEGATION_REFUSAL = 'Bots do not start subagents or workflows. Do the work yourself, or hand it to another Bot with message_bot.'+const DELEGATION_REFUSAL = 'Bots do not start subagents, teammates or workflows. Do the work yourself, or hand it to another Bot with message_bot.'const MODE_PARAM = {type: 'string',enum: ROOM_MODES,diff --git a/ds-bot/test/blocking-question.test.js b/ds-bot/test/blocking-question.test.jsindex b80d4a84..2ad39a8d 100644--- a/ds-bot/test/blocking-question.test.js+++ b/ds-bot/test/blocking-question.test.js@@ -7,8 +7,9 @@ import { createRuntime } from '../index.js'import { fakeContext } from './fake-ctx.js'const QUESTION = 'ask_user_question'-const DELEGATION = ['subagent', 'subagent_fork', 'subagent_codex', 'subagent_claude_code', 'list_subagent_models', 'send_message', 'interrupt_agent', 'list_agents', 'workflow', 'ralph']-const DELEGATION_REFUSAL = 'Bots do not start subagents or workflows. Do the work yourself, or hand it to another Bot with message_bot.'+const AGENT_TEAMS = ['spawn_teammate', 'wait_agent', 'team_task_create', 'team_task_get', 'team_task_list', 'team_task_update']+const DELEGATION = ['subagent', 'subagent_fork', 'subagent_codex', 'subagent_claude_code', 'list_subagent_models', 'send_message', 'interrupt_agent', 'list_agents', 'workflow', 'ralph', ...AGENT_TEAMS]+const DELEGATION_REFUSAL = 'Bots do not start subagents, teammates or workflows. Do the work yourself, or hand it to another Bot with message_bot.'const team = () => ({version: 1,@@ -238,6 +239,18 @@ test('a Bot\'s chat and its group Sessions lose the delegation tools; other Sessassert.deepEqual(hidden.filter(([sessionId]) => sessionId === 'plain' || sessionId === 'elsewhere'), [])})+// Fei2411/DS-Bot#973: an admin started an Agent Teams teammate it could not message,+// list or stop; the teammate died and nobody heard of it. Agent Teams registers its+// tools in each Agent's own scope, where restrict() cannot reach them; the guard test+// below is what holds there.+test('a Bot\'s chat and its group Sessions mask the Agent Teams tools; other Sessions keep them', async (t) => {+ const { agentFor, hidden, stop } = await setup({ served: ['read', 'ask_user', 'send_message', 'list_agents', ...AGENT_TEAMS] })+ t.after(stop)+ for (const id of ['chief', 'room-writer', 'plain']) await agentFor(id)+ for (const id of ['chief', 'room-writer']) assert.deepEqual(hidden.filter(([sessionId]) => sessionId === id), [[id, ['send_message', 'list_agents', ...AGENT_TEAMS]]])+ assert.deepEqual(hidden.filter(([sessionId]) => sessionId === 'plain'), [])+})+test('the guard refuses the delegation tools in Bot Sessions only', async (t) => {const { guard, stop } = await setup()t.after(stop)@@ -298,6 +311,13 @@ test('Bot Sessions filter the hidden tools and their guidance out of the promptvariables: {},}))assert.deepEqual(current, { sections: [{ name: 'bot-identity' }], contexts: [], variables: {} })+ // Fei2411/DS-Bot#973: Agent Teams' Team Lead guidance goes too.+ const team = await filters[1].listener({}, {}, async () => ({+ sections: [{ name: 'bot-identity' }, { name: 'team:policy' }, { name: 'tool:spawn_teammate' }],+ contexts: [],+ variables: {},+ }))+ assert.deepEqual(team.sections.map(section => section.name), ['bot-identity'])// The computer-use filter keeps everything but the provider's own sections.const computer = await filters[0].listener({}, {}, async () => ({sections: [{ name: 'bot-identity' }, { name: 'computer-use:dsh-cua' }],