Skip to content

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

Stop Bots from starting DSH subagents and workflows

Fei2411c9b600ac139d
diff --git a/docs/plans/2026-10-10-bot-runtime.md b/docs/plans/2026-10-10-bot-runtime.md
index b6423262..5271ff47 100644
--- a/docs/plans/2026-10-10-bot-runtime.md
+++ b/docs/plans/2026-10-10-bot-runtime.md
@@ -1,7 +1,7 @@
# Bot 运行配置:预设、模型、思考强度、工作文件夹、能力
- 日期:2026-10-10 定预设和能力包,之后陆续补充
-- 相关:#99(思考强度)、#159(换模型不生效)、#208、#209(工作文件夹)
+- 相关:#99(思考强度)、#159(换模型不生效)、#208、#209(工作文件夹)、#798(Bot 不派子代理)
- 代码:`ds-bot/src/host/roster.js`、`models.js`、`folders.js`、`capabilities.js`、`permissions.js`,建 Bot 表单在 `src/client/bot-draft.js`
权限预设(只读 / 工作区内修改 / 完全权限)和群的统一权限见[角色与权限](2026-10-07-roles-and-permissions.md),这里不重复。
@@ -19,6 +19,8 @@
- 只有一个 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 同时干:`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)。
### 模型
@@ -62,7 +64,7 @@
## 不做什么
- 不预置分工 Bot(写手、程序员……)。只有一个默认 Bot,分工由用户和 Main Bot 来建。
-- 不改造 DSH 的标准 harness。
+- 不改造 DSH 的标准 harness:只拿掉上面说的、Bot 不用的工具。
- 不让 Bot 跟随用户在 DSH 里的「新任务默认」预设或默认模型。
## 已知限制
@@ -71,6 +73,7 @@
- `create_bot` 和 `update_bot` 还不能设思考强度,只能在界面上设(#99)。
- DSH 0.2.1-alpha 上,工作文件夹被删或改名后,消息会被吞掉、不会退回总工作区(#209)。
- 能力包「coding」「research」的具体组成还没定。
+- 委派工具按 DSH 的默认名字认;profile 里改了名(`toolName`)的认不出来。
## 变更
@@ -78,3 +81,4 @@
- 2026-10-14:新的 Bot 会话、群会话和分段显式用 `standard`,修好 PTC 预设下群聊不接力(#37)。
- 2026-10-19:Bot 用 DSH 的 `working_directory` 换到工作文件夹以外时,当作给自己设工作文件夹(同样的检查和批准),换到新的一段;在工作文件夹里面换只是走进去(#345)。
- 2026-10-20:用户能在设置里换总工作区;中文名「团队工作区」改叫「总工作区」(#364)。
+- 2026-11-01:Bot 不再派 DSH 子代理:委派工具和子代理控制工具不出现在 Bot 会话里,goal、workflow 的用法说明也从 Bot 的系统提示里去掉(#798)。
diff --git a/ds-bot/src/host/tools.js b/ds-bot/src/host/tools.js
index 27fdd2e1..b090109a 100644
--- a/ds-bot/src/host/tools.js
+++ b/ds-bot/src/host/tools.js
@@ -16,8 +16,17 @@ export const GROUP_REF = { type: 'string', required: true, description: 'Exact g
const BLOCKING_QUESTION_TOOL = 'ask_user_question'
// DS Bot carries no goal across conversation parts, so Bot Sessions do not run DSH goals.
const GOAL_TOOLS = ['create_goal', 'update_goal', 'get_goal']
-const HIDDEN_TOOLS = [BLOCKING_QUESTION_TOOL, ...GOAL_TOOLS]
+// 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']
+// 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'])
const GOAL_REFUSAL = 'DS Bot does not run goals. Ask the Bot in a message instead.'
+const DELEGATION_REFUSAL = 'Bots do not start subagents or workflows. Do the work yourself, or hand it to another Bot with message_bot.'
const MODE_PARAM = {
type: 'string',
enum: ROOM_MODES,
@@ -720,7 +729,7 @@ export function install(rt) {
// the live Agents back: a reload lifts their scope while they are still
// live, and agent/created does not fire for them again, so without the walk
// their next request would come without the team tools.
- /** @type {Map<string, {agent: any, relay: boolean, tools: boolean, restricted: boolean, disposers: Array<() => void>}>} */
+ /** @type {Map<string, {agent: any, relay: boolean, tools: boolean, restricted: boolean, filtered: boolean, disposers: Array<() => void>}>} */
const scoped = new Map()
const unscope = (id) => {
const held = scoped.get(id)
@@ -775,7 +784,7 @@ export function install(rt) {
failed.push(`${def.name}: ${error.message ?? error}`)
}
}
- held ??= { relay: relayOnly, tools: false, restricted: false, disposers: [] }
+ held ??= { relay: relayOnly, tools: false, restricted: false, filtered: false, disposers: [] }
held.agent = agent
held.relay = relayOnly
held.tools = true
@@ -784,10 +793,59 @@ export function install(rt) {
if (failed.length > 0) rt.warn('ds-bot: team tools not served to %s: %s', id, failed.join('; '))
}
+ // The standard preset registers `subagent` (model selection) in each Agent's own
+ // scope, where restrict() and a same-name section cannot reach it, so the Bot's
+ // assembly drops the hidden tools and their guidance instead. restrict still
+ // masks what it can, so lookup and execution stay aligned, and the guard
+ // refuses calls. The assembly filter goes on every Bot Session whether or not
+ // the tools are served yet: subagent's own agent/created listener can run
+ // after this one.
+ const filterBotAssembly = (agent, held) => {
+ if (held.filtered === true || typeof agent.ctx?.on !== 'function') return
+ const dispose = agent.ctx.on('system-prompt/assemble', async (_assembly, _context, next) => {
+ const assembled = await next()
+ return {
+ ...assembled,
+ tools: assembled.tools.filter(tool => !HIDDEN_TOOLS.includes(tool.name)),
+ sections: assembled.sections.filter(section => !HIDDEN_SECTIONS.has(section.name)),
+ }
+ })
+ held.filtered = true
+ if (typeof dispose === 'function') held.disposers.push(dispose)
+ }
+
+ // restrict() throws on a name this profile does not serve.
+ const maskHiddenTools = (agent, held, served) => {
+ const groups = HIDDEN_TOOL_GROUPS.map(group => group.filter(name => served.has(name))).filter(group => group.length > 0)
+ if (groups.length === 0) return
+ // Marked after one attempt even when a group fails, so a profile that can
+ // never mask it is not re-masked on every resolve.
+ held.restricted = true
+ for (const deny of groups) {
+ try {
+ const lift = agent.ctx.tools.restrict({ deny })
+ if (typeof lift === 'function') held.disposers.push(lift)
+ } catch {
+ // A name in the Agent's own scope fails the whole list (restrict() masks
+ // inherited tools only), so mask the rest one at a time; what stays is
+ // covered by the assembly filter and the guard.
+ for (const name of deny) {
+ try {
+ const lift = agent.ctx.tools.restrict({ deny: [name] })
+ if (typeof lift === 'function') held.disposers.push(lift)
+ } catch {
+ // Expected for names in the Agent's own scope.
+ }
+ }
+ }
+ }
+ }
+
// dsh's own question tool holds the turn open until the user answers, and every
// message from another Bot or a group round queues behind it. Bot Sessions ask
- // through ask_user instead, so the tool is taken out of their tool list, as are the
- // goal tools. The restrict is kept with the Session's scope, so it lifts with it.
+ // through ask_user instead, so it is taken out of their tool list, as are the goal
+ // and delegation tools. The restricts are kept with the Session's scope, so they
+ // lift with it.
const hideBotUnusedTools = (agent) => {
shareBotTools(agent)
const id = agent?.session?.id
@@ -795,35 +853,28 @@ export function install(rt) {
// the team lifts them like the rest, and the Agent can be scoped again.
const shadows = rt.shadowShells?.(agent) ?? []
if (shadows.length > 0) {
- const held = scoped.get(id) ?? { relay: false, tools: false, restricted: false, disposers: [] }
+ const held = scoped.get(id) ?? { relay: false, tools: false, restricted: false, filtered: false, disposers: [] }
held.agent = agent
held.disposers.push(...shadows)
scoped.set(id, held)
}
- if (agent === undefined || !rt.isBotSession(id) || scoped.get(id)?.restricted === true) return
- if (typeof agent.ctx?.tools?.restrict !== 'function') return
- try {
- // restrict() throws on a name this profile does not serve.
- const served = new Set(ctx.tools.schemas(agent).map(schema => schema.name))
- const deny = HIDDEN_TOOLS.filter(name => served.has(name))
- if (deny.length === 0) return
- const lift = agent.ctx.tools.restrict({ deny })
- const held = scoped.get(id) ?? { relay: false, tools: false, restricted: false, disposers: [] }
- held.agent = agent
- if (typeof lift === 'function') held.disposers.push(lift)
- held.restricted = true
- scoped.set(id, held)
- } catch (error) {
- rt.warn('ds-bot: %s stay in the tool list of %s: %s', HIDDEN_TOOLS.join(', '), id, error)
- }
+ if (agent === undefined || !rt.isBotSession(id)) return
+ const held = scoped.get(id) ?? { relay: false, tools: false, restricted: false, filtered: false, disposers: [] }
+ held.agent = agent
+ scoped.set(id, held)
+ filterBotAssembly(agent, held)
+ if (held.restricted === true || typeof agent.ctx?.tools?.restrict !== 'function') return
+ maskHiddenTools(agent, held, new Set(ctx.tools.schemas(agent).map(schema => schema.name)))
}
// A new Bot, part, or group Session gets its Agent before ds-bot records it, so the
// recording path resolves it again once the session is known as a Bot's; meanwhile
- // the guard refuses the question tool in any Bot Session, and a goal made there is
- // blocked.
- ctx.tools.guard(exec => (exec.name === BLOCKING_QUESTION_TOOL && rt.isBotSession(exec.agent?.id)
- ? `Bots cannot use ${BLOCKING_QUESTION_TOOL}. Ask with ask_user in your own chat, or ask in your reply.`
- : undefined))
+ // the guard refuses the question and delegation tools in any Bot Session, and a
+ // goal made there is blocked.
+ ctx.tools.guard((exec) => {
+ if (!rt.isBotSession(exec.agent?.id)) return undefined
+ if (exec.name === BLOCKING_QUESTION_TOOL) return `Bots cannot use ${BLOCKING_QUESTION_TOOL}. Ask with ask_user in your own chat, or ask in your reply.`
+ return DELEGATION_TOOLS.includes(exec.name) ? DELEGATION_REFUSAL : undefined
+ })
// Creation waits for this listener, so the Agent's first step already lacks the tool.
ctx.on('agent/created', async ({ agent }) => {
try {
diff --git a/ds-bot/test/blocking-question.test.js b/ds-bot/test/blocking-question.test.js
index ab789d8e..a85ae760 100644
--- a/ds-bot/test/blocking-question.test.js
+++ b/ds-bot/test/blocking-question.test.js
@@ -7,6 +7,8 @@ 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 team = () => ({
version: 1,
@@ -24,14 +26,17 @@ const team = () => ({
})
// dsh keeps one Agent per Session and fires agent/created, waiting for its listeners,
-// the first time a Session resolves one. restrict() calls are recorded per Session.
-async function setup({ served = ['read', 'ask_user', QUESTION], goals } = {}) {
+// the first time a Session resolves one. restrict() calls are recorded per Session and
+// throw when deny holds throwOn (a name in the Agent's own scope fails the whole list);
+// ctx.on() listeners are recorded per Session too, with their disposal.
+async function setup({ served = ['read', 'ask_user', QUESTION], goals, throwOn } = {}) {
const home = mkdtempSync(join(tmpdir(), 'ds-bot-blocking-question-'))
writeFileSync(join(home, 'state.json'), JSON.stringify(team()))
const ctx = fakeContext({ services: goals === undefined ? {} : { goals } })
const agents = new Map()
const hidden = []
const sent = []
+ const scopedListeners = []
let sessions = 0
const created = agent => Promise.all((ctx.listeners.get('agent/created') ?? []).map(listener => listener({ agent })))
const agentFor = async (id) => {
@@ -40,7 +45,18 @@ async function setup({ served = ['read', 'ask_user', QUESTION], goals } = {}) {
id,
session: { id },
ctx: {
- tools: { restrict: (filter) => { hidden.push([id, [...filter.deny]]); return () => {} } },
+ tools: {
+ restrict: (filter) => {
+ if (throwOn !== undefined && filter.deny.includes(throwOn)) throw new Error(`"${throwOn}" is registered in this scope`)
+ hidden.push([id, [...filter.deny]])
+ return () => {}
+ },
+ },
+ on: (event, listener) => {
+ const record = { sessionId: id, event, listener, disposed: false }
+ scopedListeners.push(record)
+ return () => { record.disposed = true }
+ },
effect: execute => execute(),
},
followup: message => sent.push({ sessionId: id, message }),
@@ -78,7 +94,7 @@ async function setup({ served = ['read', 'ask_user', QUESTION], goals } = {}) {
await ctx.dispose()
rmSync(home, { recursive: true, force: true, maxRetries: 5 })
}
- return { ctx, rt, agentFor, hidden, hiddenIn, guard, sent, stop }
+ return { ctx, rt, agentFor, hidden, hiddenIn, guard, sent, scopedListeners, stop }
}
// DSH's goal service, holding one goal per Session; block() records what was asked.
@@ -209,3 +225,68 @@ test('without DSH\'s goal service a goal change is left alone', async (t) => {
await new Promise(resolve => setTimeout(resolve, 20))
assert.deepEqual(warnings, [])
})
+
+// Fei2411/DS-Bot#798: a Bot could call dsh's delegation tools; the child agents they
+// start run out of the user's sight and die with the part that started them.
+test('a Bot\'s chat and its group Sessions lose the delegation tools; other Sessions keep them', async (t) => {
+ const servedDelegation = ['subagent', 'subagent_fork', 'list_subagent_models', 'send_message', 'interrupt_agent', 'list_agents', 'workflow']
+ const { agentFor, hidden, stop } = await setup({ served: ['read', 'ask_user', QUESTION, ...servedDelegation] })
+ t.after(stop)
+ for (const id of ['chief', 'writer', 'room-writer', 'plain', 'elsewhere']) await agentFor(id)
+ for (const id of ['chief', 'writer', 'room-writer']) assert.deepEqual(hidden.filter(([sessionId]) => sessionId === id), [[id, [QUESTION]], [id, servedDelegation]])
+ assert.deepEqual(hidden.filter(([sessionId]) => sessionId === 'plain' || sessionId === 'elsewhere'), [])
+})
+
+test('the guard refuses the delegation tools in Bot Sessions only', async (t) => {
+ const { guard, stop } = await setup()
+ t.after(stop)
+ for (const name of DELEGATION) {
+ for (const sessionId of ['chief', 'writer', 'room-writer']) assert.equal(guard(name, sessionId), DELEGATION_REFUSAL)
+ for (const sessionId of ['plain', 'elsewhere', undefined]) assert.equal(guard(name, sessionId), undefined)
+ }
+ assert.equal(guard('read', 'writer'), undefined)
+ assert.equal(guard('message_bot', 'writer'), undefined)
+})
+
+// restrict() throws away the whole list when one name sits in the Agent's own scope,
+// so each name is masked on its own after the group fails; what stays is covered by
+// the assembly filter and the guard.
+test('a delegation name restrict() cannot mask keeps the other masks and stays refused', async (t) => {
+ const { rt, agentFor, hidden, guard, stop } = await setup({ served: ['read', 'ask_user', QUESTION, 'subagent', 'send_message'], throwOn: 'send_message' })
+ t.after(stop)
+ const warnings = []
+ rt.warn = (...args) => warnings.push(args)
+ await agentFor('chief')
+ assert.deepEqual(hidden, [['chief', [QUESTION]], ['chief', ['subagent']]])
+ assert.deepEqual(warnings, [])
+ // The Session is marked anyway, so resolving it again adds no restrict entries.
+ await rt.resolveAgent('chief')
+ assert.deepEqual(hidden, [['chief', [QUESTION]], ['chief', ['subagent']]])
+ assert.equal(guard('send_message', 'chief'), DELEGATION_REFUSAL)
+})
+
+// The standard preset registers subagent (model selection) in the Agent's own scope,
+// which restrict() and a same-name section cannot reach, so Bot Sessions filter the
+// hidden tools and their guidance sections out of the assembled prompt instead.
+test('Bot Sessions filter the hidden tools and their guidance out of the prompt assembly', async (t) => {
+ const { rt, agentFor, scopedListeners, stop } = await setup({ served: ['read'] })
+ t.after(stop)
+ for (const id of ['chief', 'room-writer', 'plain']) await agentFor(id)
+ const filters = scopedListeners.filter(record => record.event === 'system-prompt/assemble')
+ assert.deepEqual(filters.map(record => record.sessionId), ['chief', 'room-writer'])
+ // Resolving the same Agent again adds no listener.
+ await rt.resolveAgent('chief')
+ assert.equal(scopedListeners.length, 2)
+ const filtered = await filters[0].listener({}, {}, async () => ({
+ sections: [{ name: 'bot-identity' }, { name: 'tool:goal' }, { name: 'tool:workflow' }, { name: 'tool:subagent' }, { name: 'tool:bash' }],
+ contexts: [{ name: 'x' }],
+ tools: [{ name: 'read' }, { name: 'subagent' }, { name: 'workflow' }, { name: 'send_message' }, { name: 'message_bot' }, { name: 'ask_user_question' }],
+ variables: { a: 1 },
+ }))
+ assert.deepEqual(filtered.sections.map(section => section.name), ['bot-identity', 'tool:bash'])
+ assert.deepEqual(filtered.tools.map(tool => tool.name), ['read', 'message_bot'])
+ assert.deepEqual(filtered.contexts, [{ name: 'x' }])
+ assert.deepEqual(filtered.variables, { a: 1 })
+ await stop()
+ for (const record of scopedListeners) assert.equal(record.disposed, true)
+})