From fc5479e82360777bcfa4863f3ac01a5e70fdc2c8 Mon Sep 17 00:00:00 2001 From: Matt Rubens Date: Wed, 29 Oct 2025 23:32:26 -0400 Subject: [PATCH] Make system prompt conditional on native tool calls --- .../__tests__/system-native-tools.spec.ts | 5 ----- src/core/prompts/sections/tool-use-guidelines.ts | 12 ++++++++++-- src/core/prompts/sections/tool-use.ts | 16 ++++++++++------ src/core/prompts/system.ts | 9 ++++----- src/core/task/Task.ts | 1 - src/core/webview/generateSystemPrompt.ts | 1 - 6 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/core/prompts/__tests__/system-native-tools.spec.ts b/src/core/prompts/__tests__/system-native-tools.spec.ts index 5ba620f665..1ceca5ee2e 100644 --- a/src/core/prompts/__tests__/system-native-tools.spec.ts +++ b/src/core/prompts/__tests__/system-native-tools.spec.ts @@ -63,7 +63,6 @@ describe("SYSTEM_PROMPT with native tools", () => { false, { ...defaultSettings, todoListEnabled: false }, undefined, - undefined, true, // useNativeTools ) @@ -99,7 +98,6 @@ describe("SYSTEM_PROMPT with native tools", () => { false, { ...defaultSettings, todoListEnabled: true }, undefined, - undefined, true, // useNativeTools ) @@ -135,7 +133,6 @@ describe("SYSTEM_PROMPT with native tools", () => { false, undefined, undefined, - undefined, true, // useNativeTools ) @@ -171,7 +168,6 @@ describe("SYSTEM_PROMPT with native tools", () => { false, undefined, undefined, - undefined, true, // useNativeTools ) @@ -207,7 +203,6 @@ describe("SYSTEM_PROMPT with native tools", () => { false, undefined, undefined, - undefined, true, // useNativeTools ) diff --git a/src/core/prompts/sections/tool-use-guidelines.ts b/src/core/prompts/sections/tool-use-guidelines.ts index f6843cf842..a054969cf4 100644 --- a/src/core/prompts/sections/tool-use-guidelines.ts +++ b/src/core/prompts/sections/tool-use-guidelines.ts @@ -1,6 +1,9 @@ import { CodeIndexManager } from "../../../services/code-index/manager" -export function getToolUseGuidelinesSection(codeIndexManager?: CodeIndexManager): string { +export function getToolUseGuidelinesSection( + codeIndexManager?: CodeIndexManager, + useNativeTools: boolean = false, +): string { const isCodebaseSearchAvailable = codeIndexManager && codeIndexManager.isFeatureEnabled && @@ -34,7 +37,12 @@ export function getToolUseGuidelinesSection(codeIndexManager?: CodeIndexManager) guidelinesList.push( `${itemNumber++}. If multiple actions are needed, use one tool at a time per message to accomplish the task iteratively, with each tool use being informed by the result of the previous tool use. Do not assume the outcome of any tool use. Each step must be informed by the previous step's result.`, ) - guidelinesList.push(`${itemNumber++}. Formulate your tool use using the XML format specified for each tool.`) + + // Only include XML format guideline for XML-based tools + if (!useNativeTools) { + guidelinesList.push(`${itemNumber++}. Formulate your tool use using the XML format specified for each tool.`) + } + guidelinesList.push(`${itemNumber++}. After each tool use, the user will respond with the result of that tool use. This result will provide you with the necessary information to continue your task or make further decisions. This response may include: - Information about whether the tool succeeded or failed, along with any reasons for failure. - Linter errors that may have arisen due to the changes you made, which you'll need to address. diff --git a/src/core/prompts/sections/tool-use.ts b/src/core/prompts/sections/tool-use.ts index 28d47d0985..d192347fbe 100644 --- a/src/core/prompts/sections/tool-use.ts +++ b/src/core/prompts/sections/tool-use.ts @@ -1,9 +1,7 @@ -export function getSharedToolUseSection(): string { - return `==== - -TOOL USE - -You have access to a set of tools that are executed upon the user's approval. You must use exactly one tool per message, and every assistant message must include a tool call. You use tools step-by-step to accomplish a given task, with each tool use informed by the result of the previous tool use. +export function getSharedToolUseSection(useNativeTools: boolean = false): string { + const xmlFormatting = useNativeTools + ? "" + : ` # Tool Use Formatting @@ -16,4 +14,10 @@ Tool uses are formatted using XML-style tags. The tool name itself becomes the X Always use the actual tool name as the XML tag name for proper parsing and execution.` + + return `==== + +TOOL USE + +You have access to a set of tools that are executed upon the user's approval. You must use exactly one tool per message, and every assistant message must include a tool call. You use tools step-by-step to accomplish a given task, with each tool use informed by the result of the previous tool use.${xmlFormatting}` } diff --git a/src/core/prompts/system.ts b/src/core/prompts/system.ts index b390704a73..49a4b396bb 100644 --- a/src/core/prompts/system.ts +++ b/src/core/prompts/system.ts @@ -62,8 +62,8 @@ async function generatePrompt( rooIgnoreInstructions?: string, partialReadsEnabled?: boolean, settings?: SystemPromptSettings, - todoList?: TodoItem[], modelId?: string, + useNativeTools?: boolean, ): Promise { if (!context) { throw new Error("Extension context is required for generating system prompt") @@ -94,7 +94,7 @@ async function generatePrompt( ${markdownFormattingSection()} -${getSharedToolUseSection()} +${getSharedToolUseSection(useNativeTools)} ${getToolDescriptionsForMode( mode, @@ -112,7 +112,7 @@ ${getToolDescriptionsForMode( modelId, )} -${getToolUseGuidelinesSection(codeIndexManager)} +${getToolUseGuidelinesSection(codeIndexManager, useNativeTools)} ${mcpServersSection} @@ -153,7 +153,6 @@ export const SYSTEM_PROMPT = async ( rooIgnoreInstructions?: string, partialReadsEnabled?: boolean, settings?: SystemPromptSettings, - todoList?: TodoItem[], modelId?: string, useNativeTools?: boolean, ): Promise<{ systemPrompt: string; tools?: ToolSpec[] }> => { @@ -228,8 +227,8 @@ ${customInstructions}`, rooIgnoreInstructions, partialReadsEnabled, settings, - todoList, modelId, + useNativeTools, ) // If native tools are enabled, build tool specifications and return them with the prompt diff --git a/src/core/task/Task.ts b/src/core/task/Task.ts index 5f5756ec1a..0e71f7043b 100644 --- a/src/core/task/Task.ts +++ b/src/core/task/Task.ts @@ -2598,7 +2598,6 @@ export class Task extends EventEmitter implements TaskLike { .getConfiguration("roo-cline") .get("newTaskRequireTodos", false), }, - undefined, // todoList this.api.getModel().id, useNativeTools, ) diff --git a/src/core/webview/generateSystemPrompt.ts b/src/core/webview/generateSystemPrompt.ts index 8f3ee5d1b8..e503fd6d00 100644 --- a/src/core/webview/generateSystemPrompt.ts +++ b/src/core/webview/generateSystemPrompt.ts @@ -101,7 +101,6 @@ export const generateSystemPrompt = async (provider: ClineProvider, message: Web .getConfiguration("roo-cline") .get("newTaskRequireTodos", false), }, - undefined, // todoList undefined, // modelId useNativeTools, )