Skip to content

Commit 513eebc

Browse files
authored
Enhance native tool descriptions with examples and clarifications (#9486)
1 parent 204c71c commit 513eebc

18 files changed

+322
-94
lines changed

src/core/prompts/tools/native-tools/apply_diff.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
import type OpenAI from "openai"
22

3+
const APPLY_DIFF_DESCRIPTION = `Apply precise, targeted modifications to an existing file using one or more search/replace blocks. This tool is for surgical edits only; the 'SEARCH' block must exactly match the existing content, including whitespace and indentation. To make multiple targeted changes, provide multiple SEARCH/REPLACE blocks in the 'diff' parameter. Use the 'read_file' tool first if you are not confident in the exact content to search for.`
4+
5+
const DIFF_PARAMETER_DESCRIPTION = `A string containing one or more search/replace blocks defining the changes. The ':start_line:' is required and indicates the starting line number of the original content. You must not add a start line for the replacement content. Each block must follow this format:
6+
<<<<<<< SEARCH
7+
:start_line:[line_number]
8+
-------
9+
[exact content to find]
10+
=======
11+
[new content to replace with]
12+
>>>>>>> REPLACE`
13+
314
export const apply_diff_single_file = {
415
type: "function",
516
function: {
617
name: "apply_diff",
7-
description: `
8-
Apply precise, targeted modifications to an existing file using one or more search/replace blocks. This tool is for surgical edits only; the 'SEARCH' block must exactly match the existing content, including whitespace and indentation. To make multiple targeted changes, provide multiple SEARCH/REPLACE blocks in the 'diff' parameter. Use the 'read_file' tool first if you are not confident in the exact content to search for.
9-
`,
18+
description: APPLY_DIFF_DESCRIPTION,
1019
parameters: {
1120
type: "object",
1221
properties: {
@@ -16,16 +25,7 @@ Apply precise, targeted modifications to an existing file using one or more sear
1625
},
1726
diff: {
1827
type: "string",
19-
description: `
20-
A string containing one or more search/replace blocks defining the changes. The ':start_line:' is required and indicates the starting line number of the original content. You must not add a start line for the replacement content. Each block must follow this format:
21-
<<<<<<< SEARCH
22-
:start_line:[line_number]
23-
-------
24-
[exact content to find]
25-
=======
26-
[new content to replace with]
27-
>>>>>>> REPLACE
28-
`,
28+
description: DIFF_PARAMETER_DESCRIPTION,
2929
},
3030
},
3131
required: ["path", "diff"],

src/core/prompts/tools/native-tools/ask_followup_question.ts

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,51 @@
11
import type OpenAI from "openai"
22

3+
const ASK_FOLLOWUP_QUESTION_DESCRIPTION = `Ask the user a question to gather additional information needed to complete the task. Use when you need clarification or more details to proceed effectively.
4+
5+
Parameters:
6+
- question: (required) A clear, specific question addressing the information needed
7+
- follow_up: (required) A list of 2-4 suggested answers. Suggestions must be complete, actionable answers without placeholders. Optionally include mode to switch modes (code/architect/etc.)
8+
9+
Example: Asking for file path
10+
{ "question": "What is the path to the frontend-config.json file?", "follow_up": [{ "text": "./src/frontend-config.json", "mode": null }, { "text": "./config/frontend-config.json", "mode": null }, { "text": "./frontend-config.json", "mode": null }] }
11+
12+
Example: Asking with mode switch
13+
{ "question": "Would you like me to implement this feature?", "follow_up": [{ "text": "Yes, implement it now", "mode": "code" }, { "text": "No, just plan it out", "mode": "architect" }] }`
14+
15+
const QUESTION_PARAMETER_DESCRIPTION = `Clear, specific question that captures the missing information you need`
16+
17+
const FOLLOW_UP_PARAMETER_DESCRIPTION = `Required list of 2-4 suggested responses; each suggestion must be a complete, actionable answer and may include a mode switch`
18+
19+
const FOLLOW_UP_TEXT_DESCRIPTION = `Suggested answer the user can pick`
20+
21+
const FOLLOW_UP_MODE_DESCRIPTION = `Optional mode slug to switch to if this suggestion is chosen (e.g., code, architect)`
22+
323
export default {
424
type: "function",
525
function: {
626
name: "ask_followup_question",
7-
description:
8-
"Ask the user a question to gather additional information needed to complete the task. Use when clarification or more detail is required before proceeding.",
27+
description: ASK_FOLLOWUP_QUESTION_DESCRIPTION,
928
strict: true,
1029
parameters: {
1130
type: "object",
1231
properties: {
1332
question: {
1433
type: "string",
15-
description: "Clear, specific question that captures the missing information you need",
34+
description: QUESTION_PARAMETER_DESCRIPTION,
1635
},
1736
follow_up: {
1837
type: "array",
19-
description:
20-
"Required list of 2-4 suggested responses; each suggestion must be a complete, actionable answer and may include a mode switch",
38+
description: FOLLOW_UP_PARAMETER_DESCRIPTION,
2139
items: {
2240
type: "object",
2341
properties: {
2442
text: {
2543
type: "string",
26-
description: "Suggested answer the user can pick",
44+
description: FOLLOW_UP_TEXT_DESCRIPTION,
2745
},
2846
mode: {
2947
type: ["string", "null"],
30-
description:
31-
"Optional mode slug to switch to if this suggestion is chosen (e.g., code, architect)",
48+
description: FOLLOW_UP_MODE_DESCRIPTION,
3249
},
3350
},
3451
required: ["text", "mode"],

src/core/prompts/tools/native-tools/attempt_completion.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
11
import type OpenAI from "openai"
22

3+
const ATTEMPT_COMPLETION_DESCRIPTION = `After each tool use, the user will respond with the result of that tool use, i.e. if it succeeded or failed, along with any reasons for failure. Once you've received the results of tool uses and can confirm that the task is complete, use this tool to present the result of your work to the user. The user may respond with feedback if they are not satisfied with the result, which you can use to make improvements and try again.
4+
5+
IMPORTANT NOTE: This tool CANNOT be used until you've confirmed from the user that any previous tool uses were successful. Failure to do so will result in code corruption and system failure. Before using this tool, you must confirm that you've received successful results from the user for any previous tool uses. If not, then DO NOT use this tool.
6+
7+
Parameters:
8+
- result: (required) The result of the task. Formulate this result in a way that is final and does not require further input from the user. Don't end your result with questions or offers for further assistance.
9+
10+
Example: Completing after updating CSS
11+
{ "result": "I've updated the CSS to use flexbox layout for better responsiveness" }`
12+
13+
const RESULT_PARAMETER_DESCRIPTION = `Final result message to deliver to the user once the task is complete`
14+
315
export default {
416
type: "function",
517
function: {
618
name: "attempt_completion",
7-
description:
8-
"After each tool use, the user will respond with the result of that tool use, i.e. if it succeeded or failed, along with any reasons for failure. Once you've received the results of tool uses and can confirm that the task is complete, use this tool to present the result of your work to the user. The user may respond with feedback if they are not satisfied with the result, which you can use to make improvements and try again. IMPORTANT NOTE: This tool CANNOT be used until you've confirmed from the user that any previous tool uses were successful. Failure to do so will result in code corruption and system failure. Before using this tool, you must confirm that you've received successful results from the user for any previous tool uses. If not, then DO NOT use this tool.",
19+
description: ATTEMPT_COMPLETION_DESCRIPTION,
920
strict: true,
1021
parameters: {
1122
type: "object",
1223
properties: {
1324
result: {
1425
type: "string",
15-
description: "Final result message to deliver to the user once the task is complete",
26+
description: RESULT_PARAMETER_DESCRIPTION,
1627
},
1728
},
1829
required: ["result"],

src/core/prompts/tools/native-tools/browser_action.ts

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,51 @@
11
import type OpenAI from "openai"
22

3+
const BROWSER_ACTION_DESCRIPTION = `Request to interact with a Puppeteer-controlled browser. Every action, except close, will be responded to with a screenshot of the browser's current state, along with any new console logs. You may only perform one browser action per message, and wait for the user's response including a screenshot and logs to determine the next action.
4+
5+
Browser Session Lifecycle:
6+
- Browser sessions start with launch and end with close
7+
- The session remains active across multiple messages and tool uses
8+
- You can use other tools while the browser session is active - it will stay open in the background`
9+
10+
const ACTION_PARAMETER_DESCRIPTION = `Browser action to perform`
11+
12+
const URL_PARAMETER_DESCRIPTION = `URL to open when performing the launch action; must include protocol`
13+
14+
const COORDINATE_PARAMETER_DESCRIPTION = `Screen coordinate for hover or click actions in format 'x,y@WIDTHxHEIGHT' where x,y is the target position on the screenshot image and WIDTHxHEIGHT is the exact pixel dimensions of the screenshot image (not the browser viewport). Example: '450,203@900x600' means click at (450,203) on a 900x600 screenshot. The coordinates will be automatically scaled to match the actual viewport dimensions.`
15+
16+
const SIZE_PARAMETER_DESCRIPTION = `Viewport dimensions for the resize action in format 'WIDTHxHEIGHT' or 'WIDTH,HEIGHT'. Example: '1280x800' or '1280,800'`
17+
18+
const TEXT_PARAMETER_DESCRIPTION = `Text to type when performing the type action, or key name to press when performing the press action (e.g., 'Enter', 'Tab', 'Escape')`
19+
320
export default {
421
type: "function",
522
function: {
623
name: "browser_action",
7-
description:
8-
"Interact with a browser session. Always start by launching at a URL and always finish by closing the browser. While the browser is active, do not call any other tools. Use coordinates within the viewport to hover or click, provide text for typing, and ensure actions are grounded in the latest screenshot and console logs.",
24+
description: BROWSER_ACTION_DESCRIPTION,
925
strict: true,
1026
parameters: {
1127
type: "object",
1228
properties: {
1329
action: {
1430
type: "string",
15-
description: "Browser action to perform",
31+
description: ACTION_PARAMETER_DESCRIPTION,
1632
enum: ["launch", "click", "hover", "type", "press", "scroll_down", "scroll_up", "resize", "close"],
1733
},
1834
url: {
1935
type: ["string", "null"],
20-
description: "URL to open when performing the launch action; must include protocol",
36+
description: URL_PARAMETER_DESCRIPTION,
2137
},
2238
coordinate: {
2339
type: ["string", "null"],
24-
description:
25-
"Screen coordinate for hover or click actions in format 'x,y@WIDTHxHEIGHT' where x,y is the target position on the screenshot image and WIDTHxHEIGHT is the exact pixel dimensions of the screenshot image (not the browser viewport). Example: '450,203@900x600' means click at (450,203) on a 900x600 screenshot. The coordinates will be automatically scaled to match the actual viewport dimensions.",
40+
description: COORDINATE_PARAMETER_DESCRIPTION,
2641
},
2742
size: {
2843
type: ["string", "null"],
29-
description:
30-
"Viewport dimensions for the resize action in format 'WIDTHxHEIGHT' or 'WIDTH,HEIGHT'. Example: '1280x800' or '1280,800'",
44+
description: SIZE_PARAMETER_DESCRIPTION,
3145
},
3246
text: {
3347
type: ["string", "null"],
34-
description:
35-
"Text to type when performing the type action, or key name to press when performing the press action (e.g., 'Enter', 'Tab', 'Escape')",
48+
description: TEXT_PARAMETER_DESCRIPTION,
3649
},
3750
},
3851
required: ["action"],

src/core/prompts/tools/native-tools/codebase_search.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,37 @@
11
import type OpenAI from "openai"
22

3+
const CODEBASE_SEARCH_DESCRIPTION = `Find files most relevant to the search query using semantic search. Searches based on meaning rather than exact text matches. By default searches entire workspace. Reuse the user's exact wording unless there's a clear reason not to - their phrasing often helps semantic search. Queries MUST be in English (translate if needed).
4+
5+
Parameters:
6+
- query: (required) The search query. Reuse the user's exact wording/question format unless there's a clear reason not to.
7+
- path: (optional) Limit search to specific subdirectory (relative to the current workspace directory). Leave empty for entire workspace.
8+
9+
Example: Searching for user authentication code
10+
{ "query": "User login and password hashing", "path": "src/auth" }
11+
12+
Example: Searching entire workspace
13+
{ "query": "database connection pooling", "path": null }`
14+
15+
const QUERY_PARAMETER_DESCRIPTION = `Meaning-based search query describing the information you need`
16+
17+
const PATH_PARAMETER_DESCRIPTION = `Optional subdirectory (relative to the workspace) to limit the search scope`
18+
319
export default {
420
type: "function",
521
function: {
622
name: "codebase_search",
7-
description:
8-
"Run a semantic search across the workspace to find files relevant to a natural-language query. Reuse the user's wording where possible and keep queries in English.",
23+
description: CODEBASE_SEARCH_DESCRIPTION,
924
strict: true,
1025
parameters: {
1126
type: "object",
1227
properties: {
1328
query: {
1429
type: "string",
15-
description: "Meaning-based search query describing the information you need",
30+
description: QUERY_PARAMETER_DESCRIPTION,
1631
},
1732
path: {
1833
type: ["string", "null"],
19-
description: "Optional subdirectory (relative to the workspace) to limit the search scope",
34+
description: PATH_PARAMETER_DESCRIPTION,
2035
},
2136
},
2237
required: ["query", "path"],

src/core/prompts/tools/native-tools/execute_command.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,40 @@
11
import type OpenAI from "openai"
22

3+
const EXECUTE_COMMAND_DESCRIPTION = `Request to execute a CLI command on the system. Use this when you need to perform system operations or run specific commands to accomplish any step in the user's task. You must tailor your command to the user's system and provide a clear explanation of what the command does. For command chaining, use the appropriate chaining syntax for the user's shell. Prefer to execute complex CLI commands over creating executable scripts, as they are more flexible and easier to run. Prefer relative commands and paths that avoid location sensitivity for terminal consistency.
4+
5+
Parameters:
6+
- command: (required) The CLI command to execute. This should be valid for the current operating system. Ensure the command is properly formatted and does not contain any harmful instructions.
7+
- cwd: (optional) The working directory to execute the command in
8+
9+
Example: Executing npm run dev
10+
{ "command": "npm run dev", "cwd": null }
11+
12+
Example: Executing ls in a specific directory if directed
13+
{ "command": "ls -la", "cwd": "/home/user/projects" }
14+
15+
Example: Using relative paths
16+
{ "command": "touch ./testdata/example.file", "cwd": null }`
17+
18+
const COMMAND_PARAMETER_DESCRIPTION = `Shell command to execute`
19+
20+
const CWD_PARAMETER_DESCRIPTION = `Optional working directory for the command, relative or absolute`
21+
322
export default {
423
type: "function",
524
function: {
625
name: "execute_command",
7-
description:
8-
"Run a CLI command on the user's system. Tailor the command to the environment, explain what it does, and prefer relative paths or shell-appropriate chaining. Use the cwd parameter only when directed to run in a different directory.",
26+
description: EXECUTE_COMMAND_DESCRIPTION,
927
strict: true,
1028
parameters: {
1129
type: "object",
1230
properties: {
1331
command: {
1432
type: "string",
15-
description: "Shell command to execute",
33+
description: COMMAND_PARAMETER_DESCRIPTION,
1634
},
1735
cwd: {
1836
type: ["string", "null"],
19-
description: "Optional working directory for the command, relative or absolute",
37+
description: CWD_PARAMETER_DESCRIPTION,
2038
},
2139
},
2240
required: ["command", "cwd"],

src/core/prompts/tools/native-tools/fetch_instructions.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
import type OpenAI from "openai"
22

3+
const FETCH_INSTRUCTIONS_DESCRIPTION = `Retrieve detailed instructions for performing a predefined task, such as creating an MCP server or creating a mode.`
4+
5+
const TASK_PARAMETER_DESCRIPTION = `Task identifier to fetch instructions for`
6+
37
export default {
48
type: "function",
59
function: {
610
name: "fetch_instructions",
7-
description:
8-
"Retrieve detailed instructions for performing a predefined task, such as creating an MCP server or creating a mode.",
11+
description: FETCH_INSTRUCTIONS_DESCRIPTION,
912
strict: true,
1013
parameters: {
1114
type: "object",
1215
properties: {
1316
task: {
1417
type: "string",
15-
description: "Task identifier to fetch instructions for",
18+
description: TASK_PARAMETER_DESCRIPTION,
1619
enum: ["create_mcp_server", "create_mode"],
1720
},
1821
},

src/core/prompts/tools/native-tools/generate_image.ts

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,47 @@
11
import type OpenAI from "openai"
22

3+
const GENERATE_IMAGE_DESCRIPTION = `Request to generate or edit an image using AI models through OpenRouter API. This tool can create new images from text prompts or modify existing images based on your instructions. When an input image is provided, the AI will apply the requested edits, transformations, or enhancements to that image.
4+
5+
Parameters:
6+
- prompt: (required) The text prompt describing what to generate or how to edit the image
7+
- path: (required) The file path where the generated/edited image should be saved (relative to the current workspace directory). The tool will automatically add the appropriate image extension if not provided.
8+
- image: (optional) The file path to an input image to edit or transform (relative to the current workspace directory). Supported formats: PNG, JPG, JPEG, GIF, WEBP.
9+
10+
Example: Generating a sunset image
11+
{ "prompt": "A beautiful sunset over mountains with vibrant orange and purple colors", "path": "images/sunset.png", "image": null }
12+
13+
Example: Editing an existing image
14+
{ "prompt": "Transform this image into a watercolor painting style", "path": "images/watercolor-output.png", "image": "images/original-photo.jpg" }
15+
16+
Example: Upscaling and enhancing an image
17+
{ "prompt": "Upscale this image to higher resolution, enhance details, improve clarity and sharpness while maintaining the original content and composition", "path": "images/enhanced-photo.png", "image": "images/low-res-photo.jpg" }`
18+
19+
const PROMPT_PARAMETER_DESCRIPTION = `Text description of the image to generate or the edits to apply`
20+
21+
const PATH_PARAMETER_DESCRIPTION = `Filesystem path (relative to the workspace) where the resulting image should be saved`
22+
23+
const IMAGE_PARAMETER_DESCRIPTION = `Optional path (relative to the workspace) to an existing image to edit; supports PNG, JPG, JPEG, GIF, and WEBP`
24+
325
export default {
426
type: "function",
527
function: {
628
name: "generate_image",
7-
description:
8-
"Create a new image or edit an existing one using OpenRouter image models. Provide a prompt describing the desired output, choose where to save the image in the current workspace, and optionally supply an input image to transform.",
29+
description: GENERATE_IMAGE_DESCRIPTION,
930
strict: true,
1031
parameters: {
1132
type: "object",
1233
properties: {
1334
prompt: {
1435
type: "string",
15-
description: "Text description of the image to generate or the edits to apply",
36+
description: PROMPT_PARAMETER_DESCRIPTION,
1637
},
1738
path: {
1839
type: "string",
19-
description:
20-
"Filesystem path (relative to the workspace) where the resulting image should be saved",
40+
description: PATH_PARAMETER_DESCRIPTION,
2141
},
2242
image: {
2343
type: ["string", "null"],
24-
description:
25-
"Optional path (relative to the workspace) to an existing image to edit; supports PNG, JPG, JPEG, GIF, and WEBP",
44+
description: IMAGE_PARAMETER_DESCRIPTION,
2645
},
2746
},
2847
required: ["prompt", "path", "image"],

0 commit comments

Comments
 (0)