From b949ae070c360ebb8c8d5bec2b752fb8ad5c2394 Mon Sep 17 00:00:00 2001 From: Shaojin Wen Date: Mon, 11 May 2026 11:40:13 +0800 Subject: [PATCH] feat(tools): defer low-frequency built-in tools to reduce initial prompt size (#4022) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(tools): defer low-frequency built-in tools to reduce initial prompt size Mark Monitor, SendMessage, Skill, TaskStop, TodoWrite, and WebFetch as shouldDefer=true so their full schemas are excluded from the initial function-declaration list. The model discovers them on demand via ToolSearch, aligning with Claude Code's deferral strategy for infrequently used tools. * fix(tools): don't defer TodoWrite/Skill — they're required by the system prompt TodoWrite is mandated as high-frequency by the core system prompt ("Use VERY frequently", "IMPORTANT: Always use the TODO_WRITE tool to plan and track tasks throughout the conversation"). Deferring it forces a ToolSearch round-trip before every required call, adding latency and hurting prompt compliance. SkillTool's full description carries the dynamically generated listing and the BLOCKING invocation rules ("invoke the relevant Skill tool BEFORE generating any other response"). The deferred-tool summary truncates this, so the model loses both the list of skills and the activation contract from the initial prompt. Keep Monitor / SendMessage / TaskStop / WebFetch deferred — those are genuinely infrequent and have no system-prompt requirement. --- packages/core/src/tools/monitor.ts | 5 +++++ packages/core/src/tools/send-message.ts | 5 +++++ packages/core/src/tools/task-stop.ts | 5 +++++ packages/core/src/tools/web-fetch.ts | 5 +++++ 4 files changed, 20 insertions(+) diff --git a/packages/core/src/tools/monitor.ts b/packages/core/src/tools/monitor.ts index 8dedf11c7..1311d8040 100644 --- a/packages/core/src/tools/monitor.ts +++ b/packages/core/src/tools/monitor.ts @@ -677,6 +677,11 @@ export class MonitorTool extends BaseDeclarativeTool< required: ['command'], additionalProperties: false, }, + true, // isOutputMarkdown + false, // canUpdateOutput + true, // shouldDefer — monitoring is infrequent + false, // alwaysLoad + 'monitor watch tail log stream background', ); } diff --git a/packages/core/src/tools/send-message.ts b/packages/core/src/tools/send-message.ts index 64697bb46..62a3b9788 100644 --- a/packages/core/src/tools/send-message.ts +++ b/packages/core/src/tools/send-message.ts @@ -129,6 +129,11 @@ export class SendMessageTool extends BaseDeclarativeTool< required: ['task_id', 'message'], additionalProperties: false, }, + true, // isOutputMarkdown + false, // canUpdateOutput + true, // shouldDefer — sending messages to tasks is infrequent + false, // alwaysLoad + 'send message task communicate notify', ); } diff --git a/packages/core/src/tools/task-stop.ts b/packages/core/src/tools/task-stop.ts index bbe758062..b51e4ebba 100644 --- a/packages/core/src/tools/task-stop.ts +++ b/packages/core/src/tools/task-stop.ts @@ -247,6 +247,11 @@ export class TaskStopTool extends BaseDeclarativeTool< required: ['task_id'], additionalProperties: false, }, + true, // isOutputMarkdown + false, // canUpdateOutput + true, // shouldDefer — stopping tasks is infrequent + false, // alwaysLoad + 'task stop cancel kill background', ); } diff --git a/packages/core/src/tools/web-fetch.ts b/packages/core/src/tools/web-fetch.ts index 30bdef4c0..8e7b3cc13 100644 --- a/packages/core/src/tools/web-fetch.ts +++ b/packages/core/src/tools/web-fetch.ts @@ -289,6 +289,11 @@ export class WebFetchTool extends BaseDeclarativeTool< required: ['url', 'prompt'], type: 'object', }, + true, // isOutputMarkdown + false, // canUpdateOutput + true, // shouldDefer — web fetching is infrequent + false, // alwaysLoad + 'web fetch url http download content', ); }