Skip to content
Back to skills

Adaptive Routing

ASecurity

Routes LLM requests to a local model first (Ollama, LM Studio, llamafile), validates the response quality, and escalates to cloud only when the local result fails. Tracks local vs escalated vs cloud outcomes in a persistent dashboard. Use when: (1) user asks to run a task with a local model first, (2) user wants to reduce cloud API costs or keep requests private, (3) user wants post-outcome quality validation before committing to a local result, (4) user asks to see token savings or the routi...

  • 14 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added September 7, 2026
businesspythonbashapi

Works with

  • api

Security analysis

A96/100
  • mediumUses curl or wget to download content

Pro scans all 9 files and shows the line behind each finding

Scanned September 7, 2026

npx -y skills add modbender/skill-library-mcp --skill adaptive-routing --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Adaptive Routing?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Adaptive Routing
[![Security: A β€” Skills Directory](https://www.skillsdirectory.com/api/skills/modbender-adaptive-routing/badge)](https://www.skillsdirectory.com/skills/modbender-adaptive-routing)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: adaptive-routing
description: "Routes LLM requests to a local model first (Ollama, LM Studio, llamafile), validates the response quality, and escalates to cloud only when the local result fails. Tracks local vs escalated vs cloud outcomes in a persistent dashboard. Use when: (1) user asks to run a task with a local model first, (2) user wants to reduce cloud API costs or keep requests private, (3) user wants post-outcome quality validation before committing to a local result, (4) user asks to see token savings or the routing dashboard, (5) any request where local-vs-cloud routing should be decided automatically with a quality gate. Supports Ollama, LM Studio, and llamafile as local providers."
metadata: { "openclaw": { "emoji": "πŸ”€", "requires": { "bins": ["python3"] }, "install": [] } }
---

# Adaptive Routing

Route requests to a local LLM first. Validate the response quality. Escalate to cloud only when the local result fails the quality check. Track every outcome in a persistent dashboard.

## Quick Start

### 1. Check if a local LLM is running

```bash
python3 skills/adaptive-routing/scripts/check_local.py
```

Returns JSON: `{ "any_available": true, "best": { "provider": "ollama", "models": [...] } }`

### 2. Route a request

```bash
python3 skills/adaptive-routing/scripts/route_request.py \
  --prompt "Summarize this meeting transcript" \
  --tokens 800 \
  --local-available \
  --local-provider ollama
```

Returns: `{ "decision": "local", "reason": "...", "complexity_score": -1, "complexity_threshold": 3 }`

### 3. Execute with the chosen provider

Send the request to your local provider (Ollama, LM Studio, or llamafile).  
See [references/local-providers.md](references/local-providers.md) for curl examples.

### 4. Validate the response

```bash
python3 skills/adaptive-routing/scripts/validate_result.py \
  --response "The meeting covered three topics..." \
  --exit-code 0
```

Returns: `{ "passed": true, "score": 1.0, "reason": "ok", "should_escalate": false }`

If `should_escalate: true`, re-run step 3 with your cloud provider instead.

### 5. Log the outcome

```bash
# Local success (no escalation needed)
python3 skills/adaptive-routing/scripts/track_savings.py log \
  --kind local_success --tokens 800 --model gpt-4o

# Escalated (local failed validation, used cloud)
python3 skills/adaptive-routing/scripts/track_savings.py log \
  --kind escalated --tokens 800 --model gpt-4o
```

### 6. Show the dashboard

```bash
python3 skills/adaptive-routing/scripts/dashboard.py
```

---

## Full Routing Workflow

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  1. check_local.py  β†’  is a local provider running?      β”‚
β”‚                                                           β”‚
β”‚  2. route_request.py  β†’  local or cloud?                  β”‚
β”‚     Β· sensitivity check  (private data β†’ local)          β”‚
β”‚     Β· complexity score   (high score β†’ cloud)            β”‚
β”‚     Β· availability gate  (no local β†’ cloud)              β”‚
β”‚                                                           β”‚
β”‚  3. Execute with local provider                          β”‚
β”‚                                                           β”‚
β”‚  4. validate_result.py  β†’  did the response pass?        β”‚
β”‚     Β· passed=true   β†’ use result   (kind=local_success)  β”‚
β”‚     Β· passed=false  β†’ re-run cloud (kind=escalated)      β”‚
β”‚                                                           β”‚
β”‚  5. track_savings.py log  β†’  record the outcome          β”‚
β”‚                                                           β”‚
β”‚  6. dashboard.py  β†’  show cumulative savings             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

---

## Routing Rules (Summary)

| Condition                                                                     | Route    |
| ----------------------------------------------------------------------------- | -------- |
| No local provider available                                                   | ☁️ Cloud |
| Prompt contains sensitive data (`password`, `secret`, `api key`, `ssn`, etc.) | 🏠 Local |
| Complexity score β‰₯ threshold (default 3)                                      | ☁️ Cloud |
| Complexity score < threshold                                                  | 🏠 Local |

After routing locally, `validate_result.py` applies a second gate:

| Signal                       | Escalate? |
| ---------------------------- | --------- |
| Empty response               | Yes       |
| Process exit code != 0       | Yes       |
| Timed out                    | Yes       |
| Tool error                   | Yes       |
| Clean response, score β‰₯ 0.75 | No        |

For full scoring details, see [references/routing-logic.md](references/routing-logic.md).

---

## Configuration

Create `~/.openclaw/adaptive-routing/config.json` to tune thresholds:

```json
{
  "complexity_threshold": 3,
  "token_high_watermark": 4000,
  "token_low_watermark": 500,
  "redact_output": true
}
```

Pass `--config /path/to/config.json` to `route_request.py` to use a custom path.

---

## Executing with a Local Provider

Once `route_request.py` returns `"decision": "local"`, send the request:

### Ollama

```bash
curl http://localhost:11434/api/generate \
  -d '{"model": "llama3.2", "prompt": "YOUR_PROMPT", "stream": false}'
```

### LM Studio / llamafile (OpenAI-compatible)

```bash
curl http://localhost:1234/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{"model": "local-model", "messages": [{"role": "user", "content": "YOUR_PROMPT"}]}'
```

---

## Dashboard

The dashboard reads from `~/.openclaw/adaptive-routing/savings.json` (auto-created).

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚      πŸ”€  Adaptive Routing  Β·  Dashboard       β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Local LLM:  βœ…  ollama (llama3.2...)         β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Total requests:                           42  β”‚
β”‚  Local (passed):               31  (73.8%)    β”‚
β”‚  Escalated to cloud:                        4  β”‚
β”‚  Cloud (direct):                            7  β”‚
β”‚  Escalation rate:                       11.4%  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Tokens (local):                       84,200  β”‚
β”‚  Tokens (cloud):                        9,600  β”‚
β”‚  Cost saved (USD):                     $0.4210 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

Reset savings data:

```bash
python3 skills/adaptive-routing/scripts/track_savings.py reset
```

---

## Additional References

- **Routing & validation logic**: [references/routing-logic.md](references/routing-logic.md)
- **Local provider setup** (Ollama, LM Studio, llamafile): [references/local-providers.md](references/local-providers.md)
- **Token estimation & cloud cost table**: [references/token-estimation.md](references/token-estimation.md)

Files in this skill

  • SKILL.md7.8 KB
  • references/local-providers.md2.2 KB
  • references/routing-logic.md4.2 KB
  • references/token-estimation.md2 KB
  • scripts/check_local.py1.4 KB
  • scripts/dashboard.py2.9 KB
  • scripts/route_request.py5.3 KB
  • scripts/track_savings.py6.3 KB
  • scripts/validate_result.py2.6 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…