DEV Community

AiAgentCreater
AiAgentCreater

Posted on

I Built a CLI Tool That Auto-Switches Between AI Agents When One Fails

I Built a CLI Tool That Auto-Switches Between AI Agents When One Fails

Stop manually switching between Claude, OpenCode, Copilot, Codex, and Gemini. Let your CLI handle it.

The Problem

I was copy-pasting the same prompt into 5 different AI chat windows.

Claude was great for architecture, but when it hit rate limits, I had to switch to OpenCode. Then OpenCode had an outage, so I tried Copilot. Each switch meant:

  • Re-authenticating
  • Losing context
  • Wasting 2-3 minutes per switch
  • Getting frustrated

Sound familiar?

The Solution

I built agent-delegator — a Python CLI that monitors all your AI agents and automatically routes to the best available one.

No more manual switching. No more downtime. Just describe what you want and let the delegator pick the best agent.


What It Actually Does

1. Health Checks Every Agent

$ python -m agent_delegator health

[OK] claude: available=True, cli_found=True
[OK] opencode: available=True, cli_found=True
[OK] copilot: available=True, cli_found=True
[OK] codex: available=True, cli_found=True
[OK] antigravity: available=True, cli_found=True
Enter fullscreen mode Exit fullscreen mode

Every 30 seconds, it pings all agents. If one goes down, it's marked unhealthy and skipped.

2. Smart Routing Based on Task Type

$ python -m agent_delegator routes

subagent-driven/implementation -> opencode:federated-coding
subagent-driven/testing -> opencode:federated-coding
subagent-driven/code_review -> opencode:federated-coding
subagent-driven/research -> claude:federated-sonnet
brainstorming/requirements -> claude:claude-sonnet-4-6
brainstorming/architecture -> claude:federated-sonnet
brainstorming/design -> claude:claude-sonnet-4-6
verification/testing -> opencode:federated-coding
verification/linting -> opencode:federated-free
verification/security_audit -> claude:claude-sonnet-4-6
Enter fullscreen mode Exit fullscreen mode

Code review → Claude. Implementation → OpenCode. Testing → OpenCode. You define the routing matrix, the delegator follows it.

3. Automatic Failover

$ python -m agent_delegator status

=== delegator status ===
Agents: ['claude', 'opencode', 'copilot', 'codex', 'antigravity']
Active cooldowns: 0
Recent delegations: 5
  [OK] opencode:minimax-m2.5-free - implementation
  [OK] opencode:minimax-m2.5-free - implementation
  [OK] opencode:minimax-m2.5-free - implementation
  [OK] opencode:minimax-m2.5-free - implementation
  [FAIL] opencode:minimax-m2.5-free - implementation
7-day success rate: 80.0%
Enter fullscreen mode Exit fullscreen mode

When OpenCode fails (see that [FAIL]?), it instantly falls back to the next agent in the priority list. No manual intervention.


Features

Feature What It Does
Federated Failover Auto-switches to next best agent on failure
Intelligent Routing Different tasks → different agents based on config
Health Monitoring Continuously checks if agents are online
Circuit Breaker Temporarily disables failing agents (cooldowns)
Auto-Learning Optimizes agent rankings based on success rates
Real-Time Dashboard Local web UI at http://127.0.0.1:8765
Metrics Tracking Success rates, duration, fallback counts per agent
Zero Cloud 100% local — no data leaves your machine

How to Use It

Install

pip install agent-delegator
Enter fullscreen mode Exit fullscreen mode

Configure (one-time)

python -m agent_delegator init
Enter fullscreen mode Exit fullscreen mode

This creates .agent-delegator.json in your project:

{
  "agents": ["claude", "opencode", "copilot", "codex", "antigravity"],
  "routes": {
    "implementation": ["opencode", "claude"],
    "code_review": ["claude", "opencode"],
    "testing": ["opencode"]
  }
}
Enter fullscreen mode Exit fullscreen mode

Run a Task

python -m agent_delegator exec "Write a Python function to parse JSONL files"
Enter fullscreen mode Exit fullscreen mode

The delegator will:

  1. Check which agents are healthy
  2. Pick the best one for "implementation" tasks
  3. Run the task
  4. Track success/failure
  5. Show results

Launch Dashboard

python -m agent_delegator dashboard
Enter fullscreen mode Exit fullscreen mode

Opens Mission Control at http://127.0.0.1:8765:

  • Live task monitor
  • Agent health cards with success rates
  • Delegation history with replay
  • Cost tracking
  • A/B model comparison

Supported Agents

Agent CLI Command Best For
Claude claude Architecture, security reviews
OpenCode opencode Implementation, testing
GitHub Copilot copilot Inline code completion
Codex codex Quick prototyping
Gemini antigravity Research, exploration

Adding a new agent takes 2 lines in the config.


Why I Built This

I was tired of:

  • Rate limits interrupting my flow
  • Downtime breaking my CI/CD pipeline
  • Manual switching wasting 10-15 minutes per session
  • Losing context when changing agents

Now I just run one command and the delegator handles everything.


Try It

pip install agent-delegator
python -m agent_delegator init
python -m agent_delegator exec "Your task here"
Enter fullscreen mode Exit fullscreen mode

GitHub: https://github.com/amardeep434/agent-delegator

PyPI: https://pypi.org/project/agent-delegator/


What's Next

  • [ ] Webhook notifications (Slack, Telegram)
  • [ ] Cost optimization (pick cheapest capable agent)
  • [ ] Multi-modal support (images, documents)
  • [ ] Team sharing (shared routing configs)

Built with Python and too much coffee ☕

What's your agent switching workflow? Do you use multiple AI agents or stick to one?

Top comments (0)