A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Keep create_bot on a working model and renames with the Main Bot
lulu feizhua3be16c8f119
diff --git a/ds-bot/src/host/prompt.js b/ds-bot/src/host/prompt.jsindex 9309a3b3..6f89201d 100644--- a/ds-bot/src/host/prompt.js+++ b/ds-bot/src/host/prompt.js@@ -14,7 +14,7 @@ const TEAM_RULES = ['- Only for a direct user request in your own chat that needs several steps: write one short sentence of normal reply text before your first tool call, and make that tool call in the same response. Never start such a task with tools alone or end it with a promise. On long tasks, give brief factual updates only at meaningful milestones, then keep working.','- For "[Group chat …]", "[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.','- 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: role label, color, model, working folder, or instructions. Only a Main Bot can rename a Bot. 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 your final reply is posted when you finish. Any member can hand work to another with @Name, and the one that asked answers the result. 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.',diff --git a/ds-bot/src/host/tools.js b/ds-bot/src/host/tools.jsindex ffaf7827..3f797a8e 100644--- a/ds-bot/src/host/tools.js+++ b/ds-bot/src/host/tools.js@@ -175,7 +175,7 @@ export function install(rt) {role: { type: 'string', required: true, description: 'Two-to-four character role label shown under the name' },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 DSH default model.' },+ 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.' },work_dir: WORK_DIR_PARAM,},output,@@ -186,7 +186,12 @@ export function install(rt) {const workDir = args.work_dir ? await rt.cleanWorkDir(args.work_dir) : undefinedconst name = String(args.name ?? '').trim()await rt.approveFolder(exec, { path: workDir, who: { en: `the new Bot ${name}`, zh: `新 Bot ${name} ` } })- const bot = await rt.createBot({ ...args, workDir, createdBy: rt.selfOf(exec.agent.id) })+ // Without a named model the new Bot takes its creator's: the DSH default may be+ // a provider that has no key, and then the new Bot fails on its first reply.+ 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 })return `Created ${bot.name}${workDir ? `, working in ${workDir}` : ''}. It is greeting the user now.`} catch (error) {return `Could not create the Bot: ${error.message}`@@ -196,7 +201,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, working folder, or instructions. Every Bot may change itself except its name; only a Main Bot may rename a Bot or 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' },@@ -215,6 +220,8 @@ export function install(rt) {const bot = args.bot ? rt.findBot(args.bot) : callerif (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.'+ // A rename would let a Bot pass itself off as a Bot that does not exist.+ if (args.name !== undefined && String(args.name).trim() !== bot.name && !rt.isMain(self)) return 'Only a Main Bot can rename a Bot. When the user wants another Bot, ask a Main Bot with message_bot.'try {const { name: newName, role, instructions, color, model } = argsconst moving = typeof args.work_dir === 'string'diff --git a/ds-bot/test/update-bot.test.js b/ds-bot/test/update-bot.test.jsindex 1cc74699..efb97391 100644--- a/ds-bot/test/update-bot.test.js+++ b/ds-bot/test/update-bot.test.js@@ -59,15 +59,22 @@ function start() {test('a Bot changes itself by leaving out bot, or by naming itself', async (t) => {const { tool, state, stop } = start()t.after(stop)- assert.equal(await tool('update_bot', { name: 'King', instructions: 'Lead the team' }, 'b2'), 'Updated King.')- const king = state().bots.b2- assert.equal(king.name, 'King')- assert.equal(king.instructions, 'Lead the team')- // Its current name resolves to it again.- assert.equal(await tool('update_bot', { bot: 'King', role: '掌门' }, 'b2'), 'Updated King.')+ assert.equal(await tool('update_bot', { instructions: 'Lead the team' }, 'b2'), 'Updated Writer.')+ assert.equal(state().bots.b2.instructions, 'Lead the team')+ assert.equal(await tool('update_bot', { bot: 'Writer', role: '掌门', name: 'Writer' }, 'b2'), 'Updated Writer.')assert.equal(state().bots.b2.role, '掌门')})+test('only a Main Bot renames a Bot, so a Bot cannot pass itself off as another', async (t) => {+ const { tool, state, stop } = start()+ t.after(stop)+ assert.match(await tool('update_bot', { name: 'Editor', instructions: 'Edit' }, 'b2'), /^Only a Main Bot can rename a Bot/)+ assert.equal(state().bots.b2.name, 'Writer')+ assert.equal(state().bots.b2.instructions, '')+ assert.equal(await tool('update_bot', { bot: 'Writer', name: 'King' }, 'm1'), 'Updated King.')+ assert.equal(await tool('update_bot', { name: 'Boss' }, 'm1'), 'Updated Boss.')+})+test('a Bot cannot change another Bot; a Main Bot can', async (t) => {const { tool, state, stop } = start()t.after(stop)diff --git a/ds-bot/test/work-dir.test.js b/ds-bot/test/work-dir.test.jsindex c82ddf15..7a5b9cf9 100644--- a/ds-bot/test/work-dir.test.js+++ b/ds-bot/test/work-dir.test.js@@ -29,7 +29,7 @@ const TEAM = {// DSH_HOME, the team's data inside it, and a project folder beside it. Every Session// starts in the team workspace unless it is made with a cwd. `services` are what// ctx.get finds, such as the sandbox policy and approvals.-async function start({ services = {}, workspaces = [] } = {}) {+async function start({ services = {}, workspaces = [], llm, team: saved = TEAM } = {}) {// The native realpath, as fs/promises uses: on Windows the JS one keeps 8.3 short names.const root = realpathSync.native(mkdtempSync(join(tmpdir(), 'ds-bot-work-dir-')))const dsh = join(root, 'dsh')@@ -37,7 +37,7 @@ async function start({ services = {}, workspaces = [] } = {}) {const team = join(home, 'workspace')const project = join(root, 'project')for (const dir of [team, project]) mkdirSync(dir, { recursive: true })- writeFileSync(join(home, 'state.json'), JSON.stringify(TEAM))+ writeFileSync(join(home, 'state.json'), JSON.stringify(saved))const previousHome = process.env.DSH_HOMEprocess.env.DSH_HOME = dsh@@ -66,7 +66,7 @@ async function start({ services = {}, workspaces = [] } = {}) {}const registry = new Map([['w1', { id: 'w1', path: team, title: 'DS Bot' }], ...workspaces.map(workspace => [workspace.id, workspace])])Object.assign(ctx, {- llm: { listProviders: () => [], listModels: async () => [], resolveModelInfo: async () => ({}) },+ llm: llm ?? { listProviders: () => [], listModels: async () => [], resolveModelInfo: async () => ({}) },workspaceRegistry: {get: id => registry.get(id),list: () => [...registry.values()],@@ -379,3 +379,23 @@ test('the folder menu browses through the DSH folder picker', async (t) => {function rootless() {return join(tmpdir(), `ds-bot-work-dir-none-${process.pid}`)}++test('a Bot the Main Bot creates runs on its creator\'s model unless one is named', async (t) => {+ // The DSH default is a provider without a key; the Main Bot runs on one that works.+ const providers = { deepseek: ['v4'], official: ['pro'] }+ const env = await start({+ services: { agentDefaultModel: { currentSelection: () => ({ provider: 'official', model: 'pro' }) } },+ team: { ...TEAM, bots: { ...TEAM.bots, a: { ...TEAM.bots.a, model: 'deepseek/v4' } } },+ llm: {+ listProviders: () => Object.keys(providers).map(id => ({ id, name: id })),+ listModels: async id => providers[id].map(model => ({ id: model })),+ resolveModelInfo: async () => ({}),+ },+ })+ t.after(env.stop)+ const made = name => Object.values(env.state().bots).find(bot => bot.name === name)+ assert.equal(await env.tool('create_bot', { name: 'Editor', role: 'Edit', instructions: 'Edit' }, 'a'), 'Created Editor. It is greeting the user now.')+ assert.equal(made('Editor').model, 'deepseek/v4')+ assert.equal(await env.tool('create_bot', { name: 'Tester', role: 'Test', instructions: 'Test', model: 'official/pro' }, 'a'), 'Created Tester. It is greeting the user now.')+ assert.equal(made('Tester').model, 'official/pro')+})