A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Run a fresh part on the Bot's model, also when it changes during the handoff
Fei2411fdaad8e6b8a9
diff --git a/ds-bot/src/host/parts.js b/ds-bot/src/host/parts.jsindex f20643eb..12ad5510 100644--- a/ds-bot/src/host/parts.js+++ b/ds-bot/src/host/parts.js@@ -720,6 +720,18 @@ export function install(rt) {}}+ // A fresh part runs on the Bot's model. The earlier part's route is what its last+ // request used, which misses a model the user picked since, so it counts only for a+ // Bot without a model of its own.+ async function freshRoute(bot, session) {+ const ref = await rt.desiredModel(bot)+ if (ref !== undefined) return { ref, effort: await rt.desiredEffort(bot, ref) }+ const route = session.requestHeader()?.config+ return route?.provider && route?.model ? { ref: `${route.provider}/${route.model}`, effort: route.reasoningEffort } : undefined+ }+ const selectRoute = (bot, sessionId, { ref, effort }) => rt.selectSessionModel(sessionId, { ...splitRef(ref), ...(effort === undefined ? {} : { reasoningEffort: effort }) })+ .catch(error => rt.warn('ds-bot: model for the fresh part of %s not applied: %s', bot.name, error))+async function moveOn(agent, job, signal) {job.started = trueconst bot = rt.botOf(job.botId)@@ -764,13 +776,8 @@ export function install(rt) {const dir = rt.workDirOf(job)const intended = dir !== undefined && await rt.isFolder(dir) ? dir : rt.teamFolder()const freshId = await rt.createSession(room ? `${bot.name} · ${room.name}` : bot.name, { dir })- const route = session.requestHeader()?.config- const ref = route?.provider && route?.model ? `${route.provider}/${route.model}` : await rt.desiredModel(bot)- if (ref !== undefined) {- const effort = route?.reasoningEffort ?? await rt.desiredEffort(bot, ref)- await rt.selectSessionModel(freshId, { ...splitRef(ref), ...(effort === undefined ? {} : { reasoningEffort: effort }) })- .catch(error => rt.warn('ds-bot: model for the fresh part of %s not applied: %s', bot.name, error))- }+ const picked = await freshRoute(bot, session)+ if (picked !== undefined) await selectRoute(bot, freshId, picked)await rt.applyPermission(bot, freshId, room).catch(error => rt.warn('ds-bot: permission for the fresh part of %s not applied: %s', bot.name, error))const segment = { sessionId: agent.id, endedAt: Date.now(), ...(tokens !== undefined ? { tokens } : {}), ...noted }@@ -790,6 +797,10 @@ export function install(rt) {}}await rt.save()+ // A model the user picked until now went to the earlier part, which was still the+ // Bot's; from here on a change goes to the fresh one.+ const now = await freshRoute(bot, session)+ if (now !== undefined && (now.ref !== picked?.ref || now.effort !== picked?.effort)) await selectRoute(bot, freshId, now)if (job.failed !== undefined) rescued.set(freshId, job.bare ? 'bare' : 'carried')void rt.moveSchedules(agent.id, freshId)job.moved = truediff --git a/ds-bot/test/work-dir.test.js b/ds-bot/test/work-dir.test.jsindex 8cb98a1e..b4dd6d66 100644--- a/ds-bot/test/work-dir.test.js+++ b/ds-bot/test/work-dir.test.js@@ -443,3 +443,58 @@ test('a Bot the Main Bot creates runs on its creator\'s model unless one is nameassert.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')})++// 公开#159: the fresh part took the model of the earlier part's last request, so a model+// the user picked during the handoff never reached it, nor any part after it.+const MODELS = {+ listProviders: () => [{ id: 'deepseek', name: 'DeepSeek' }],+ listModels: async () => [{ id: 'flash' }, { id: 'v4-pro' }],+ resolveModelInfo: async () => ({}),+}+const onModel = (model, appliedModel = model) => ({ ...TEAM, bots: { ...TEAM.bots, b: { ...TEAM.bots.b, model, appliedModel } } })+const recordSelections = (env) => {+ const selected = []+ env.ctx.sessionController.selectModel = async (request) => { selected.push([request.sessionId, request.model]) }+ // The earlier part's last request went to flash.+ env.agentOf('b').session.requestHeader = () => ({ config: { provider: 'deepseek', model: 'flash' } })+ return selected+}++test('a fresh part runs on the Bot\'s model, not on the earlier part\'s last request', async (t) => {+ const env = await start({ llm: MODELS, team: onModel('deepseek/v4-pro') })+ t.after(env.stop)+ const selected = recordSelections(env)+ assert.equal((await env.call('update-bot', { id: 'b', workDir: env.project })).ok, true)+ await until(() => env.state().bots.b.sessionId === 's1')+ await until(() => handoffOf(env.agentOf('s1')) !== undefined)+ assert.deepEqual(selected.filter(([sessionId]) => sessionId === 's1'), [['s1', 'v4-pro']])+})++test('a model the user picks while the fresh part is made reaches the fresh part', async (t) => {+ const env = await start({ llm: MODELS, team: onModel('deepseek/flash') })+ t.after(env.stop)+ const selected = recordSelections(env)+ const select = env.ctx.sessionController.selectModel+ env.ctx.sessionController.selectModel = async (request) => {+ await select(request)+ if (request.sessionId !== 's1' || selected.length > 1) return+ // The user switches models after the fresh part got the old one, before it is the Bot's.+ void env.call('update-bot', { id: 'b', model: 'deepseek/v4-pro' })+ await until(() => env.state().bots.b.model === 'deepseek/v4-pro')+ }+ assert.equal((await env.call('update-bot', { id: 'b', workDir: env.project })).ok, true)+ await until(() => env.state().bots.b.sessionId === 's1')+ await until(() => selected.some(([sessionId, model]) => sessionId === 'b' && model === 'v4-pro'))+ await until(() => handoffOf(env.agentOf('s1')) !== undefined)+ assert.deepEqual(selected.filter(([sessionId]) => sessionId === 's1'), [['s1', 'flash'], ['s1', 'v4-pro']])+})++test('a Bot without a model of its own goes on with the earlier part\'s route', async (t) => {+ const env = await start({ llm: MODELS })+ t.after(env.stop)+ const selected = recordSelections(env)+ assert.equal((await env.call('update-bot', { id: 'b', workDir: env.project })).ok, true)+ await until(() => env.state().bots.b.sessionId === 's1')+ await until(() => handoffOf(env.agentOf('s1')) !== undefined)+ assert.deepEqual(selected.filter(([sessionId]) => sessionId === 's1'), [['s1', 'flash']])+})