A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.
Fall back to the default model for memory panel calls
Fei2411fd0d7519e262
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex be0739b5..f7906d69 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -4,6 +4,10 @@ All notable changes to DS Bot are listed here. The format follows [Keep a Change## [Unreleased]+### Fixed++- The memory panel's summary, its "ask or update" and the memory review no longer stop when the Bot's model refuses the call or runs out of output budget: they try once more on the profile's default model. After you change the Bot's model, a failed summary is written again automatically. ([#116](https://github.com/Fei2411/DeepSeek-Bot/issues/116))+## [0.1.4] - 2026-10-13### Addeddiff --git a/ds-bot/src/host/memory.js b/ds-bot/src/host/memory.jsindex aee6322d..4e4cf91f 100644--- a/ds-bot/src/host/memory.js+++ b/ds-bot/src/host/memory.js@@ -936,6 +936,25 @@ export function install(rt) {throw new Error(`The model's reasoning used up the output budget (${SUMMARY_MAX_TOKENS} and ${SUMMARY_RETRY_MAX_TOKENS} tokens); no complete answer was written`)}+ // A served model can still refuse the call (a key without access, say), and+ // desiredModel only falls back for models that are not served; so a failed call+ // is tried once more on the profile default.+ async function botShot(bot, system, text, tag) {+ const own = await modelFor(bot)+ try {+ return await oneShot(own, system, text, tag)+ } catch (error) {+ const fallback = splitRef(await rt.defaultModel())+ if (fallback === undefined || (fallback.provider === own.provider && fallback.model === own.model)) throw error+ try {+ return await oneShot(fallback, system, text, tag)+ } catch (again) {+ const said = failure => failure?.message ?? String(failure)+ throw new Error(`${own.provider}/${own.model}: ${said(error)}; ${fallback.provider}/${fallback.model}: ${said(again)}`)+ }+ }+ }+/** @type {Map<string, {hash:string, text:string, at:number}>} */const summaries = new Map()const summarizing = new Map()@@ -955,21 +974,23 @@ export function install(rt) {const linesFor = files => allEntries(files).map(entry => `- ${entry.file.topic ? `[[${entry.file.topic}]] ` : ''}${entry.text}`)function startSummary(bot, own, team, language, hash) {+ const model = bot.modelconst job = (async () => {- const text = await oneShot(await modelFor(bot), SUMMARY_SYSTEM, summaryRequest({ name: bot.name, own: linesFor(own), team: linesFor(team), language }), { sessionId: rt.chatOf(bot.id), kind: 'memory' })+ const text = await botShot(bot, SUMMARY_SYSTEM, summaryRequest({ name: bot.name, own: linesFor(own), team: linesFor(team), language }), { sessionId: rt.chatOf(bot.id), kind: 'memory' })const value = { hash, text: text.slice(0, SUMMARY_TEXT_MAX), at: Date.now() }summaries.set(bot.id, value)summaryFailures.delete(bot.id)if (rt.readOnly() === undefined) await writeText(summaryPath(bot.id), JSON.stringify(value, null, 2))})().catch((error) => {- summaryFailures.set(bot.id, { hash, message: error?.message ?? String(error) })+ summaryFailures.set(bot.id, { hash, model, message: error?.message ?? String(error) })rt.warn('ds-bot: memory summary for %s failed: %s', bot.name, error)}).finally(() => summarizing.delete(bot.id))summarizing.set(bot.id, job)}// The summary is written again when the entries or the interface language change;- // a failed one waits for `regenerate` instead of retrying on every poll.+ // a failed one waits for `regenerate`, or a new model for the Bot, instead of+ // retrying on every poll.function memoryView(body) {const bot = rt.botOf(String(body.botId ?? ''))if (bot === undefined) throw new Error('Unknown Bot')@@ -979,8 +1000,9 @@ export function install(rt) {const language = languageNow()const hash = createHash('sha256').update(JSON.stringify([language, linesFor(own), linesFor(team)])).digest('hex')const saved = savedSummary(bot.id)- const failed = summaryFailures.get(bot.id)- const wanted = body.regenerate === true || (body.summarize === true && saved?.hash !== hash && failed?.hash !== hash)+ const prior = summaryFailures.get(bot.id)+ const failed = prior?.hash === hash && prior.model === bot.model ? prior : undefined+ const wanted = body.regenerate === true || (body.summarize === true && saved?.hash !== hash && failed === undefined)if (wanted && entries.length > 0 && !summarizing.has(bot.id)) startSummary(bot, own, team, language, hash)return {botId: bot.id,@@ -990,7 +1012,7 @@ export function install(rt) {summary: entries.length > 0 && saved !== undefined ? { text: saved.text, at: saved.at } : null,fresh: entries.length === 0 || saved?.hash === hash,summarizing: summarizing.has(bot.id),- error: failed?.hash === hash && !summarizing.has(bot.id) ? failed.message : null,+ error: failed !== undefined && !summarizing.has(bot.id) ? failed.message : null,}}@@ -1003,7 +1025,7 @@ export function install(rt) {...allEntries(loadScope(ownScope(bot.id))).map(entry => ({ ...entry, scope: 'own' })),...allEntries(loadScope(TEAM)).map(entry => ({ ...entry, scope: 'team' })),]- const answer = parseAsk(await oneShot(await modelFor(bot), ASK_SYSTEM, askRequest({ name: bot.name, numbered, language: languageNow(), text }), { sessionId: rt.chatOf(bot.id), kind: 'memory' }))+ const answer = parseAsk(await botShot(bot, ASK_SYSTEM, askRequest({ name: bot.name, numbered, language: languageNow(), text }), { sessionId: rt.chatOf(bot.id), kind: 'memory' }))const meta = { source: 'memory panel', by: 'user', added: today() }const changes = []for (const change of answer.changes.slice(0, ASK_CHANGES_MAX)) {@@ -1236,7 +1258,7 @@ export function install(rt) {const sizes = { own: ownFiles[0].content.length, team: teamFiles[0].content.length }const earlier = batch.earlier.map(line => reviewLine(line.who, line.text, bot))const language = writtenIn(read.filter(line => line.who === 'user').map(line => line.text.replace(/^User: /, '')), languageNow())- const reply = await oneShot(await modelFor(bot), reviewSystem(writesTeam(bot.id)), reviewRequest({ bot, numbered, left, sizes, where: batch.where, earlier, fresh: fresh.texts, more, language }), { sessionId: rt.chatOf(bot.id), kind: 'memory' })+ const reply = await botShot(bot, reviewSystem(writesTeam(bot.id)), reviewRequest({ bot, numbered, left, sizes, where: batch.where, earlier, fresh: fresh.texts, more, language }), { sessionId: rt.chatOf(bot.id), kind: 'memory' })const changes = parseReview(reply)if (changes === undefined) throw new Error(`the model's answer is not a list of changes: ${clip(reply.replace(/\s+/g, ' '), 120)}`)const unknown = changes.find(change => change.op !== 'add' && numbered[Number(change.entry) - 1] === undefined)diff --git a/ds-bot/test/memory.test.js b/ds-bot/test/memory.test.jsindex d49c01b6..82273662 100644--- a/ds-bot/test/memory.test.js+++ b/ds-bot/test/memory.test.js@@ -120,14 +120,15 @@ const ownChat = [// The model answers each call with the next of `replies`. `history` holds the events// of a Session, oldest first; each own chat has one user message, at seq 10, unless// it says otherwise.-function start({ home = mkdtempSync(join(tmpdir(), 'ds-bot-memory-')), replies = [], config = {}, history = {}, reasoning = { efforts: [{ id: 'off' }, { id: 'high' }] } } = {}) {+function start({ home = mkdtempSync(join(tmpdir(), 'ds-bot-memory-')), replies = [], config = {}, history = {}, reasoning = { efforts: [{ id: 'off' }, { id: 'high' }] }, models = ['v4'], defaultModel } = {}) {if (!existsSync(join(home, 'state.json'))) writeFileSync(join(home, 'state.json'), JSON.stringify(TEAM))- const ctx = fakeContext()+ const services = defaultModel === undefined ? {} : { agentDefaultModel: { currentSelection: () => ({ provider: 'deepseek', model: defaultModel }) } }+ const ctx = fakeContext({ services })const requests = []Object.assign(ctx, {llm: {listProviders: () => [{ id: 'deepseek', name: 'DeepSeek' }],- listModels: async () => [{ id: 'v4' }],+ listModels: async () => models.map(id => ({ id })),resolveModelInfo: async () => ({ reasoning }),async* stream(request) {requests.push(request)@@ -135,7 +136,7 @@ function start({ home = mkdtempSync(join(tmpdir(), 'ds-bot-memory-')), replies =if (reply instanceof Error) throw replyconst out = typeof reply === 'object' && reply !== null ? reply : { text: reply ?? '' }yield { type: 'text-delta', index: 0, text: out.text ?? '' }- yield { type: 'finish', reason: { kind: out.finish ?? 'stop' } }+ yield { type: 'finish', reason: { kind: out.finish ?? 'stop', ...(out.failure ? { failure: { message: out.failure } } : {}) } }},},sessionController: {@@ -406,6 +407,65 @@ test('the panel call asks for the model\'s lowest thinking level when it has noassert.equal(second.requests[0].reasoningEffort, undefined)})+const routes = requests => requests.map(request => `${request.provider}/${request.model}@${request.maxTokens}`)++test('a summary the Bot\'s model refuses is written by the profile default model', async (t) => {+ const replies = [{ text: '', finish: 'error', failure: '403 Forbidden' }, '## Overview\nYou like tea.']+ const { tool, call, requests, stop } = start({ replies, models: ['v4', 'flash'], defaultModel: 'flash' })+ t.after(() => stop())+ await tool('remember', { text: 'Likes tea' }, 'b2')+ await call('memory-view', { botId: 'b2', summarize: true })+ await settle()+ const done = (await call('memory-view', { botId: 'b2' })).value+ assert.deepEqual([done.summary?.text, done.fresh, done.error], ['## Overview\nYou like tea.', true, null])+ assert.deepEqual(routes(requests), ['deepseek/v4@2048', 'deepseek/flash@2048'])+ assert.ok(requests.every(request => request.messages[0].content[0].text.includes('Likes tea')))+})++test('a summary cut off at both budgets on the Bot\'s model is written by the default model', async (t) => {+ const replies = [{ text: '', finish: 'max-tokens' }, { text: '## half', finish: 'max-tokens' }, '## Overview\nYou like tea.']+ const { tool, call, requests, stop } = start({ replies, models: ['v4', 'flash'], defaultModel: 'flash' })+ t.after(() => stop())+ await tool('remember', { text: 'Likes tea' }, 'b2')+ await call('memory-view', { botId: 'b2', summarize: true })+ await settle()+ const done = (await call('memory-view', { botId: 'b2' })).value+ assert.deepEqual([done.summary?.text, done.error], ['## Overview\nYou like tea.', null])+ assert.deepEqual(routes(requests), ['deepseek/v4@2048', 'deepseek/v4@8192', 'deepseek/flash@2048'])+})++test('a summary that failed on both models is tried again once the Bot has another model', async (t) => {+ const replies = [new Error('401: Unauthorized'), { text: '', finish: 'error', failure: '503 Service Unavailable' }]+ const { tool, call, requests, stop } = start({ replies, models: ['v4', 'flash'], defaultModel: 'flash' })+ t.after(() => stop())+ await tool('remember', { text: 'Likes tea' }, 'b2')+ await call('memory-view', { botId: 'b2', summarize: true })+ await settle()+ const failed = (await call('memory-view', { botId: 'b2', summarize: true })).value+ assert.equal(failed.error, 'deepseek/v4: 401: Unauthorized; deepseek/flash: 503 Service Unavailable')+ assert.equal(failed.summarizing, false)+ assert.equal(requests.length, 2)++ assert.equal((await call('update-bot', { id: 'b2', model: 'deepseek/flash' })).ok, true)+ replies.push('## Overview\nYou like tea.')+ const retried = (await call('memory-view', { botId: 'b2', summarize: true })).value+ assert.deepEqual([retried.summarizing, retried.error], [true, null])+ await settle()+ const done = (await call('memory-view', { botId: 'b2' })).value+ assert.deepEqual([done.summary?.text, done.error], ['## Overview\nYou like tea.', null])+ assert.deepEqual(routes(requests).slice(2), ['deepseek/flash@2048'])+})++test('"ask or update" falls back to the default model when the Bot\'s model fails', async (t) => {+ const replies = [new Error('403 Forbidden'), JSON.stringify({ reply: 'You like tea.', changes: [] })]+ const { tool, call, requests, stop } = start({ replies, models: ['v4', 'flash'], defaultModel: 'flash' })+ t.after(() => stop())+ await tool('remember', { text: 'Likes tea' }, 'b2')+ const answer = (await call('memory-ask', { botId: 'b2', text: 'What do I like?' })).value+ assert.equal(answer.reply, 'You like tea.')+ assert.deepEqual(routes(requests), ['deepseek/v4@2048', 'deepseek/flash@2048'])+})+test('"ask or update" answers from the entries and changes them through the same rules', async (t) => {const replies = []const { tool, call, read, journal, requests, stop } = start({ replies })