From 3d588b0a0f5ae91af005f8b9b42c600aed26ca42 Mon Sep 17 00:00:00 2001 From: Radian <102750431+withRiver@users.noreply.github.com> Date: Tue, 2 Jun 2026 20:40:24 +0800 Subject: [PATCH] Merge pull request #128 from withRiver/fix/remove-tools-clean-context-runner fix: pass disableTools:true when enableTools=false in CleanContextRunner --- src/utils/clean-context-runner.ts | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/utils/clean-context-runner.ts b/src/utils/clean-context-runner.ts index 525b996..d8ae883 100644 --- a/src/utils/clean-context-runner.ts +++ b/src/utils/clean-context-runner.ts @@ -5,7 +5,7 @@ * Guarantees: * 1. Blank conversation history (temporary session file) * 2. Independent system prompt (only the task prompt) - * 3. No tool calls (tools restricted to minimal read-only set to avoid empty tools[] rejection by some providers) + * 3. No tool calls when enableTools=false (disableTools:true — no tool definitions sent to API) * 4. No contamination from the main agent's context */ @@ -390,10 +390,11 @@ export class CleanContextRunner { }, tools: { ...((this.options.config as Record)?.tools as Record | undefined), - // When enableTools=false we still keep one lightweight read-only tool - // so that the tools array sent to the API is non-empty. - // Some providers (e.g. qwencode) reject tools:[] with minItems:1 validation. - allow: this.options.enableTools ? ["read", "write", "edit"] : ["read"], + // When enableTools=true, restrict to the minimal set needed for + // scene extraction (read/write/edit). + // When enableTools=false, pass an empty allow list — disableTools:true + // will prevent tools from being sent to the API entirely. + allow: this.options.enableTools ? ["read", "write", "edit"] : [], }, // Override the full agent system prompt with the caller's extraction-specific // system prompt. This replaces OpenClaw's default system prompt (identity, @@ -451,11 +452,13 @@ export class CleanContextRunner { runId, provider: this.resolvedProvider, model: this.resolvedModel, - // Do NOT pass disableTools:true — that produces tools:[] which some - // providers (qwencode) reject with "[] is too short - 'tools'". - // Instead rely on cleanConfig.tools.allow to restrict the tool set - // to a minimal read-only tool (when enableTools=false). - disableTools: false, + // When enableTools=false, pass disableTools:true so that no tool + // definitions are sent to the API. This avoids polluting the LLM + // context with tool schemas and prevents the model from attempting + // tool calls during pure text extraction tasks. + // If a provider (e.g. qwencode) rejects empty tools[], users should + // switch to StandaloneLLMRunner via LLM configuration instead. + disableTools: !this.options.enableTools, extraSystemPrompt: effectiveSystemPrompt, streamParams: { maxTokens: params.maxTokens,