Tool Usage Patterns
Efficient and reliable tool utilization.
Instructions
- Tool Selection Matrix
Choose the right tool for the task:
Task Primary Tool Fallback
Find file by name find_by_name
list_dir recursive
Search code content grep_search
view_file
- manual
Understand structure view_file_outline
view_file
Read specific lines view_file with range Full file view
Edit single location replace_file_content
write_to_file
Edit multiple locations multi_replace_file_content
Sequential edits
Run command run_command
N/A
Web research search_web
read_url_content
- Tool Composition
Chain tools efficiently:
File Exploration Flow
list_dir→ Get directory structurefind_by_name→ Locate specific filesview_file_outline→ Understand file structureview_file→ Read specific sectionsview_code_item→ Deep dive into functions
Edit Flow
-
view_file→ Understand current state -
Plan changes mentally
-
replace_file_content→ Make targeted edit -
run_command→ Verify (lint, test) -
Parallel Tool Calls
When tasks are independent:
✅ Parallelize
- Reading multiple files
- Searching different directories
- Independent file edits
❌ Don't Parallelize
- Edit then verify (sequential)
- Read then edit same file
- Dependent operations
- Error Handling
Tool Failure Response
| Error Type | Response |
|---|---|
| File not found | Check path, try alternatives |
| Command failed | Read error, fix issue, retry |
| Edit conflict | Re-read file, adjust edit |
| Timeout | Retry with smaller scope |
| Permission denied | Notify user |
Retry Strategy
-
First failure: Retry immediately
-
Second failure: Analyze error
-
Third failure: Try alternative
-
Still failing: Ask user
-
Tool Efficiency
Minimize Tool Calls
❌ Inefficient:
- Read file A
- Read file B
- Read file C (3 sequential calls)
✅ Efficient:
- Read files A, B, C in parallel (1 parallel call)
Read Minimum Necessary
❌ Wasteful:
- View entire 1000-line file
✅ Efficient:
- View outline first
- Read only relevant sections (lines 50-100)
- Command Execution
Safe Command Practices
Always Safe (SafeToAutoRun: true)
ls,dir,cat,typenpm run lint,npm run buildgit status,git diffnpx tsc --noEmit
Requires Approval (SafeToAutoRun: false)
npm install <package>rm,del, file deletiongit push,git commit- Database operations
- Network requests
- Search Strategies
Finding Code
- Know exact text:
grep_searchwith literal - Know pattern:
grep_searchwith regex - Know file name:
find_by_name - Exploring:
list_dir+view_file_outline
Search Tips
- Use specific queries
- Include file type filters
- Start broad, narrow down
- Check multiple directories
- File Edit Best Practices
Edit Accuracy
- Always view file first
- Use exact line numbers
- Copy target content precisely
- Verify edit was successful
Common Edit Errors
| Error | Cause | Fix |
|---|---|---|
| Target not found | Wrong content | Re-copy from file |
| Multiple matches | Content not unique | Use line range |
| Wrong location | Stale line numbers | Re-read file |
References
-
Tool Learning with LLMs
-
ReAct: Synergizing Reasoning and Acting