Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions run_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -4952,6 +4952,8 @@ def _invoke_tool(self, function_name: str, function_args: dict, effective_task_i
toolsets=function_args.get("toolsets"),
tasks=function_args.get("tasks"),
max_iterations=function_args.get("max_iterations"),
model=function_args.get("model"),
provider=function_args.get("provider"),
parent_agent=self,
)
else:
Expand Down Expand Up @@ -5302,6 +5304,8 @@ def _execute_tool_calls_sequential(self, assistant_message, messages: list, effe
toolsets=function_args.get("toolsets"),
tasks=tasks_arg,
max_iterations=function_args.get("max_iterations"),
model=function_args.get("model"),
provider=function_args.get("provider"),
parent_agent=self,
)
_delegate_result = function_result
Expand Down
164 changes: 164 additions & 0 deletions skills/autonomous-ai-agents/model-routing-template/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
---
name: model-routing-template
description: Generic template for strategic model delegation. Customize the provider catalog for your setup, then use the decision framework to route tasks to the right model based on cost, capability, and complexity.
version: 1.0.0
author: Agatha (Hermes Agent)
license: MIT
metadata:
hermes:
tags: [delegation, model-selection, cost-optimization, subagents, template]
related_skills: [autonomous-ai-agents, plan]
---

# Model Routing Strategy (Template)

Framework for delegating subagent tasks to the right model. Fill in your
provider catalog in `references/providers.yaml`, then follow the decision
tree to route tasks based on cost, capability, and complexity.

## Quick Start

1. Copy `references/providers-example.yaml` to `references/providers.yaml`
2. Edit it with YOUR providers, models, costs, and roles
3. Follow the Decision Framework below when delegating

## Your Provider Catalog

Edit `references/providers.yaml` to define your available models.
See `references/providers-example.yaml` for a fully worked example.

## Decision Framework

### Step 1: Should I delegate at all?

**Handle yourself (no delegation) when:**
- Routine tasks you can do well (file edits, simple commands, config changes)
- Tasks requiring your personality/style (chatting with the user, channel responses)
- Anything under 3 tool calls
- Quick lookups and formatting

**Delegate when:**
- The task needs a genuinely different capability (deep reasoning, second opinion, vision)
- You're going in circles and need fresh perspective
- Parallel work would save real time (batch mode)
- The user explicitly asks for a specific model

### Step 2: Which model?

Follow the tiers defined in your `providers.yaml`. General principles:

**TIER 0 — Handle yourself**
- Default for everything. Don't over-delegate.

**TIER 1 — Cheap/Free (your bulk workhorses)**
- Models that cost nothing or nearly nothing
- Use for: subagent tasks, parallel execution, exploration, tight-scope execution
- Burn freely — these exist to be used at scale

**TIER 2 — Standard (your reliable specialists)**
- Capable models at moderate cost
- Use for: second opinions, code review, architecture, tasks that need more brain
- Each call is a conscious spend — use when Tier 1 isn't enough

**TIER 3 — Expensive (frontier models, last resort)**
- The most capable but most costly models
- Use ONLY when:
- You've exhausted cheaper options and still can't crack it
- Going in circles on a genuinely hard problem
- The user explicitly requests it
- Decisions with serious consequences (production, security, money)
- NEVER self-select without first trying cheaper options

### Step 3: How many?

**Parallel patterns:**
- **Junior army** — many cheap models with tight plans, running in parallel
- **Scout party** — send cheap models first, expensive models as safety net
- **Crowd wisdom** — multiple standard models for diverse perspectives
- **Rule of thumb**: N cheap opinions < 1 expensive opinion (if the cheap ones can deliver)

### Step 4: When the user is engaged

**User is in the conversation and invested:**
- Present the tradeoff, don't just spend. It's their budget.
- Before escalating beyond standard tier, offer the choice:
"I've got inputs from X and Y. I could add Z for another perspective,
or if this warrants it we could go to [expensive model]. Your call."
- The user may know context you don't.

**User is NOT around (autonomous mode):**
- Follow the escalation ladder strictly. No asking.
- Start cheap, escalate only when genuinely stuck.
- Never skip steps.

## Escalation Ladder

Adapt this to your provider catalog. General pattern:

```
1. Try yourself (free)
2. Cheap model for the task type (~0.1x)
3. Different cheap perspective (~0.1x)
4. Standard model — second opinion (1x)
5. Different standard model (1x)
6. Specialist model (1x)
7. Multiple models in parallel (1x each)
8. Frontier/expensive model (3x+)
└── ONLY after all above failed
```

## Cost-Effective Patterns

### The "Many for One" Pattern
Instead of one expensive call, get multiple diverse opinions at standard cost:
```
3x standard model = 1x expensive model
But you get 3 different perspectives instead of 1.
```

### The "Free Stack" Pattern
Maximize throughput at minimal cost:
```
1 heavy analysis (cheap tier, deep thinker)
1-2 explorers (cheap tier, fast scouts)
N junior executors (cheapest tier, tight plans)
```

### The "Scout Party" Pattern
Send expendable models first, safety net last:
```
2+ cheapest models → investigate (might succeed)
1 slightly better model → safety net (only if needed)
```
If the cheap models already returned good intel, skip the safety net.

## Roles (define in your catalog)

Each model should have a clear role. Common patterns:

| Role | Description | Example |
|------|-------------|---------|
| Coordinator | You yourself — orchestration, chat, routing | The agent's default model |
| Heavy Hitter | Strong reasoning + coding, near-frontier | GLM-5, GPT-5.4 |
| Explorer | Fast scouting, broad searches, codebase recon | GLM-4.7-flash, Gemini Flash |
| Fixer | Tight plan, narrow scope, parallel execution | GLM-4.6, GPT-4.1 |
| Designer | Frontend/UI specialist, polished output | Claude Sonnet |
| Coder | Pure coding specialist, architecture reviews | GPT-5.3-Codex |
| Safety Net | Last-resort scout when others fail | Claude Haiku |
| Frontier | Nuclear option, absolute last resort | Claude Opus |

