Skill — Agent Tool Selection (Intelligent Capability Routing)
When this skill activates
When designing tool selection logic for AI agents, optimizing tool descriptions,
building fallback chains, or analyzing tool usage patterns. Use for any scenario
where an agent must choose between multiple tools to accomplish a task.
Core principle: Specificity over generality — when two tools can both handle a
task, prefer the more specific one. It will be faster, cheaper, and more reliable.
A hammer works for screws, but a screwdriver is better.
Mandatory actions when this skill is active
Tool Selection Algorithm
Selection pipeline (in order):
Input: task description + available tools
Step 1 — Capability Match:
- For each tool: does its capability set cover the task requirements?
- Eliminate tools that CANNOT handle the task (hard filter)
Step 2 — Rank by Specificity:
- More specific tool > more general tool
- Example: "Read file" > "Bash (cat)" for reading files
- Specificity = how narrow is the tool's intended use case?
Step 3 — Rank by Cost-Efficiency:
- Among equally capable tools: prefer cheaper/faster
- Read (free, instant) > Bash cat (process spawn) > API call (network)
Step 4 — Rank by Reliability:
- Among equal cost: prefer higher success rate
- Check historical success rate per tool per task type
Step 5 — Verify Preconditions:
- Does the selected tool's preconditions hold?
- Example: Edit requires file was previously Read
- If preconditions not met: add prerequisite steps
Output: ordered list of tools to try (primary + fallbacks)
Decision matrix template:
| Task Type | Primary Tool | Fallback 1 | Fallback 2 | Anti-pattern |
|--------------------|--------------|--------------|----------- |------------------|
| Read file content | Read | Bash (cat) | — | Grep (wrong use) |
| Search for pattern | Grep | Bash (grep) | Read + scan | Read all files |
| Edit existing file | Edit | Write | — | Bash (sed) |
| Create new file | Write | Bash (echo>) | — | Edit (no file) |
| Run tests | Bash | — | — | Read test output |
| Check file exists | Bash (ls) | Read (error) | — | Grep for path |
Tool Description Optimization
Writing effective tool descriptions (they ARE prompts):
Good description (specific, with examples):
"Read a file from disk. Use when you need to see file contents.
Supports text, images, PDFs. Prefer over Bash cat/head/tail.
NOT for directories (use Bash ls)."
Bad description (vague):
"Reads things from the filesystem."
Good description (with when-to-use and when-NOT-to-use):
"Edit an existing file by replacing exact string matches.
Use when: modifying 1-5 specific locations in a file.
Do NOT use when: rewriting >50% of the file (use Write instead).
Requires: file must have been Read in this session first."
Bad description (missing boundaries):
"Edits files."
Rules:
- Include WHEN to use (positive examples)
- Include when NOT to use (negative examples — prevents misuse)
- State preconditions explicitly
- Keep descriptions under 100 words (concise > comprehensive)
- Use concrete examples, not abstract capabilities
Cost-Aware Selection
Cost hierarchy (prefer cheaper when quality is equal):
Tier 1 — Free/Instant (prefer these):
- Read (file content)
- Edit (modify file)
- Write (create file)
- Grep (pattern search in known scope)
Tier 2 — Cheap/Fast (use when Tier 1 can't):
- Bash (shell commands — process spawn overhead)
- Glob (file path patterns)
Tier 3 — Moderate (use when necessary):
- LSP (language server queries)
- Web fetch (network requests)
Tier 4 — Expensive (use sparingly):
- Sub-agent spawn (full agent instantiation)
- Multi-file analysis (token-heavy)
- External API calls (rate-limited, costly)
Rules:
- Always check if a Tier 1 tool can handle the task before reaching for Tier 3-4
- Track cumulative cost during a session (don't let tool costs compound silently)
- For repeated operations: batch when possible (one Bash with && vs many Bash calls)
- Cost includes: token consumption, time, API calls, compute resources
Fallback Chains
Designing robust fallback sequences:
Fallback chain structure:
1. Try primary tool (most specific, cheapest)
2. If fails (error, timeout, precondition unmet):
- Log failure reason
- Try fallback 1 (broader capability)
3. If fallback 1 fails:
- Try fallback 2 (most general/expensive)
4. If all fail:
- Escalate to user with: what was tried, why each failed, what's needed
Example:
Task: "Find where function X is defined"
1. Grep (fast, pattern-based) → found? done
2. LSP (semantic, language-aware) → found? done
3. Bash find + grep (brute force) → found? done
4. Escalate: "I couldn't locate function X. Can you point me to the file?"
Rules:
- Fallback chains should be pre-defined per task type (not improvised)
- Each fallback should be DIFFERENT in approach (not just retry)
- Log which level of the chain succeeded (optimize primary over time)
- Max 3 fallback levels before escalation (avoid infinite retry loops)
Tool Composition
Combining tools for complex tasks:
Composition patterns:
Sequential: Tool A output → Tool B input
Example: Grep (find file) → Read (get content) → Edit (modify)
Parallel: Tool A + Tool B independently → merge results
Example: Grep (find usages) + Read (get definition) → understand full context
Conditional: If Tool A succeeds → Tool B, else → Tool C
Example: If Read(file) succeeds → Edit, else → Write (file doesn't exist)
Iterative: Repeat Tool A until condition met
Example: Bash(test) → fails → Edit(fix) → Bash(test) → passes → done
Rules:
- Plan composition BEFORE executing (don't improvise mid-chain)
- Minimize total tool calls (combine steps where possible)
- Never call the same tool twice with identical inputs (cache/reuse results)
- If composition exceeds 5 sequential steps: consider if there's a more direct tool
Tool Disambiguation
- When multiple tools seem equally valid:
Disambiguation criteria (in priority order):
1. Fewer side effects: Read-only > Read-write (prefer observation over action)
2. More specific: Narrow tool > broad tool (Edit > Bash sed)
3. Cheaper: Less resource consumption > more
4. More reversible: Undoable > permanent (Edit > Write for existing files)
5. Better error messages: Tools with clear failure modes > opaque failures
If still tied after all criteria: pick the one that appears first in the
tool list (convention-based tie-breaking, prevents analysis paralysis)
Self-check before task completion
Before marking a task done when this skill was active:
1---2name: agent-tool-selection3description: Skill — Agent Tool Selection (Intelligent Capability Routing)4---56# Skill — Agent Tool Selection (Intelligent Capability Routing)78## When this skill activates9When designing tool selection logic for AI agents, optimizing tool descriptions,10building fallback chains, or analyzing tool usage patterns. Use for any scenario11where an agent must choose between multiple tools to accomplish a task.1213Core principle: **Specificity over generality** — when two tools can both handle a14task, prefer the more specific one. It will be faster, cheaper, and more reliable.15A hammer works for screws, but a screwdriver is better.1617## Mandatory actions when this skill is active1819### Tool Selection Algorithm20211. **Selection pipeline (in order):**22 ```23 Input: task description + available tools2425 Step 1 — Capability Match:26 - For each tool: does its capability set cover the task requirements?27 - Eliminate tools that CANNOT handle the task (hard filter)2829 Step 2 — Rank by Specificity:30 - More specific tool > more general tool31 - Example: "Read file" > "Bash (cat)" for reading files32 - Specificity = how narrow is the tool's intended use case?3334 Step 3 — Rank by Cost-Efficiency:35 - Among equally capable tools: prefer cheaper/faster36 - Read (free, instant) > Bash cat (process spawn) > API call (network)3738 Step 4 — Rank by Reliability:39 - Among equal cost: prefer higher success rate40 - Check historical success rate per tool per task type4142 Step 5 — Verify Preconditions:43 - Does the selected tool's preconditions hold?44 - Example: Edit requires file was previously Read45 - If preconditions not met: add prerequisite steps4647 Output: ordered list of tools to try (primary + fallbacks)48 ```49502. **Decision matrix template:**51 ```52 | Task Type | Primary Tool | Fallback 1 | Fallback 2 | Anti-pattern |53 |--------------------|--------------|--------------|----------- |------------------|54 | Read file content | Read | Bash (cat) | — | Grep (wrong use) |55 | Search for pattern | Grep | Bash (grep) | Read + scan | Read all files |56 | Edit existing file | Edit | Write | — | Bash (sed) |57 | Create new file | Write | Bash (echo>) | — | Edit (no file) |58 | Run tests | Bash | — | — | Read test output |59 | Check file exists | Bash (ls) | Read (error) | — | Grep for path |60 ```6162### Tool Description Optimization63643. **Writing effective tool descriptions (they ARE prompts):**65 ```66 Good description (specific, with examples):67 "Read a file from disk. Use when you need to see file contents.68 Supports text, images, PDFs. Prefer over Bash cat/head/tail.69 NOT for directories (use Bash ls)."7071 Bad description (vague):72 "Reads things from the filesystem."7374 Good description (with when-to-use and when-NOT-to-use):75 "Edit an existing file by replacing exact string matches.76 Use when: modifying 1-5 specific locations in a file.77 Do NOT use when: rewriting >50% of the file (use Write instead).78 Requires: file must have been Read in this session first."7980 Bad description (missing boundaries):81 "Edits files."82 ```8384 Rules:85 - Include WHEN to use (positive examples)86 - Include when NOT to use (negative examples — prevents misuse)87 - State preconditions explicitly88 - Keep descriptions under 100 words (concise > comprehensive)89 - Use concrete examples, not abstract capabilities9091### Cost-Aware Selection92934. **Cost hierarchy (prefer cheaper when quality is equal):**94 ```95 Tier 1 — Free/Instant (prefer these):96 - Read (file content)97 - Edit (modify file)98 - Write (create file)99 - Grep (pattern search in known scope)100101 Tier 2 — Cheap/Fast (use when Tier 1 can't):102 - Bash (shell commands — process spawn overhead)103 - Glob (file path patterns)104105 Tier 3 — Moderate (use when necessary):106 - LSP (language server queries)107 - Web fetch (network requests)108109 Tier 4 — Expensive (use sparingly):110 - Sub-agent spawn (full agent instantiation)111 - Multi-file analysis (token-heavy)112 - External API calls (rate-limited, costly)113 ```114115 Rules:116 - Always check if a Tier 1 tool can handle the task before reaching for Tier 3-4117 - Track cumulative cost during a session (don't let tool costs compound silently)118 - For repeated operations: batch when possible (one Bash with && vs many Bash calls)119 - Cost includes: token consumption, time, API calls, compute resources120121### Fallback Chains1221235. **Designing robust fallback sequences:**124 ```125 Fallback chain structure:126 1. Try primary tool (most specific, cheapest)127 2. If fails (error, timeout, precondition unmet):128 - Log failure reason129 - Try fallback 1 (broader capability)130 3. If fallback 1 fails:131 - Try fallback 2 (most general/expensive)132 4. If all fail:133 - Escalate to user with: what was tried, why each failed, what's needed134135 Example:136 Task: "Find where function X is defined"137 1. Grep (fast, pattern-based) → found? done138 2. LSP (semantic, language-aware) → found? done139 3. Bash find + grep (brute force) → found? done140 4. Escalate: "I couldn't locate function X. Can you point me to the file?"141 ```142143 Rules:144 - Fallback chains should be pre-defined per task type (not improvised)145 - Each fallback should be DIFFERENT in approach (not just retry)146 - Log which level of the chain succeeded (optimize primary over time)147 - Max 3 fallback levels before escalation (avoid infinite retry loops)148149### Tool Composition1501516. **Combining tools for complex tasks:**152 ```153 Composition patterns:154155 Sequential: Tool A output → Tool B input156 Example: Grep (find file) → Read (get content) → Edit (modify)157158 Parallel: Tool A + Tool B independently → merge results159 Example: Grep (find usages) + Read (get definition) → understand full context160161 Conditional: If Tool A succeeds → Tool B, else → Tool C162 Example: If Read(file) succeeds → Edit, else → Write (file doesn't exist)163164 Iterative: Repeat Tool A until condition met165 Example: Bash(test) → fails → Edit(fix) → Bash(test) → passes → done166 ```167168 Rules:169 - Plan composition BEFORE executing (don't improvise mid-chain)170 - Minimize total tool calls (combine steps where possible)171 - Never call the same tool twice with identical inputs (cache/reuse results)172 - If composition exceeds 5 sequential steps: consider if there's a more direct tool173174### Tool Disambiguation1751767. **When multiple tools seem equally valid:**177 ```178 Disambiguation criteria (in priority order):179 1. Fewer side effects: Read-only > Read-write (prefer observation over action)180 2. More specific: Narrow tool > broad tool (Edit > Bash sed)181 3. Cheaper: Less resource consumption > more182 4. More reversible: Undoable > permanent (Edit > Write for existing files)183 5. Better error messages: Tools with clear failure modes > opaque failures184185 If still tied after all criteria: pick the one that appears first in the186 tool list (convention-based tie-breaking, prevents analysis paralysis)187 ```188189## Self-check before task completion190191Before marking a task done when this skill was active:192193- [ ] Did I follow the selection pipeline (capability → specificity → cost → reliability)?194- [ ] Are tool descriptions specific, with positive AND negative usage examples?195- [ ] Is cost hierarchy respected (cheaper tools preferred when quality is equal)?196- [ ] Are fallback chains defined for each critical task type (max 3 levels)?197- [ ] Is tool composition planned before execution (not improvised)?198- [ ] Are disambiguations resolved by: side effects → specificity → cost → reversibility?199- [ ] Are tool calls minimized (no redundant calls, batched where possible)?200- [ ] Is escalation to user defined as the final fallback (not infinite retry)?