Skip to content

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

Retry the memory summary when reasoning spends the output budget

Fei241124a5a8d4b2dd
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 685ad0a3..017b62b5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -20,6 +20,7 @@ All notable changes to DS Bot are listed here. The format follows [Keep a Change
- In a group chat, typing `@` and a Bot's name and pressing Enter inserted a conversation reference instead of the Bot's name.
- A long conversation's fresh part keeps the Bot's model and thinking level. Before, the new part fell back to the default model.
- A provider adapter that cannot measure tokens no longer fails every turn. The context size is estimated instead, with one warning in the log.
+- The memory panel's summary works on models that think by default. The call asks for the model's lowest thinking level, and when the answer is cut off at the output limit it is written once more with a larger budget instead of failing or being saved half-written.
## [0.1.2] - 2026-10-11
diff --git a/ds-bot/src/host/memory.js b/ds-bot/src/host/memory.js
index 7de494e5..aee6322d 100644
--- a/ds-bot/src/host/memory.js
+++ b/ds-bot/src/host/memory.js
@@ -44,6 +44,9 @@ const QUERY_TERMS_MAX = 6
const SOURCE_READ_MS = 5_000
const MODEL_TIMEOUT_MS = 120_000
const SUMMARY_MAX_TOKENS = 2_048
+// A reply cut off at the limit is tried once more with room for reasoning plus
+// the answer; a model that thinks can spend the smaller budget thinking alone.
+const SUMMARY_RETRY_MAX_TOKENS = 8_192
const SUMMARY_TEXT_MAX = 8_000
const ASK_TEXT_MAX = 2_000
const ASK_CHANGES_MAX = 20
@@ -905,24 +908,32 @@ export function install(rt) {
// the tag the meter would file them under "other".
async function oneShot(route, system, text, tag) {
const info = await ctx.llm.resolveModelInfo(route.provider, route.model).catch(() => undefined)
- const off = info?.reasoning?.efforts?.some(effort => effort.id === 'off')
- const assembler = new BlockAssembler()
+ const efforts = info?.reasoning?.efforts ?? []
+ // Thinking counts against the same output budget as the answer, so ask for
+ // the least the model offers: 'off' when it has one, else its lowest level.
+ const effort = efforts.some(entry => entry.id === 'off') ? 'off' : efforts.at(0)?.id
const messages = [{ role: 'user', content: [{ type: 'text', text }] }]
if (tag !== undefined) rt.tagUsage?.(messages, tag)
- for await (const chunk of ctx.llm.stream({
- provider: route.provider,
- model: route.model,
- ...(off ? { reasoningEffort: 'off' } : {}),
- system,
- messages,
- maxTokens: SUMMARY_MAX_TOKENS,
- signal: AbortSignal.timeout(MODEL_TIMEOUT_MS),
- })) assembler.push(chunk)
- const finish = assembler.finish
- if (finish.kind === 'error' || finish.kind === 'aborted') throw new Error(finish.failure?.message ?? finish.kind)
- const reply = assembler.blocks().filter(block => block.type === 'text').map(block => block.text).join('\n').trim()
- if (reply === '') throw new Error('The model wrote nothing')
- return reply
+ for (const maxTokens of [SUMMARY_MAX_TOKENS, SUMMARY_RETRY_MAX_TOKENS]) {
+ const assembler = new BlockAssembler()
+ for await (const chunk of ctx.llm.stream({
+ provider: route.provider,
+ model: route.model,
+ ...(effort === undefined ? {} : { reasoningEffort: effort }),
+ system,
+ messages,
+ maxTokens,
+ signal: AbortSignal.timeout(MODEL_TIMEOUT_MS),
+ })) assembler.push(chunk)
+ const finish = assembler.finish
+ if (finish.kind === 'error' || finish.kind === 'aborted') throw new Error(finish.failure?.message ?? finish.kind)
+ const reply = assembler.blocks().filter(block => block.type === 'text').map(block => block.text).join('\n').trim()
+ if (finish.kind !== 'max-tokens' && reply !== '') return reply
+ // A reply cut off at the limit — all of it thinking, or a half-written
+ // answer — is dropped, never used; the retry gives it room once.
+ if (finish.kind !== 'max-tokens' && maxTokens === SUMMARY_MAX_TOKENS) throw new Error('The model wrote nothing')
+ }
+ 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`)
}
/** @type {Map<string, {hash:string, text:string, at:number}>} */
diff --git a/ds-bot/test/memory.test.js b/ds-bot/test/memory.test.js
index ece480d3..6efbbc06 100644
--- a/ds-bot/test/memory.test.js
+++ b/ds-bot/test/memory.test.js
@@ -120,7 +120,7 @@ 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 = {} } = {}) {
+function start({ home = mkdtempSync(join(tmpdir(), 'ds-bot-memory-')), replies = [], config = {}, history = {}, reasoning = { efforts: [{ id: 'off' }, { id: 'high' }] } } = {}) {
if (!existsSync(join(home, 'state.json'))) writeFileSync(join(home, 'state.json'), JSON.stringify(TEAM))
const ctx = fakeContext()
const requests = []
@@ -128,13 +128,14 @@ function start({ home = mkdtempSync(join(tmpdir(), 'ds-bot-memory-')), replies =
llm: {
listProviders: () => [{ id: 'deepseek', name: 'DeepSeek' }],
listModels: async () => [{ id: 'v4' }],
- resolveModelInfo: async () => ({ reasoning: { efforts: [{ id: 'off' }, { id: 'high' }] } }),
+ resolveModelInfo: async () => ({ reasoning }),
async* stream(request) {
requests.push(request)
const reply = await replies.shift()
if (reply instanceof Error) throw reply
- yield { type: 'text-delta', index: 0, text: reply ?? '' }
- yield { type: 'finish', reason: { kind: 'stop' } }
+ const 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' } }
},
},
sessionController: {
@@ -353,6 +354,58 @@ test('the memory panel shows every entry and a summary the Bot\'s model writes o
assert.equal((await call('memory-view', { botId: 'nope' })).error.message, 'Unknown Bot')
})
+test('a summary cut off at the output limit is written once more with a bigger budget, never kept half', async (t) => {
+ const replies = [
+ { text: '## Overview\nYou like', finish: 'max-tokens' },
+ '## Overview\nYou like tea.',
+ ]
+ const { tool, call, requests, stop } = start({ replies })
+ 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(requests.map(request => request.maxTokens), [2048, 8192])
+})
+
+test('a summary cut off at both budgets keeps the old one and says the reasoning used the budget', async (t) => {
+ const replies = [
+ '## Overview\nYou like tea.',
+ { text: '', finish: 'max-tokens' },
+ { text: '## Overview\nhalf', finish: 'max-tokens' },
+ ]
+ const { tool, call, requests, stop } = start({ replies })
+ t.after(() => stop())
+ await tool('remember', { text: 'Likes tea' }, 'b2')
+ await call('memory-view', { botId: 'b2', summarize: true })
+ await settle()
+ // A new entry asks for a fresh summary; both its tries are cut off.
+ await tool('remember', { text: 'Lives in Hangzhou' }, 'b2')
+ await call('memory-view', { botId: 'b2', summarize: true })
+ await settle()
+ const failed = (await call('memory-view', { botId: 'b2' })).value
+ assert.equal(failed.summary.text, '## Overview\nYou like tea.')
+ assert.match(failed.error, /reasoning.*output budget|output budget.*reasoning/i)
+ assert.deepEqual(requests.map(request => request.maxTokens), [2048, 2048, 8192])
+})
+
+test('the panel call asks for the model\'s lowest thinking level when it has no "off"', async (t) => {
+ const first = start({ replies: ['## ok'], reasoning: { efforts: [{ id: 'low' }, { id: 'high' }] } })
+ t.after(() => first.stop())
+ await first.tool('remember', { text: 'Likes tea' }, 'b2')
+ await first.call('memory-view', { botId: 'b2', summarize: true })
+ await settle()
+ assert.equal(first.requests[0].reasoningEffort, 'low')
+
+ const second = start({ replies: ['## ok'], reasoning: {} })
+ t.after(() => second.stop())
+ await second.tool('remember', { text: 'Likes tea' }, 'b2')
+ await second.call('memory-view', { botId: 'b2', summarize: true })
+ await settle()
+ assert.equal(second.requests[0].reasoningEffort, undefined)
+})
+
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 })