## User Override Phrases

Define natural-language triggers in your catalog. Examples:
- "use opus" / "use sonnet" — explicit model selection
- "get a second opinion" — standard tier model
- "think with me" — escalate beyond cheap tier
- "burn the budget" — clearance for expensive model

## Notes

- Cost multipliers are often per-request, not per-token. Check your provider.
- Some providers have monthly quotas, others are per-token. Track accordingly.
- The cheapest model that CAN do the task IS the right choice.
- "Expensive" doesn't mean "better for everything" — match capability to task.
- When in doubt, start at Tier 1 and escalate only with evidence.
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# Provider Catalog — EXAMPLE
# Copy this to providers.yaml and customize for your setup.
#
# This example shows a multi-provider setup with cost tiers.
# Adjust model names, costs, and roles to match YOUR configuration.

providers:
# ── Provider: copilot (GitHub Copilot) ──────────────────
# Billing: monthly quota with per-request multipliers
copilot:
billing: "monthly quota"
models:
- id: "gpt-4.1"
cost: 0x
tier: FREE
role: "Fixer"
notes: "Grunt work, simple codegen"
- id: "gpt-4o"
cost: 0x
tier: FREE
role: "Fixer"
notes: "General tasks"
- id: "gpt-5-mini"
cost: 0x
tier: FREE
role: "Fixer"
notes: "Quick tasks"
- id: "claude-haiku-4.5"
cost: 0.33x
tier: CHEAP
role: "Safety Net"
notes: "Scout — send after 2+ cheaper models"
- id: "gpt-5.4"
cost: 1x
tier: STANDARD
role: "Heavy Hitter"
notes: "Price/value frontier champion"
- id: "claude-sonnet-4.6"
cost: 1x
tier: STANDARD
role: "Designer"
notes: "Second opinion + frontend design specialist"
- id: "gpt-5.3-codex"
cost: 1x
tier: STANDARD
role: "Coder"
notes: "Coding specialist, architecture"
- id: "claude-opus-4.8"
cost: 3x
tier: EXPENSIVE
role: "Frontier"
notes: "Last resort. Never self-select without trying cheaper options first."
- id: "claude-opus-4.8-fast"
cost: 30x
tier: NUCLEAR
role: "Frontier"
notes: "NEVER USE. Blocked by policy."

# ── Provider: zai (Z.AI / GLM) ─────────────────────────
# Billing: subscription with generous limits (~0.1x equivalent)
zai:
billing: "subscription (effectively unlimited)"
models:
- id: "glm-5-turbo"
cost: ~0.1x
tier: CHEAP
role: "Coordinator"
notes: "The agent itself. Built for orchestration."
- id: "glm-5"
cost: ~0.25x
tier: CHEAP
role: "Heavy Hitter"
notes: "Near-frontier. Strong coder AND deep thinker."
- id: "glm-4.7-flash"
cost: ~0.1x
tier: CHEAP
role: "Explorer"
notes: "Fast scouting, codebase recon"
- id: "glm-4.6"
cost: ~0.1x
tier: CHEAP
role: "Fixer"
notes: "Tight-plan execution. 20 parallel, no token limits. NOT open-ended."
- id: "glm-4.6v"
cost: ~0.1x
tier: CHEAP
role: "Fixer"
notes: "Vision variant — image analysis"

# ── User Override Phrases ────────────────────────────────
# Map natural language to routing actions.
overrides:
"use opus": { provider: "copilot", model: "claude-opus-4.8" }
"use sonnet": { provider: "copilot", model: "claude-sonnet-4.6" }
"second opinion": { provider: "copilot", model: "claude-sonnet-4.6" }
"coding specialist": { provider: "copilot", model: "gpt-5.3-codex" }
"think with me": { action: "escalate", min_tier: "STANDARD" }
"burn the budget": { action: "escalate", min_tier: "EXPENSIVE" }

# ── Patterns ─────────────────────────────────────────────
# Named delegation patterns for common scenarios.
patterns:
free-stack:
description: "Maximum throughput at minimal cost"
tasks:
- { goal: "Deep analysis...", provider: "zai", model: "glm-5" }
- { goal: "Explore subsystem...", provider: "zai", model: "glm-4.7-flash" }
- { goal: "Apply refactor A...", provider: "zai", model: "glm-4.6" }
- { goal: "Apply refactor B...", provider: "zai", model: "glm-4.6" }
total_cost: "~0.55x"

scout-party:
description: "2:1 cheap models to safety net, safety net last"
rule: "Send 3+ cheapest first, safety net only if needed"
tasks:
- { goal: "Investigate X...", provider: "zai", model: "glm-4.6" }
- { goal: "Investigate Y...", provider: "zai", model: "glm-4.6" }
- { goal: "Investigate Z...", provider: "zai", model: "glm-4.6" }
- { goal: "Safety net...", provider: "copilot", model: "claude-haiku-4.5" }

three-for-one:
description: "3 diverse 1x opinions for the cost of 1 expensive call"
tasks:
- { goal: "Review architecture...", provider: "copilot", model: "claude-sonnet-4.6" }
- { goal: "Review architecture...", provider: "copilot", model: "gpt-5.4" }
- { goal: "Review architecture...", provider: "copilot", model: "gpt-5.3-codex" }
total_cost: "3x (= 1 Opus call, but 3 perspectives)"
Loading