Skip to content

Commit 433de96

Browse files
committed
Add tool use overview documentation
1 parent 2d0a5e7 commit 433de96

File tree

1 file changed

+241
-0
lines changed

1 file changed

+241
-0
lines changed
Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
# Tool Use Overview
2+
3+
Roo Code implements a sophisticated tool system that allows AI models to interact with your development environment in a controlled and secure manner. This document explains how tools work, when they're called, and how they're managed.
4+
5+
## Core Concepts
6+
7+
### Tool Groups
8+
9+
Tools are organized into logical groups based on their functionality:
10+
11+
| Category | Purpose | Tools | Common Use |
12+
|----------|---------|-------|------------|
13+
| **Read Group** | File system reading and searching | [read_file](/features/tools/read-file), [search_files](/features/tools/search-files), [list_files](/features/tools/list-files), [list_code_definition_names](/features/tools/list-code-definition-names) | Code exploration and analysis |
14+
| **Edit Group** | File system modifications | [apply_diff](/features/tools/apply-diff), [write_to_file](/features/tools/write-to-file) | Code changes and file manipulation |
15+
| **Browser Group** | Web automation | [browser_action](/features/tools/browser-action) | Web testing and interaction |
16+
| **Command Group** | System command execution | [execute_command](/features/tools/execute-command) | Running scripts, building projects |
17+
| **MCP Group** | External tool integration | [use_mcp_tool](/features/tools/use-mcp-tool), [access_mcp_resource](/features/tools/access-mcp-resource) | Specialized functionality through external servers |
18+
| **Workflow Group** | Mode and task management | [switch_mode](/features/tools/switch-mode), [new_task](/features/tools/new-task), [ask_followup_question](/features/tools/ask-followup-question), [attempt_completion](/features/tools/attempt-completion) | Context switching and task organization |
19+
20+
### Always Available Tools
21+
22+
Certain tools are accessible regardless of the current mode:
23+
24+
- [ask_followup_question](/features/tools/ask-followup-question): Gather additional information from users
25+
- [attempt_completion](/features/tools/attempt-completion): Signal task completion
26+
- [switch_mode](/features/tools/switch-mode): Change operational modes
27+
- [new_task](/features/tools/new-task): Create subtasks
28+
29+
## Available Tools
30+
31+
### Read Tools
32+
These tools help Roo understand your code and project:
33+
34+
- [read_file](/features/tools/read-file) - Examines the contents of files
35+
- [search_files](/features/tools/search-files) - Finds patterns across multiple files
36+
- [list_files](/features/tools/list-files) - Maps your project's file structure
37+
- [list_code_definition_names](/features/tools/list-code-definition-names) - Creates a structural map of your code
38+
39+
### Edit Tools
40+
These tools help Roo make changes to your code:
41+
42+
- [apply_diff](/features/tools/apply-diff) - Makes precise, surgical changes to your code
43+
- [write_to_file](/features/tools/write-to-file) - Creates new files or completely rewrites existing ones
44+
- [insert_content](/features/tools/insert-content) - Adds new content to existing files
45+
- [search_and_replace](/features/tools/search-and-replace) - Replaces specific patterns across files
46+
47+
### Browser Tools
48+
These tools help Roo interact with web applications:
49+
50+
- [browser_action](/features/tools/browser-action) - Automates browser interactions
51+
52+
### Command Tools
53+
These tools help Roo execute commands:
54+
55+
- [execute_command](/features/tools/execute-command) - Runs system commands and programs
56+
57+
### MCP Tools
58+
These tools help Roo connect with external services:
59+
60+
- [use_mcp_tool](/features/tools/use-mcp-tool) - Uses specialized external tools
61+
- [access_mcp_resource](/features/tools/access-mcp-resource) - Accesses external data sources
62+
63+
### Workflow Tools
64+
These tools help manage the conversation and task flow:
65+
66+
- [ask_followup_question](/features/tools/ask-followup-question) - Gets additional information from you
67+
- [attempt_completion](/features/tools/attempt-completion) - Presents final results
68+
- [switch_mode](/features/tools/switch-mode) - Changes to a different mode for specialized tasks
69+
- [new_task](/features/tools/new-task) - Creates a new subtask
70+
71+
## Tool Calling Mechanism
72+
73+
### When Tools Are Called
74+
75+
Tools are invoked under specific conditions:
76+
77+
1. **Direct Task Requirements**
78+
- When specific actions are needed to complete a task as decided by the LLM
79+
- In response to user requests
80+
- During automated workflows
81+
82+
2. **Mode-Based Availability**
83+
- Different modes enable different tool sets
84+
- Mode switches can trigger tool availability changes
85+
- Some tools are restricted to specific modes
86+
87+
3. **Context-Dependent Calls**
88+
- Based on the current state of the workspace
89+
- In response to system events
90+
- During error handling and recovery
91+
92+
### Decision Process
93+
94+
The system uses a multi-step process to determine tool availability:
95+
96+
1. **Mode Validation**
97+
```typescript
98+
isToolAllowedForMode(
99+
tool: string,
100+
modeSlug: string,
101+
customModes: ModeConfig[],
102+
toolRequirements?: Record<string, boolean>,
103+
toolParams?: Record<string, any>
104+
)
105+
```
106+
107+
2. **Requirement Checking**
108+
- System capability verification
109+
- Resource availability
110+
- Permission validation
111+
112+
3. **Parameter Validation**
113+
- Required parameter presence
114+
- Parameter type checking
115+
- Value validation
116+
117+
## Technical Implementation
118+
119+
### Tool Call Processing
120+
121+
1. **Initialization**
122+
- Tool name and parameters are validated
123+
- Mode compatibility is checked
124+
- Requirements are verified
125+
126+
2. **Execution**
127+
```typescript
128+
const toolCall = {
129+
type: "tool_call",
130+
name: chunk.name,
131+
arguments: chunk.input,
132+
callId: chunk.callId
133+
}
134+
```
135+
136+
3. **Result Handling**
137+
- Success/failure determination
138+
- Result formatting
139+
- Error handling
140+
141+
### Security and Permissions
142+
143+
1. **Access Control**
144+
- File system restrictions
145+
- Command execution limitations
146+
- Network access controls
147+
148+
2. **Validation Layers**
149+
- Tool-specific validation
150+
- Mode-based restrictions
151+
- System-level checks
152+
153+
## Mode Integration
154+
155+
### Mode-Based Tool Access
156+
157+
Tools are made available based on the current mode:
158+
159+
- **Code Mode**: Full access to file system tools, code editing capabilities, command execution
160+
- **Ask Mode**: Limited to reading tools, information gathering capabilities, no file system modifications
161+
- **Architect Mode**: Design-focused tools, documentation capabilities, limited execution rights
162+
- **Custom Modes**: Can be configured with specific tool access for specialized workflows
163+
164+
### Mode Switching
165+
166+
1. **Process**
167+
- Current mode state preservation
168+
- Tool availability updates
169+
- Context switching
170+
171+
2. **Impact on Tools**
172+
- Tool set changes
173+
- Permission adjustments
174+
- Context preservation
175+
176+
## Best Practices
177+
178+
### Tool Usage Guidelines
179+
180+
1. **Efficiency**
181+
- Use the most specific tool for the task
182+
- Avoid redundant tool calls
183+
- Batch operations when possible
184+
185+
2. **Security**
186+
- Validate inputs before tool calls
187+
- Use minimum required permissions
188+
- Follow security best practices
189+
190+
3. **Error Handling**
191+
- Implement proper error checking
192+
- Provide meaningful error messages
193+
- Handle failures gracefully
194+
195+
### Common Patterns
196+
197+
1. **Information Gathering**
198+
```
199+
[ask_followup_question](/features/tools/ask-followup-question) → [read_file](/features/tools/read-file) → [search_files](/features/tools/search-files)
200+
```
201+
202+
2. **Code Modification**
203+
```
204+
[read_file](/features/tools/read-file) → [apply_diff](/features/tools/apply-diff) → [attempt_completion](/features/tools/attempt-completion)
205+
```
206+
207+
3. **Task Management**
208+
```
209+
[new_task](/features/tools/new-task) → [switch_mode](/features/tools/switch-mode) → [execute_command](/features/tools/execute-command)
210+
```
211+
212+
## Error Handling and Recovery
213+
214+
### Error Types
215+
216+
1. **Tool-Specific Errors**
217+
- Parameter validation failures
218+
- Execution errors
219+
- Resource access issues
220+
221+
2. **System Errors**
222+
- Permission denied
223+
- Resource unavailable
224+
- Network failures
225+
226+
3. **Context Errors**
227+
- Invalid mode for tool
228+
- Missing requirements
229+
- State inconsistencies
230+
231+
### Recovery Strategies
232+
233+
1. **Automatic Recovery**
234+
- Retry mechanisms
235+
- Fallback options
236+
- State restoration
237+
238+
2. **User Intervention**
239+
- Error notifications
240+
- Recovery suggestions
241+
- Manual intervention options

0 commit comments

Comments
 (0)