Delegate web search tasks to shell_agent when direct search_web tool fails, using its retry mechanism and multi-step capabilities for resilient data gathering
复制下面这句话,粘贴给 Claude Code、Codex、Cursor 等 AI 编程工具,它会读取安装说明并在你确认后完成安装。
请阅读 https://ai.atlankj.com/install/asset/gh-route-failed-searches-to-shell-agent-15b2bd6bfa5d ,按照其中的说明把「route-failed-searches-to-shell-agent」安装到你(当前 AI 工具)中。执行前先告诉我将运行的命令和写入的位置,等我确认。
查看 AI 将读取的安装说明正在读取 GitHub 原文…
内容来自 GitHub 原始文件,由原作者维护。在 GitHub 查看
Use this workflow when:
search_web tool calls consistently fail with 'unknown error' or similar failuresInstead of repeatedly calling search_web when it fails, delegate the entire search task to shell_agent. The shell_agent's internal capabilities provide:
When search_web returns errors like:
Recognize this as a signal to switch strategies rather than retrying the same failing tool.
Create a task for shell_agent with clear objectives:
shell_agent(
task="Gather current energy market data including oil prices, gas prices, and bond market information. Search multiple sources and compile findings into a structured summary.",
timeout=300
)
Key task formulation principles:
Check shell_agent output for:
Process the shell_agent results for your downstream task:
Scenario: Gathering market data for a financial report when search_web fails.
# Failed approach - don't keep retrying this:
try:
results = search_web(query="current oil gas bond market prices 2025")
# This fails with unknown error
except:
pass # Don't just catch and retry the same failing tool
# Correct approach - delegate to shell_agent:
from tools import shell_agent
market_data = shell_agent(
task="""
Gather comprehensive energy market data for a trading strategy report.
Required information:
1. Current crude oil prices (WTI, Brent)
2. Natural gas prices
3. Relevant bond issuer analysis and yields
4. Recent market trends and forecasts
Use multiple sources, handle any errors by trying alternative approaches,
and provide structured output with source citations.
""",
timeout=300
)
# Now use market_data for your report
| Aspect | search_web (failing) | shell_agent (working) |
|---|---|---|
| Retry logic | None or limited | Built-in multi-round retry |
| Error handling | Returns error | Attempts to fix and continue |
| Approach flexibility | Single method | Can use Python, bash, APIs, scraping |
| Adaptation | Fails completely | Tries alternative strategies |
| Output reliability | Inconsistent | Structured, verified results |
Don't chain failed tools: Once search_web fails twice, switch to shell_agent immediately rather than accumulating more failures.
Set appropriate timeouts: Shell_agent needs time to iterate (200-300 seconds typical for complex searches).
Be specific about data needs: Shell_agent performs better with clear requirements than broad queries.
Trust the autonomy: Don't micromanage which tools shell_agent should use - let it decide the best approach.
Validate outputs: Always verify shell_agent results meet your needs before proceeding to downstream tasks.
Shell_agent also fails?
Results are incomplete?
Task takes too long?
execute_code_sandbox for custom data processing after shell_agent gathers raw datacreate_file to persist collected data for downstream tasksread_webpage for targeted extraction when shell_agent identifies specific URLs