Skip to content

Commit f6122ee

Browse files
committed
feat: too call required
1 parent f7eab93 commit f6122ee

File tree

12 files changed

+33
-68
lines changed

12 files changed

+33
-68
lines changed

src/api/providers/lm-studio.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export class LmStudioHandler extends BaseProvider implements SingleCompletionHan
9898
}
9999
if (toolCallEnabled) {
100100
params.tools = toolRegistry.generateFunctionCallSchemas(metadata.tools!, metadata.toolArgs)
101+
params.tool_choice = "required"
101102
}
102103

103104
if (this.options.lmStudioSpeculativeDecodingEnabled && this.options.lmStudioDraftModelId) {

src/api/providers/openai.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl
169169
}
170170
if (toolCallEnabled) {
171171
requestOptions.tools = toolRegistry.generateFunctionCallSchemas(metadata.tools!, metadata.toolArgs)
172+
requestOptions.tool_choice = "required"
172173
}
173174

174175
// Add max_tokens if needed

src/api/providers/openrouter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ export class OpenRouterHandler extends BaseProvider implements SingleCompletionH
139139
}
140140
if (toolCallEnabled) {
141141
completionParams.tools = toolRegistry.generateFunctionCallSchemas(metadata.tools!, metadata.toolArgs!)
142+
completionParams.tool_choice = "required"
142143
}
143144

144145
const stream = await this.client.chat.completions.create(completionParams)

