Skip to content

Commit 3a44bcf

Browse files
remove claude tool use backwards compatability (RooCodeInc#2102)
1 parent ccba2ed commit 3a44bcf

File tree

2 files changed

+6
-60
lines changed

2 files changed

+6
-60
lines changed

src/core/Cline.ts

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { OpenRouterHandler } from "../api/providers/openrouter"
1414
import { ApiStream } from "../api/transform/stream"
1515
import CheckpointTracker from "../integrations/checkpoints/CheckpointTracker"
1616
import { DIFF_VIEW_URI_SCHEME, DiffViewProvider } from "../integrations/editor/DiffViewProvider"
17-
import { findToolName, formatContentBlockToMarkdown } from "../integrations/misc/export-markdown"
17+
import { formatContentBlockToMarkdown } from "../integrations/misc/export-markdown"
1818
import { extractTextFromFile } from "../integrations/misc/extract-text"
1919
import { showSystemNotification } from "../integrations/notifications"
2020
import { TerminalManager } from "../integrations/terminal/TerminalManager"
@@ -860,42 +860,7 @@ export class Cline {
860860

861861
// need to make sure that the api conversation history can be resumed by the api, even if it goes out of sync with cline messages
862862

863-
let existingApiConversationHistory: Anthropic.Messages.MessageParam[] = await this.getSavedApiConversationHistory()
864-
865-
// v2.0 xml tags refactor caveat: since we don't use tools anymore, we need to replace all tool use blocks with a text block since the API disallows conversations with tool uses and no tool schema
866-
const conversationWithoutToolBlocks = existingApiConversationHistory.map((message) => {
867-
if (Array.isArray(message.content)) {
868-
const newContent = message.content.map((block) => {
869-
if (block.type === "tool_use") {
870-
// it's important we convert to the new tool schema format so the model doesn't get confused about how to invoke tools
871-
const inputAsXml = Object.entries(block.input as Record<string, string>)
872-
.map(([key, value]) => `<${key}>\n${value}\n</${key}>`)
873-
.join("\n")
874-
return {
875-
type: "text",
876-
text: `<${block.name}>\n${inputAsXml}\n</${block.name}>`,
877-
} as Anthropic.Messages.TextBlockParam
878-
} else if (block.type === "tool_result") {
879-
// Convert block.content to text block array, removing images
880-
const contentAsTextBlocks = Array.isArray(block.content)
881-
? block.content.filter((item) => item.type === "text")
882-
: [{ type: "text", text: block.content }]
883-
const textContent = contentAsTextBlocks.map((item) => item.text).join("\n\n")
884-
const toolName = findToolName(block.tool_use_id, existingApiConversationHistory)
885-
return {
886-
type: "text",
887-
text: `[${toolName} Result]\n\n${textContent}`,
888-
} as Anthropic.Messages.TextBlockParam
889-
}
890-
return block
891-
})
892-
return { ...message, content: newContent }
893-
}
894-
return message
895-
})
896-
existingApiConversationHistory = conversationWithoutToolBlocks
897-
898-
// FIXME: remove tool use blocks altogether
863+
const existingApiConversationHistory: Anthropic.Messages.MessageParam[] = await this.getSavedApiConversationHistory()
899864

900865
// if the last message is an assistant message, we need to check if there's tool use since every tool use has to have a tool response
901866
// if there's no tool use and only a text block, then we can just add a user message

src/integrations/misc/export-markdown.ts

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,7 @@ export async function downloadTask(dateTs: number, conversationHistory: Anthropi
4747
}
4848
}
4949

50-
export function formatContentBlockToMarkdown(
51-
block: Anthropic.ContentBlockParam,
52-
// messages: Anthropic.MessageParam[]
53-
): string {
50+
export function formatContentBlockToMarkdown(block: Anthropic.ContentBlockParam): string {
5451
switch (block.type) {
5552
case "text":
5653
return block.text
@@ -69,32 +66,16 @@ export function formatContentBlockToMarkdown(
6966
}
7067
return `[Tool Use: ${block.name}]\n${input}`
7168
case "tool_result":
72-
// For now we're not doing tool name lookup since we don't use tools anymore
73-
// const toolName = findToolName(block.tool_use_id, messages)
74-
const toolName = "Tool"
7569
if (typeof block.content === "string") {
76-
return `[${toolName}${block.is_error ? " (Error)" : ""}]\n${block.content}`
70+
return `[Tool${block.is_error ? " (Error)" : ""}]\n${block.content}`
7771
} else if (Array.isArray(block.content)) {
78-
return `[${toolName}${block.is_error ? " (Error)" : ""}]\n${block.content
72+
return `[Tool${block.is_error ? " (Error)" : ""}]\n${block.content
7973
.map((contentBlock) => formatContentBlockToMarkdown(contentBlock))
8074
.join("\n")}`
8175
} else {
82-
return `[${toolName}${block.is_error ? " (Error)" : ""}]`
76+
return `[Tool${block.is_error ? " (Error)" : ""}]`
8377
}
8478
default:
8579
return "[Unexpected content type]"
8680
}
8781
}
88-
89-
export function findToolName(toolCallId: string, messages: Anthropic.MessageParam[]): string {
90-
for (const message of messages) {
91-
if (Array.isArray(message.content)) {
92-
for (const block of message.content) {
93-
if (block.type === "tool_use" && block.id === toolCallId) {
94-
return block.name
95-
}
96-
}
97-
}
98-
}
99-
return "Unknown Tool"
100-
}

0 commit comments

Comments
 (0)