From 17beca6715f2ed42e9d18a2348b311d7875b63f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=B5=A9?= Date: Fri, 5 Jun 2026 17:42:00 +0800 Subject: [PATCH] fix(compaction): pass maxOutputSize to resolveCompletionBudget The compaction worker was not passing maxOutputSize to resolveCompletionBudget, causing it to fall back to max_context_size as the completion token cap. For models like glm-5.1 configured via openai_legacy provider, this resulted in max_tokens being set to the full context window (e.g. 202752), which the upstream API rejected with a 400 error. Normal chat requests already pass maxOutputSize correctly via Agent.llm. --- .changeset/fix-compaction-max-output-size.md | 5 +++++ packages/agent-core/src/agent/compaction/full.ts | 1 + 2 files changed, 6 insertions(+) create mode 100644 .changeset/fix-compaction-max-output-size.md diff --git a/.changeset/fix-compaction-max-output-size.md b/.changeset/fix-compaction-max-output-size.md new file mode 100644 index 000000000..cac5f917c --- /dev/null +++ b/.changeset/fix-compaction-max-output-size.md @@ -0,0 +1,5 @@ +--- +"@moonshot-ai/agent-core": patch +--- + +Pass `maxOutputSize` to `resolveCompletionBudget` in the compaction worker to prevent falling back to `max_context_size` as the completion token cap. \ No newline at end of file diff --git a/packages/agent-core/src/agent/compaction/full.ts b/packages/agent-core/src/agent/compaction/full.ts index 3c52043a9..4ed98874e 100644 --- a/packages/agent-core/src/agent/compaction/full.ts +++ b/packages/agent-core/src/agent/compaction/full.ts @@ -244,6 +244,7 @@ export class FullCompaction { const provider = applyCompletionBudget({ provider: this.agent.config.provider, budget: resolveCompletionBudget({ + maxOutputSize: this.agent.config.maxOutputSize, reservedContextSize: this.agent.kimiConfig?.loopControl?.reservedContextSize, }), capability: this.agent.config.modelCapabilities,