Skip to content

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

Let create_bot and update_bot set a Bot's thinking level

Fei24118416941f9572
diff --git a/ds-bot/src/host/prompt.js b/ds-bot/src/host/prompt.js
index 917012d1..232cad39 100644
--- a/ds-bot/src/host/prompt.js
+++ b/ds-bot/src/host/prompt.js
@@ -15,7 +15,7 @@ const TEAM_RULES = [
'- For "[Message from …]" or "[Reply from …]" messages, do not write plans or progress updates: use tools silently, then reply with the answer. Simple answers do not need progress messages.',
'- In a group chat, the group sees what you write while you work, not only your final reply. For work that takes more than a quick look, start with one short sentence on what you will do, in the same response as your first tool call. After that, write only when you find something the group should know or finish a part of the work, in a sentence or two, not at every step. End with the result. Simple answers need no updates.',
'- Offer choices with ask_user (a tap-to-answer card) instead of long option lists in text. Calling it ends your turn at once, so write everything you want to say before the call, in the same reply. The answer arrives as the user\'s next message.',
- '- update_bot changes your own settings: name, role label, color, model, working folder, or instructions. Leave out bot to change yourself. Use it when the user asks you to change how you are set up, for example to work in a project folder (work_dir, a full path). Only a Main Bot can change other Bots; when another Bot needs changing, ask a Main Bot.',
+ '- update_bot changes your own settings: name, role label, color, model, thinking level, working folder, or instructions. Leave out bot to change yourself. Use it when the user asks you to change how you are set up, for example to work in a project folder (work_dir, a full path). Only a Main Bot can change other Bots; when another Bot needs changing, ask a Main Bot.',
'- You may be in group chats with the user and other Bots. You speak in each group from a separate conversation of yours, apart from your own chat with the user. There your turn arrives as a "[Group chat …]" message that shows the speaking order, and your reply is posted to the group. When someone there asks you to do something, do the work in that turn: the group goes on without waiting and sees what you write as you go. Any member can hand work to another with @Name, and the one that asked answers the result. Work for a group stays in it: there message_bot reaches only members of that group, as @Name does. In a group, read_own_chat shows your own chat (the group sees that you looked; share only what the group needs). In your own chat, read_group_chat shows what was said in a group. A group may have an admin, who steers it: the admin can call members with @Name, change the group with update_group, and start a new discussion there with post_to_group.',
'- When you need a key, token, or password, call request_secret: the user types it into a secure card and you never see it. Never ask the user to paste one into the chat. Use it through its environment variable ($DSH_SECRET_<NAME> in bash, $env:DSH_SECRET_<NAME> in PowerShell) and never print it. list_secrets shows which keys exist.',
'- web_search results say which search backend answered. If web_search fails, never guess URLs or present pages you remember as search results: use a browser tool if you have one, otherwise tell the user that search is unavailable and the reason it gave.',
@@ -30,8 +30,8 @@ const MAIN_RULES = [
'- After creating a Bot, tell the user in one line that it is ready, using its exact name.',
'- Route work to the right Bot: one Bot\'s task with message_bot, a group\'s task with post_to_group (or @Name when you speak in that group). Send each task one way only, then tell the user what you asked and that you will report back.',
'- If a Bot does not heed your message and must not finish what it is doing, stop_bot ends its turn at once and tells it why; the reply comes back to you.',
- '- Every Bot runs on one model of its own (list_bots shows it). Pass model to create_bot or update_bot only when the user names one; list_models gives the provider/model refs.',
- '- Use update_bot to rename a Bot, change its role, color, model, working folder, or instructions when the user asks.',
+ '- Every Bot runs on one model of its own (list_bots shows it). Pass model or a thinking level (effort) to create_bot or update_bot only when the user names one; list_models gives the provider/model refs and, for a model in use, the thinking levels it serves.',
+ '- Use update_bot to rename a Bot, change its role, color, model, thinking level, working folder, or instructions when the user asks.',
'- You run the group chats too. create_group makes a group (you join it as its admin unless you name another); update_group changes any group\'s name, notice, members, admin, reply mode, or the folder every member works in there; post_to_group posts into any group as you, which starts a round of replies the user reads there; delete_group archives a group, only when the user asks. list_bots shows every group.',
'- The team can have more than one Main Bot; list_bots marks them. They share these powers; message them only when your work overlaps theirs.',
].join('\n')
diff --git a/ds-bot/src/host/roster.js b/ds-bot/src/host/roster.js
index 1475afeb..706a8c86 100644
--- a/ds-bot/src/host/roster.js
+++ b/ds-bot/src/host/roster.js
@@ -108,7 +108,10 @@ export function install(rt) {
const cleanAvatarValue = cleanAvatar(avatar)
// The model is fixed at creation, so a later change of the DSH default leaves it alone.
const modelRef = model ? await rt.resolveModel(model) : pickModel ? undefined : await rt.defaultModel()
- const effortId = modelRef !== undefined && effort !== undefined ? await rt.resolveEffort(modelRef, effort) : undefined
+ // A thinking level needs a model to resolve against; with none it would be dropped
+ // silently, so the create fails before a Session is made.
+ if (effort !== undefined && effort !== '' && modelRef === undefined) throw new Error('Pick a model before choosing a thinking level')
+ const effortId = modelRef === undefined ? undefined : await rt.resolveEffort(modelRef, effort)
const dir = workDir === undefined || workDir === null ? undefined : await rt.cleanWorkDir(workDir)
const id = await createSession(cleanName, { dir })
try {
@@ -206,9 +209,24 @@ export function install(rt) {
async function updateBot(id, patch) {
const bot = rt.botOf(id)
if (bot === undefined) throw new Error('Unknown Bot')
- // Checked first, so a folder that does not pass leaves the rest unchanged too.
+ // Checked first, so a folder, model or level that does not pass leaves the rest
+ // unchanged too.
const moving = patch.workDir !== undefined
const workDir = moving ? await rt.cleanWorkDir(patch.workDir ?? '') : undefined
+ const modelRef = patch.model === undefined ? undefined
+ : patch.model === null || patch.model === '' ? null
+ : await rt.resolveModel(patch.model)
+ // A new level resolves against the model the Bot will run on: the new one, the
+ // model it keeps, or — the model cleared — the one it last ran on.
+ const effortRef = modelRef === undefined ? bot.model ?? bot.appliedModel : modelRef ?? bot.appliedModel
+ let effortId
+ if (patch.effort !== undefined) {
+ if (patch.effort === null || patch.effort === '') effortId = null
+ else {
+ if (effortRef === undefined) throw new Error('Pick a model before choosing a thinking level')
+ effortId = await rt.resolveEffort(effortRef, patch.effort)
+ }
+ }
if (patch.name !== undefined) {
const next = String(patch.name).trim().slice(0, 40)
const clash = rt.findBot(next)
@@ -235,17 +253,13 @@ export function install(rt) {
else delete bot.avatar
}
if (patch.model !== undefined) {
- if (patch.model === null || patch.model === '') delete bot.model
- else bot.model = await rt.resolveModel(patch.model)
+ if (modelRef === null) delete bot.model
+ else bot.model = modelRef
modelChanged = true
}
if (patch.effort !== undefined) {
- if (patch.effort === null || patch.effort === '') delete bot.effort
- else {
- const ref = bot.model ?? bot.appliedModel
- if (ref === undefined) throw new Error('Pick a model before choosing a thinking level')
- bot.effort = await rt.resolveEffort(ref, patch.effort)
- }
+ if (effortId === null) delete bot.effort
+ else bot.effort = effortId
modelChanged = true
}
if (patch.permission !== undefined) await rt.setPermission(bot, patch.permission)
diff --git a/ds-bot/src/host/tools.js b/ds-bot/src/host/tools.js
index dcd264ad..fd927167 100644
--- a/ds-bot/src/host/tools.js
+++ b/ds-bot/src/host/tools.js
@@ -248,6 +248,7 @@ export function install(rt) {
instructions: { type: 'string', required: true, description: 'What this Bot is responsible for and how it should work' },
brief: { type: 'string', description: 'Why the user wants it, passed to the new Bot as its first context' },
model: { type: 'string', description: 'Model the Bot runs on, as provider/model or a model id. Only when the user names one; otherwise the model you run on.' },
+ effort: { type: 'string', description: 'Thinking level for the model, as list_models shows it. Only when the user names one.' },
work_dir: WORK_DIR_PARAM,
},
output,
@@ -263,7 +264,7 @@ export function install(rt) {
const creator = callerBot(exec)
const served = creator?.model && (await rt.catalog()).some(entry => entry.ref === creator.model)
const model = args.model || (served ? creator.model : undefined)
- const bot = await rt.createBot({ ...args, model, workDir, createdBy: creator?.id })
+ const bot = await rt.createBot({ ...args, model, workDir, effort: args.effort, createdBy: creator?.id })
return `Created ${bot.name}${workDir ? `, working in ${workDir}` : ''}. It is greeting the user now.`
} catch (error) {
return `Could not create the Bot: ${error.message}`
@@ -273,7 +274,7 @@ export function install(rt) {
ctx.tools.register(defineTool({
name: 'update_bot',
- description: 'Change a Bot\'s name, role, color, model, working folder, or instructions. Every Bot may change itself; only a Main Bot may change another Bot.',
+ description: 'Change a Bot\'s name, role, color, model, thinking level, working folder, or instructions. Every Bot may change itself; only a Main Bot may change another Bot.',
parameters: {
bot: { type: 'string', description: 'Current name of the Bot to change; leave out to change yourself' },
name: { type: 'string', description: 'New name' },
@@ -281,6 +282,7 @@ export function install(rt) {
instructions: { type: 'string', description: 'Replacement instructions' },
color: { type: 'string', description: `One of ${[...COLORS, ...EXTRA_COLORS].join(', ')}` },
model: { type: 'string', description: 'Move the Bot to another model, as provider/model or a model id' },
+ effort: { type: 'string', description: 'Thinking level for the Bot\'s model, as list_models shows; an empty string returns to the model\'s default' },
work_dir: { ...WORK_DIR_PARAM, description: `${WORK_DIR_PARAM.description}; an empty string returns it to the team workspace` },
},
output,
@@ -293,11 +295,11 @@ export function install(rt) {
if (bot === undefined) return `No Bot named ${args.bot}.`
if (bot.id !== caller.id && !rt.isMain(self)) return 'Only a Main Bot can change another Bot. Leave out bot to change yourself, or ask a Main Bot with message_bot.'
try {
- const { name: newName, role, instructions, color, model } = args
+ const { name: newName, role, instructions, color, model, effort } = args
const moving = typeof args.work_dir === 'string'
const workDir = moving ? await rt.cleanWorkDir(args.work_dir) : undefined
if (moving && workDir !== bot.workDir) await rt.approveFolder(exec, { path: workDir, sessions: rt.sessionsOfBot(bot.id), who: { en: bot.name, zh: ` ${bot.name} ` } })
- const next = await rt.updateBot(bot.id, { name: newName, role, instructions, color, ...(model ? { model } : {}), ...(moving ? { workDir: workDir ?? '' } : {}) })
+ const next = await rt.updateBot(bot.id, { name: newName, role, instructions, color, ...(model ? { model } : {}), ...(effort === undefined ? {} : { effort }), ...(moving ? { workDir: workDir ?? '' } : {}) })
if (!moving) return `Updated ${next.name}.`
const folder = workDir ?? 'the team workspace'
return bot.id === caller.id ? `Updated ${next.name}. From your next step on, you work in ${folder}.` : `Updated ${next.name}. It now works in ${folder}.`
@@ -309,14 +311,20 @@ export function install(rt) {
ctx.tools.register(defineTool({
name: 'list_models',
- description: 'List the models a Bot can run on, as provider/model refs for create_bot and update_bot.',
+ description: 'List the models a Bot can run on, as provider/model refs for create_bot and update_bot. A model in use also lists the thinking levels it serves.',
parameters: {},
output,
async execute() {
- const models = await rt.catalog()
+ const models = await rt.catalog({ fresh: true })
if (models.length === 0) return 'No models are configured. Ask the user to add one in Settings → Models.'
const fallback = rt.defaultRef()
- return models.map(entry => `- ${entry.ref}${entry.name !== entry.id ? ` (${entry.name})` : ''}${entry.input?.includes('image') ? ', reads images' : ''}${entry.ref === fallback ? ', default' : ''}`).join('\n')
+ // Only catalog entries that already carry `reasoning` (models a Bot runs on)
+ // show levels; asking every model for its levels would take a call each.
+ return models.map((entry) => {
+ const levels = entry.reasoning?.efforts?.map(effort => effort.id) ?? []
+ const thinking = levels.length > 0 ? `, thinking: ${levels.join(', ')}${entry.reasoning.defaultEffort === undefined ? '' : ` (default: ${entry.reasoning.defaultEffort})`}` : ''
+ return `- ${entry.ref}${entry.name !== entry.id ? ` (${entry.name})` : ''}${entry.input?.includes('image') ? ', reads images' : ''}${entry.ref === fallback ? ', default' : ''}${thinking}`
+ }).join('\n')
},
}))
diff --git a/ds-bot/test/roster.test.js b/ds-bot/test/roster.test.js
index 2362ec0f..6dc8cde5 100644
--- a/ds-bot/test/roster.test.js
+++ b/ds-bot/test/roster.test.js
@@ -639,3 +639,127 @@ test('a create that fails lets its name go', async (t) => {
ctx.sessionController.create = create
assert.equal((await call('create-bot', { name: 'Coder' })).ok, true)
})
+
+// #99: the team tools take a Bot's thinking level. `effort` is optional, an empty
+// string returns to the model's default, and a level the model does not serve is
+// refused before anything about the Bot changes.
+const TOOL_REASONING = {
+ 'deepseek/deepseek-v4-flash': { reasoning: { efforts: [{ id: 'low', name: 'Low' }, { id: 'high', name: 'High' }], defaultEffort: 'high' } },
+}
+
+test('create_bot and update_bot advertise an optional thinking level without a fixed enum', async (t) => {
+ const { ctx, stop } = start(undefined, { models: ['deepseek-v4-flash'] })
+ t.after(stop)
+ for (const name of ['create_bot', 'update_bot']) {
+ const schema = ctx.registeredTools.get(name).parameters
+ assert.equal(schema.properties.effort?.type, 'string')
+ assert.equal(schema.required?.includes('effort') ?? false, false)
+ assert.equal(schema.properties.effort.enum, undefined)
+ }
+})
+
+test('update_bot sets, keeps and clears the thinking level', async (t) => {
+ const { ctx, call, stop, selected, sent } = start(undefined, { models: ['deepseek-v4-flash'], reasoning: TOOL_REASONING })
+ t.after(stop)
+ const chief = (await call('state', {})).value.mainBotId
+ const writer = (await call('create-bot', { name: 'Writer' })).value
+ await until(() => sent.some(entry => entry.sessionId === writer.id))
+ const tool = args => ctx.registeredTools.get('update_bot').execute({ bot: 'Writer', ...args }, { agent: { id: chief } })
+ const current = async () => (await call('state', {})).value.bots.find(bot => bot.id === writer.id)
+
+ assert.equal(await tool({ effort: 'low' }), 'Updated Writer.')
+ assert.equal((await current()).effort, 'low')
+ await until(() => selected.at(-1)?.sessionId === writer.id && selected.at(-1).reasoningEffort === 'low')
+
+ // Left out, the pick is kept; an empty string returns to the model's default.
+ assert.equal(await tool({ instructions: 'Be concise' }), 'Updated Writer.')
+ assert.equal((await current()).effort, 'low')
+ assert.equal(await tool({ effort: '' }), 'Updated Writer.')
+ assert.equal((await current()).effort, undefined)
+})
+
+test('update_bot checks a level against the model it names, and a failure changes nothing', async (t) => {
+ const reasoning = {
+ ...TOOL_REASONING,
+ 'deepseek/other': { reasoning: { efforts: [{ id: 'medium', name: 'Medium' }] } },
+ }
+ const { ctx, call, stop, selected, sent } = start(undefined, { models: ['deepseek-v4-flash', 'other'], reasoning })
+ t.after(stop)
+ const chief = (await call('state', {})).value.mainBotId
+ const writer = (await call('create-bot', { name: 'Writer', model: 'deepseek/deepseek-v4-flash', effort: 'low' })).value
+ await until(() => sent.some(entry => entry.sessionId === writer.id))
+ const tool = args => ctx.registeredTools.get('update_bot').execute({ bot: 'Writer', ...args }, { agent: { id: chief } })
+ const current = async () => (await call('state', {})).value.bots.find(bot => bot.id === writer.id)
+
+ // Model and level together resolve the level against the new model.
+ assert.equal(await tool({ model: 'deepseek/other', effort: 'medium' }), 'Updated Writer.')
+ assert.equal((await current()).model, 'deepseek/other')
+ assert.equal((await current()).effort, 'medium')
+ await until(() => selected.at(-1)?.sessionId === writer.id && selected.at(-1).reasoningEffort === 'medium')
+
+ // A level the new model does not serve leaves name, model and level as they were.
+ assert.match(await tool({ name: 'Renamed', model: 'deepseek/deepseek-v4-flash', effort: 'bogus' }), /^Could not update the Bot: Thinking level bogus is not available/)
+ assert.equal((await current()).name, 'Writer')
+ assert.equal((await current()).model, 'deepseek/other')
+ assert.equal((await current()).effort, 'medium')
+ // A level the kept model does not serve fails the same way.
+ assert.match(await tool({ effort: 'low' }), /^Could not update the Bot: Thinking level low is not available/)
+ assert.equal((await current()).effort, 'medium')
+ // A model that is not served fails before anything changes too.
+ assert.match(await tool({ name: 'Renamed', model: 'deepseek/nothing' }), /^Could not update the Bot: Model deepseek\/nothing is not available/)
+ assert.equal((await current()).name, 'Writer')
+})
+
+test('create_bot stores a named thinking level and refuses one without a model', async (t) => {
+ const { ctx, call, stop, sent } = start(undefined, { models: ['deepseek-v4-flash'], reasoning: TOOL_REASONING })
+ t.after(stop)
+ const chief = (await call('state', {})).value.mainBotId
+ const exec = { agent: { id: chief } }
+ const create = args => ctx.registeredTools.get('create_bot').execute(args, exec)
+ assert.match(await create({ name: 'Writer', role: 'Write', instructions: 'Write clearly', model: 'deepseek/deepseek-v4-flash', effort: 'low' }), /^Created Writer/)
+ const writer = (await call('state', {})).value.bots.find(bot => bot.name === 'Writer')
+ assert.equal(writer.model, 'deepseek/deepseek-v4-flash')
+ assert.equal(writer.effort, 'low')
+ await until(() => sent.some(entry => entry.sessionId === writer.id))
+ // A level the model does not serve leaves no Bot behind.
+ assert.match(await create({ name: 'Phantom', role: 'Write', instructions: 'Write', model: 'deepseek/deepseek-v4-flash', effort: 'bogus' }), /^Could not create the Bot: Thinking level bogus is not available/)
+ assert.equal((await call('state', {})).value.bots.some(bot => bot.name === 'Phantom'), false)
+})
+
+test('create_bot with a level but no resolvable model fails before a Session is made', async (t) => {
+ // No models are served, so no model can be resolved and an effort has nothing to
+ // resolve against.
+ const { ctx, call, stop } = start(undefined, { models: [] })
+ t.after(stop)
+ const chief = (await call('state', {})).value.mainBotId
+ let created = 0
+ const create = ctx.sessionController.create
+ ctx.sessionController.create = async (...args) => { created += 1; return create(...args) }
+ const answer = await ctx.registeredTools.get('create_bot').execute({ name: 'Phantom', role: 'Write', instructions: 'Write', effort: 'low' }, { agent: { id: chief } })
+ assert.match(answer, /^Could not create the Bot: Pick a model before choosing a thinking level/)
+ assert.equal(created, 0)
+ assert.equal((await call('state', {})).value.bots.some(bot => bot.name === 'Phantom'), false)
+})
+
+test('a non-Main Bot still cannot change another Bot\u2019s thinking level', async (t) => {
+ const { ctx, call, stop, sent } = start(undefined, { models: ['deepseek-v4-flash'], reasoning: TOOL_REASONING })
+ t.after(stop)
+ await call('state', {})
+ const writer = (await call('create-bot', { name: 'Writer', model: 'deepseek/deepseek-v4-flash', effort: 'high' })).value
+ await until(() => sent.some(entry => entry.sessionId === writer.id))
+ const exec = { agent: { id: writer.id } }
+ assert.match(await ctx.registeredTools.get('update_bot').execute({ bot: 'Chief', effort: 'low' }, exec), /^Only a Main Bot can change another Bot/)
+ // Its own level it may change.
+ assert.equal(await ctx.registeredTools.get('update_bot').execute({ effort: 'low' }, exec), 'Updated Writer.')
+ assert.equal((await call('state', {})).value.bots.find(bot => bot.id === writer.id).effort, 'low')
+})
+
+test('list_models names the thinking levels of the models a Bot runs on', async (t) => {
+ const { ctx, call, stop } = start(undefined, { models: ['deepseek-v4-flash', 'plain'], reasoning: TOOL_REASONING })
+ t.after(stop)
+ const chief = (await call('state', {})).value.mainBotId
+ await call('update-bot', { id: chief, model: 'deepseek/deepseek-v4-flash' })
+ const result = await ctx.registeredTools.get('list_models').execute({}, { agent: { id: chief } })
+ assert.match(result, /deepseek\/deepseek-v4-flash.*thinking: low, high \(default: high\)/)
+ assert.doesNotMatch(result.split('\n').find(line => line.includes('deepseek/plain')), /thinking/)
+})