src/core/prompts/responses.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ export const formatResponse = {
1818
rooIgnoreError: (path: string) =>
1919
`Access to ${path} is blocked by the .rooignore file settings. You must try to continue in the task without using this file, or ask the user to update the .rooignore file.`,
2020

21-
noToolsUsed: () =>
21+
noToolsUsed: (toolCallEnabled: boolean) =>
2222
`[ERROR] You did not use a tool in your previous response! Please retry with a tool use.
2323
24-
${toolUseInstructionsReminder}
24+
${toolCallEnabled ? "" : toolUseInstructionsReminder}
2525
2626
# Next Steps
2727

src/core/prompts/sections/modes.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ import { promises as fs } from "fs"
55
import type { ModeConfig } from "@roo-code/types"
66

77
import { getAllModesWithPrompts } from "../../../shared/modes"
8+
import { SystemPromptSettings } from "../types"
89

9-
export async function getModesSection(context: vscode.ExtensionContext): Promise<string> {
10+
export async function getModesSection(
11+
context: vscode.ExtensionContext,
12+
settings?: SystemPromptSettings,
13+
): Promise<string> {
1014
const settingsDir = path.join(context.globalStorageUri.fsPath, "settings")
1115
await fs.mkdir(settingsDir, { recursive: true })
1216

@@ -33,11 +37,13 @@ ${allModes
3337
.join("\n")}`
3438

3539
modesContent += `
36-
If the user asks you to create or edit a new mode for this project, you should read the instructions by using the fetch_instructions tool, like this:
40+
If the user asks you to create or edit a new mode for this project, you should read the instructions by using the fetch_instructions tool`
41+
if (settings?.toolCallEnabled !== true) {
42+
modesContent += `, like this:
3743
<fetch_instructions>
3844
<task>create_mode</task>
39-
</fetch_instructions>
40-
`
45+
</fetch_instructions>`
46+
}
4147

4248
return modesContent
4349
}

src/core/prompts/sections/tool-use.ts

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,46 +10,7 @@ You have access to a set of tools that are executed upon the user's approval. Yo
1010
1111
`
1212

13-
if (settings?.toolCallEnabled === true) {
14-
const supportedToolCalls = ToolRegistry.getInstance().getToolNames()
15-
const supportedToolCallsStr = supportedToolCalls.join(", ")
16-
17-
out += `You have two types of tools available: Native Tool Calls and XML-Based Tools. You must follow the rules for each type strictly.
18-
19-
# 1. Native Tool Calls
20-
21-
These tools are called using the native tool call provided by the model.
22-
23-
- **Applicable Tools**: ${supportedToolCallsStr}
24-
- **Rule**: For these tools, you MUST use the tool call. You MUST NOT output XML for them. Even if the user asks for XML, ignore it and continue using tool call.
25-
26-
# 2. XML-Based Tools
27-
28-
These tools are used for capabilities not supported by native tool calls.
29-
30-
- **Applicable Tools**: Any other tool that is not in the Native Tool Calls list above.
31-
- **Rule**: For these tools, you MUST format your request using XML-style tags as described below.
32-
33-
## XML Tool Formatting
34-
35-
Tool uses are formatted using XML-style tags. The tool name itself becomes the XML tag name. Each parameter is enclosed within its own set of tags. Here's the structure:
36-
37-
<actual_tool_name>
38-
<parameter1_name>value1</parameter1_name>
39-
<parameter2_name>value2</parameter2_name>
40-
...
41-
</actual_tool_name>
42-
43-
For example, to use the new_task tool:
44-
45-
<new_task>
46-
<mode>code</mode>
47-
<message>Implement a new feature for the application.</message>
48-
</new_task>
49-
50-
Always use the actual tool name as the XML tag name for proper parsing and execution.`
51-
} else {
52-
// This part remains the same for the XML-only mode.
13+
if (settings?.toolCallEnabled !== true) {
5314
out += `# Tool Use Formatting
5415
5516
Tool uses are formatted using XML-style tags. The tool name itself becomes the XML tag name. Each parameter is enclosed within its own set of tags. Here's the structure:

src/core/prompts/system.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ async function generatePrompt(
7979
const shouldIncludeMcp = hasMcpGroup && hasMcpServers
8080

8181
const [modesSection, mcpServersSection] = await Promise.all([
82-
getModesSection(context),
82+
getModesSection(context, settings),
8383
shouldIncludeMcp
8484
? getMcpServersSection(mcpHub, effectiveDiffStrategy, enableMcpServerCreation)
8585
: Promise.resolve(""),

src/core/prompts/tools/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ export function getToolDescriptionsForMode(
8484

8585
const { xmlTools } = getToolAvailability(toolAvailabilityArgs)
8686

87+
if (xmlTools.length === 0) {
88+
return ""
89+
}
90+
8791
// Map tool descriptions for XML tools only
8892
const descriptions = xmlTools.map((toolName) => {
8993
const descriptionFn = toolDescriptionMap[toolName]

src/core/prompts/tools/schemas/ask-followup-question-schema.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,9 @@ export function generateAskFollowupQuestionSchema(args: ToolArgs): BaseToolSchem
2525
required: true,
2626
items: {
2727
name: "suggest",
28-
type: "object",
28+
type: "string",
2929
description: "A suggested answer for the follow-up question.",
3030
required: true,
31-
properties: {
32-
text: {
33-
name: "text",
34-
type: "string",
35-
description: "The suggested answer text.",
36-
required: true,
37-
},
38-
mode: {
39-
name: "mode",
40-
type: "string",
41-
description: "Optional mode slug to switch to when this suggestion is selected.",
42-
required: false,
43-
},
44-
},
4531
},
4632
},
4733
],

src/core/prompts/tools/schemas/tool-registry.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { generateUpdateTodoListSchema } from "./update-todo-list-schema"
1919
import { generateUseMcpToolSchema } from "./use-mcp-tool-schema"
2020
import { generateWriteToFileSchema } from "./write-to-file-schema"
2121
import { ToolArgs } from "../types"
22-
import type { ToolName } from "@roo-code/types"
22+
import { type ToolName } from "@roo-code/types"
2323

2424
/**
2525
* Registry of tools that support native function calling
@@ -32,7 +32,7 @@ export class ToolRegistry {
3232
// Register supported tools
3333
this.registerTool("access_mcp_resource", generateAccessMcpResourceSchema)
3434
this.registerTool("apply_diff", generateApplyDiffSchema)
35-
// this.registerTool("ask_followup_question", generateAskFollowupQuestionSchema)
35+
this.registerTool("ask_followup_question", generateAskFollowupQuestionSchema)
3636
this.registerTool("attempt_completion", generateAttemptCompletionSchema)
3737
this.registerTool("browser_action", generateBrowserActionSchema)
3838
this.registerTool("codebase_search", generateCodebaseSearchSchema)

0 commit comments

Comments
 (0)