fix: prevent duplicate responses when using native OpenAI tool format

- Fixed issue where text content was being duplicated in responses when using native tool format
- The problem occurred because text was accumulated in both assistantMessage and assistantMessageContent
- Solution: For native protocol with text blocks, use only the text blocks from assistantMessageContent
- For XML protocol or native without text blocks, use the accumulated assistantMessage as before

Fixes #9669
This commit is contained in:
Roo Code 2025-11-28 08:40:18 +00:00
parent e682c039de
commit c0cbc3deee

View file

@ -2924,8 +2924,23 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
// Build the assistant message content array
const assistantContent: Array<Anthropic.TextBlockParam | Anthropic.ToolUseBlockParam> = []
// Add text content if present
if (assistantMessage) {
// For native protocol, check if we already have text blocks in assistantMessageContent
// to avoid duplication. For XML protocol, use the accumulated assistantMessage.
const hasTextBlocks = this.assistantMessageContent.some((block) => block.type === "text")
if (!shouldUseXmlParser && hasTextBlocks) {
// Native protocol with text blocks - use the text blocks from assistantMessageContent
const textBlocks = this.assistantMessageContent.filter((block) => block.type === "text")
for (const block of textBlocks) {
if (block.type === "text" && block.content) {
assistantContent.push({
type: "text" as const,
text: block.content,
})
}
}
} else if (assistantMessage) {
// XML protocol or native protocol without text blocks - use accumulated assistantMessage
assistantContent.push({
type: "text" as const,
text: assistantMessage,