Skip to content

Commit 26aa469

Browse files
committed
allow use five tools in one call
1 parent 568fb87 commit 26aa469

File tree

5 files changed

+32
-11
lines changed

5 files changed

+32
-11
lines changed

src/core/assistant-message/presentAssistantMessage.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export async function presentAssistantMessage(cline: Task) {
8080

8181
switch (block.type) {
8282
case "text": {
83-
if (cline.didRejectTool || cline.didAlreadyUseTool) {
83+
if (cline.didRejectTool || cline.didAlreadyUseTool > 0) {
8484
break
8585
}
8686

@@ -212,11 +212,18 @@ export async function presentAssistantMessage(cline: Task) {
212212
break
213213
}
214214

215-
if (cline.didAlreadyUseTool) {
215+
if (cline.didAlreadyUseTool > 4) {
216216
// Ignore any content after a tool has already been used.
217217
cline.userMessageContent.push({
218218
type: "text",
219-
text: `Tool [${block.name}] was not executed because a tool has already been used in this message. Only one tool may be used per message. You must assess the first tool's result before proceeding to use the next tool.`,
219+
text: `Tool [${block.name}] was not executed because too many tools have already been used in this message. Only five tools may be used per message. You must assess the first tool's result before proceeding to use the next tool.`,
220+
})
221+
222+
break
223+
} else if (cline.didAlreadyUseTool > 0 && block.name === "attempt_completion") {
224+
cline.userMessageContent.push({
225+
type: "text",
226+
text: `Tool [attempt_completion] was not executed because attempt_completion cannot use with other tools.`,
220227
})
221228

222229
break
@@ -234,7 +241,7 @@ export async function presentAssistantMessage(cline: Task) {
234241
// Once a tool result has been collected, ignore all other tool
235242
// uses since we should only ever present one tool result per
236243
// message.
237-
cline.didAlreadyUseTool = true
244+
cline.didAlreadyUseTool++
238245
}
239246

240247
const askApproval = async (
@@ -491,7 +498,7 @@ export async function presentAssistantMessage(cline: Task) {
491498
// skip execution since `didRejectTool` and iterate until `contentIndex` is
492499
// set to message length and it sets userMessageContentReady to true itself
493500
// (instead of preemptively doing it in iterator).
494-
if (!block.partial || cline.didRejectTool || cline.didAlreadyUseTool) {
501+
if (!block.partial || cline.didRejectTool || cline.didAlreadyUseTool > 4) {
495502
// Block is finished streaming and executing.
496503
if (cline.currentStreamingContentIndex === cline.assistantMessageContent.length - 1) {
497504
// It's okay that we increment if !didCompleteReadingStream, it'll

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export function getSharedToolUseSection(): string {
33
44
TOOL USE
55
6-
You have access to a set of tools that are executed upon the user's approval. You can use one tool per message, and will receive the result of that tool use in the user's response. You use tools step-by-step to accomplish a given task, with each tool use informed by the result of the previous tool use.
6+
You have access to a set of tools that are executed upon the user's approval. You can use up to five tools in a single message to reduce the number of interaction rounds, and will receive the results of those tool use in the user's response. Read and write tools should not be used simultaneously in one request. You use tools step-by-step to accomplish a given task, with each tool use informed by the result of the previous tool use.
77
88
# Tool Use Formatting
99
@@ -15,11 +15,21 @@ Tool uses are formatted using XML-style tags. The tool name itself becomes the X
1515
...
1616
</actual_tool_name>
1717
18-
For example, to use the read_file tool:
18+
<actual_tool_name2>
19+
<parameter1_name>value1</parameter1_name>
20+
<parameter2_name>value2</parameter2_name>
21+
...
22+
</actual_tool_name2>
23+
24+
For example, to use two read_file tools:
1925
2026
<read_file>
2127
<path>src/main.js</path>
2228
</read_file>
2329
30+
<read_file>
31+
<path>src/index.js</path>
32+
</read_file>
33+
2434
Always use the actual tool name as the XML tag name for proper parsing and execution.`
2535
}

src/core/prompts/tools/new-task.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ToolArgs } from "./types"
33
export function getNewTaskDescription(_args: ToolArgs): string {
44
return `## new_task
55
Description: This will let you create a new task instance in the chosen mode using your provided message.
6+
IMPORTANT: This tool can only be called once per message.
67
78
Parameters:
89
- mode: (required) The slug of the mode to start the new task in (e.g., "code", "debug", "architect").

src/core/task/Task.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export class Task extends EventEmitter<ClineEvents> {
183183
userMessageContent: (Anthropic.TextBlockParam | Anthropic.ImageBlockParam)[] = []
184184
userMessageContentReady = false
185185
didRejectTool = false
186-
didAlreadyUseTool = false
186+
didAlreadyUseTool = 0
187187
didCompleteReadingStream = false
188188

189189
constructor({
@@ -1178,7 +1178,7 @@ export class Task extends EventEmitter<ClineEvents> {
11781178
this.userMessageContent = []
11791179
this.userMessageContentReady = false
11801180
this.didRejectTool = false
1181-
this.didAlreadyUseTool = false
1181+
this.didAlreadyUseTool = 0
11821182
this.presentAssistantMessageLocked = false
11831183
this.presentAssistantMessageHasPendingUpdates = false
11841184

@@ -1260,9 +1260,9 @@ export class Task extends EventEmitter<ClineEvents> {
12601260
// get generation details.
12611261
// UPDATE: It's better UX to interrupt the request at the
12621262
// cost of the API cost not being retrieved.
1263-
if (this.didAlreadyUseTool) {
1263+
if (this.didAlreadyUseTool > 4) {
12641264
assistantMessage +=
1265-
"\n\n[Response interrupted by a tool use result. Only one tool may be used at a time and should be placed at the end of the message.]"
1265+
"\n\n[Response interrupted by a tool use result. Only five tools may be used at a time and should be placed at the end of the message.]"
12661266
break
12671267
}
12681268
}

src/core/tools/newTaskTool.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ export async function newTaskTool(
8888
cline.isPaused = true
8989
cline.emit("taskPaused")
9090

91+
// no tool should be used after new task tool
92+
cline.didAlreadyUseTool += 5
93+
9194
return
9295
}
9396
} catch (error) {

0 commit comments

Comments
 (0)