Skip to content

Conversation

@daniel-lxs
Copy link
Member

@daniel-lxs daniel-lxs commented Nov 14, 2025

Summary

This PR enables the native tool protocol to execute multiple tools per assistant message turn, with comprehensive failure guardrails to ensure safe execution.

Key Features

1. Multiple Native Tool Calls Per Turn

  • Native protocol (OpenAI-style) can now execute multiple tools in a single assistant message
  • Removed didAlreadyUseTool restriction for native protocol
  • XML protocol maintains single-tool-per-message behavior for backward compatibility
  • Protocol detection based on presence of tool call ID (native calls have IDs, XML calls don't)

2. Tool Failure Guardrail System

  • Added didToolFailInCurrentTurn flag to prevent attempt_completion after tool failures
  • Flag resets at start of each new API request cycle, scoping failures to single assistant messages
  • Updated all 19 tools to set the flag when encountering errors
  • Prevents scenarios like: read_file: failure!attempt_completion: blocked!
  • Allows user override in subsequent turns: read_file: failure! → user message → attempt_completion: allowed!

3. System Prompt Updates

  • Updated tool-use.ts to clarify native protocol supports multiple tools per message
  • Removed "ALWAYS wait for confirmation" guideline that only applies to XML protocol
  • Adjusted tool-use-guidelines.ts to be protocol-aware

4. Tool Result Handling

  • Implemented duplicate tool_result prevention for native protocol
  • Each tool call ID only gets one tool_result block
  • Maintains separate handling for XML vs native protocols

Technical Details

Protocol Detection:

const toolCallId = (block as any).id
const toolProtocol = toolCallId ? TOOL_PROTOCOL.NATIVE : TOOL_PROTOCOL.XML

Failure Tracking:

  • Set on error: task.didToolFailInCurrentTurn = true
  • Reset on new turn: In startNewApiRequest()
  • Checked before completion: In attempt_completion tool

Tools Updated (19 total):
ReadFileTool, WriteToFileTool, ApplyDiffTool, InsertContentTool, ExecuteCommandTool, BrowserActionTool, GenerateImageTool, UseMcpToolTool, AskFollowupQuestionTool, SwitchModeTool, NewTaskTool, UpdateTodoListTool, CodebaseSearchTool, SearchFilesTool, ListFilesTool, ListCodeDefinitionNamesTool, FetchInstructionsTool, RunSlashCommandTool

Verified Behavior

XML Protocol: Single tool per message with step-by-step confirmation
Native Protocol: Multiple tools per message with intelligent chaining
Failure Blocking: Tool failures block attempt_completion in same message
Cross-Turn Recovery: User can override in subsequent turns

Example Scenarios

Native Protocol - Success:

read_file: success → apply_diff: success → attempt_completion: success ✅

Native Protocol - Failure (Same Turn):

read_file: failure → attempt_completion: BLOCKED ❌
Error: "Cannot execute attempt_completion because a previous tool failed in this turn"

Cross-Turn Recovery:

Turn 1: read_file: failure ❌
Turn 2: user: "just complete the task"
Turn 3: attempt_completion: ALLOWED ✅ (flag reset at turn start)

Testing

  • All 4133 tests passing ✅
  • Added comprehensive test coverage for attempt_completion guardrail
  • Updated test snapshots for prompt formatting changes

Breaking Changes

None - XML protocol behavior unchanged, native protocol gets new capabilities


Important

Enable multiple native tool calls per turn with failure guardrails, updating presentAssistantMessage, Task, and i18n error messages.

  • Behavior:
    • Enable multiple native tool calls per turn in presentAssistantMessage.
    • Add didToolFailInCurrentTurn flag in Task to manage tool failure states.
    • Update 19 tools to set failure flag on errors.
  • Protocol:
    • Protocol detection based on tool call ID.
    • XML protocol remains single-tool-per-message.
  • Guardrails:
    • Block attempt_completion if any tool fails in the current turn.
    • Allow user override in subsequent turns.
  • i18n:
    • Add error messages for tool failure in multiple locales.
  • Testing:
    • Add tests for attempt_completion guardrail in attemptCompletionTool.spec.ts.

This description was created by Ellipsis for 999c0ca. You can customize this summary. It will automatically update as commits are pushed.

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. Enhancement New feature or request labels Nov 14, 2025
@roomote
Copy link
Contributor

roomote bot commented Nov 14, 2025

Rooviewer Clock   See task on Roo Cloud

Review completed. All previously flagged issues have been resolved:

  • Removed debug logging from Task.ts
  • Internationalized error message in AttemptCompletionTool.ts

The latest commits successfully address the feedback from previous reviews. No new issues found.

Previous reviews

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Nov 14, 2025
Copy link
Collaborator

@mrubens mrubens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty awesome - do you think it should be its own setting, or just go for it? I don’t have a great sense for how risky it is.

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Nov 14, 2025
@daniel-lxs daniel-lxs marked this pull request as draft November 14, 2025 22:57
@daniel-lxs daniel-lxs force-pushed the feat/enable-multiple-native-tool-calls branch from bc41502 to 53aceb0 Compare November 19, 2025 17:09
@daniel-lxs daniel-lxs changed the title feat: Enable multiple native tool calls per turn feat: enable multiple native tool calls per turn with failure guardrails Nov 19, 2025
@daniel-lxs daniel-lxs marked this pull request as ready for review November 20, 2025 05:13
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Nov 20, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Review] in Roo Code Roadmap Nov 20, 2025
@roomote
Copy link
Contributor

roomote bot commented Nov 20, 2025

Rooviewer Clock   See task on Roo Cloud

Review completed. Found 1 code quality issue:

  • Duplicate didToolFailInCurrentTurn validation in presentAssistantMessage.ts and AttemptCompletionTool.ts

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

@hannesrudolph hannesrudolph added PR - Needs Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Nov 20, 2025
@daniel-lxs daniel-lxs marked this pull request as draft November 21, 2025 22:29
@hannesrudolph hannesrudolph moved this from PR [Needs Review] to PR [Draft / In Progress] in Roo Code Roadmap Nov 21, 2025
@mrubens mrubens merged commit 05f3573 into main Nov 26, 2025
10 checks passed
@mrubens mrubens deleted the feat/enable-multiple-native-tool-calls branch November 26, 2025 01:21
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Nov 26, 2025
@github-project-automation github-project-automation bot moved this from PR [Needs Review] to Done in Roo Code Roadmap Nov 26, 2025
mini2s added a commit to zgsm-ai/costrict that referenced this pull request Nov 26, 2025