From cbc170818f39630671a1e4405850bbc87edd70ad Mon Sep 17 00:00:00 2001 From: chouti Date: Mon, 8 Jun 2026 19:06:03 +0800 Subject: [PATCH] fix(config): add maxTokens to LlmSchema & SkillEvolverSchema Reasoning models (deepseek-reasoner, o1*, gpt-5-thinking) consume hundreds of tokens on chain-of-thought. The hard-coded 1024 cap on LLM JSON reflection caused 73+ 'llm.json malformed' errors per episode, blocking episode closure and disconnecting the bridge. - Add maxTokens: NumberInRange(4000, 1024, 32768) to LlmSchema - Add maxTokens: NumberInRange(4000, 1024, 32768) to SkillEvolverSchema - Add corresponding defaults in defaults.ts (backward compat) TypeBox's Value.Default preserves user-supplied fields, so old configs without maxTokens get the 4000 default; new configs can override. --- apps/memos-local-plugin/core/config/defaults.ts | 2 ++ apps/memos-local-plugin/core/config/schema.ts | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/apps/memos-local-plugin/core/config/defaults.ts b/apps/memos-local-plugin/core/config/defaults.ts index 1cf2d2cf6..fe43147a2 100644 --- a/apps/memos-local-plugin/core/config/defaults.ts +++ b/apps/memos-local-plugin/core/config/defaults.ts @@ -41,6 +41,7 @@ export const DEFAULT_CONFIG: ResolvedConfig = { apiKey: "", timeoutMs: 45_000, maxRetries: 3, + maxTokens: 4_000, }, skillEvolver: { // Empty by default — falls back to the shared `llm` settings. @@ -52,6 +53,7 @@ export const DEFAULT_CONFIG: ResolvedConfig = { apiKey: "", temperature: 0, timeoutMs: 60_000, + maxTokens: 4_000, }, algorithm: { lightweightMemory: { diff --git a/apps/memos-local-plugin/core/config/schema.ts b/apps/memos-local-plugin/core/config/schema.ts index 7c9ff193b..daffa0f75 100644 --- a/apps/memos-local-plugin/core/config/schema.ts +++ b/apps/memos-local-plugin/core/config/schema.ts @@ -65,6 +65,14 @@ const LlmSchema = Type.Object({ timeoutMs: NumberInRange(45_000, 1_000), /** Max retries on transient errors. */ maxRetries: NumberInRange(3, 0, 10), + /** + * Max output tokens per LLM call. Default 4_000 — sufficient budget for + * reasoning models (deepseek-reasoner, o1*, gpt-5-thinking) that burn + * hundreds of tokens on chain-of-thought before content. Below ~2_000 + * the JSON reflection / synth prompts get truncated mid-string and the + * bridge logs `llm.json malformed`. + */ + maxTokens: NumberInRange(4_000, 1_024, 32_768), }, { default: {} }); /** @@ -89,6 +97,13 @@ const SkillEvolverSchema = Type.Object({ apiKey: StringWithDefault(""), temperature: NumberInRange(0, 0, 2), timeoutMs: NumberInRange(60_000, 1_000), + /** + * Max output tokens per skill-evolver LLM call. Same reasoning budget + * as `llm.maxTokens` — 4_000 covers typical crystallisation JSON + * (multi-policy evidence rollup + decision rationale) without hitting + * the 32k OpenAI ceiling. + */ + maxTokens: NumberInRange(4_000, 1_024, 32_768), }, { default: {} }); const AlgorithmSchema = Type.Object({