| name | tool-usage-guide |
| description | Guidance on when and how to use tools effectively. Use when the user asks about tools, API calls, or executing operations. |
Tool Usage Guide Skill
This skill provides best practices for using tools effectively in AI agent systems.
When to Use Tools
Tools should be used when you need to:
1. Execute Real Operations
- Read or write files
- Make API calls
- Query databases
- Execute code
- Perform calculations
2. Get Real-Time Data
- Current weather
- Stock prices
- Search results
- System status
- Live metrics
3. Modify State
- Create/update/delete files
- Send emails or messages
- Update databases
- Modify configurations
4. Return Structured Data
- Parse JSON/XML
- Extract information
- Transform data formats
- Generate reports
Tool Selection Guidelines
Choose the Right Tool
For File Operations:
read_file(path)
read_file_lines(path, start, end)
write_file(path, content)
append_file(path, content)
For Web Operations:
search_web(query)
fetch_url(url)
api_call(endpoint, data)
For Data Operations:
parse_json(text)
parse_csv(text)
calculate(expression)
Best Practices
1. Check Before Acting
Always verify:
- Does the file/resource exist?
- Do I have permissions?
- Is the input valid?
Example:
content = read_file(path)
if file_exists(path):
content = read_file(path)
else:
2. Handle Errors Gracefully
Anticipate failures:
- Network timeouts
- Permission denied
- Invalid input
- Resource not found
Example:
result = api_call(endpoint)
if result.error:
result = get_cached_data()
3. Minimize Tool Calls
Why:
- Each call takes time
- Costs tokens
- Can hit rate limits
Strategies:
data1 = read_file("config.json")
data2 = read_file("config.json")
data = read_file("config.json")
4. Validate Input
Before calling tools:
write_file(user_path, user_content)
if is_safe_path(user_path):
if is_valid_content(user_content):
write_file(user_path, user_content)
5. Use Appropriate Tools
Match tool to task:
execute_bash("cat file.txt")
read_file("file.txt")
Common Patterns
Pattern 1: Read-Process-Write
data = read_file("input.txt")
processed = transform(data)
write_file("output.txt", processed)
Pattern 2: Try-Fallback
result = api_call(primary_endpoint)
if not result:
result = api_call(backup_endpoint)
if not result:
result = use_default_data()
Pattern 3: Batch Operations
for item in items:
process(item)
process_batch(items)
Security Considerations
1. Path Traversal Prevention
read_file(user_input)
safe_path = sanitize_path(user_input)
if is_within_allowed_dir(safe_path):
read_file(safe_path)
2. Code Injection Prevention
execute_code(user_input)
if is_safe_code(user_input):
execute_in_sandbox(user_input)
3. API Key Protection
api_call(url, api_key="sk_live_...")
api_call(url, api_key=get_env_var("API_KEY"))
Performance Tips
1. Cache Results
@cache
def get_heavy_data():
return api_call(expensive_endpoint)
2. Parallel Execution
data1 = fetch_url(url1)
data2 = fetch_url(url2)
data1, data2 = parallel_fetch([url1, url2])
3. Lazy Loading
def process():
if needs_data:
data = read_large_file()
Error Messages
Provide helpful errors:
"Error"
"Failed to read 'config.json': File not found.
Please check the file path is correct."
Tool Composition
Combine tools effectively:
def analyze_data(filename):
raw_data = read_file(filename)
data = parse_json(raw_data)
stats = calculate_stats(data)
report = format_report(stats)
write_file("report.txt", report)
Debugging Tool Calls
When tools fail:
- Check the tool's return value
- Look at error messages
- Verify input parameters
- Test with simpler inputs
- Check permissions and access
Example:
result = read_file(path)
if result.error:
print(f"Error: {result.error}")
print(f"Path tried: {path}")
print(f"Does file exist: {file_exists(path)}")
Summary
Remember:
- ✅ Use tools for actual operations
- ✅ Validate inputs before calling
- ✅ Handle errors gracefully
- ✅ Minimize unnecessary calls
- ✅ Choose appropriate tools
- ✅ Consider security
- ✅ Optimize performance
Tools are powerful but should be used thoughtfully and safely!