ruflo

🧭 Intelligent Routing

/docs/development-tools/intelligent-routing

The Route system uses Q-Learning to automatically assign tasks to the best agent based on learned performance patterns.

How Routing Works

ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
│                     INTELLIGENT ROUTING                             │
ā”œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¤
│                                                                     │
│  Task: "Fix authentication bug"                                     │
│           │                                                         │
│           ā–¼                                                         │
│  ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”                                                │
│  │ Analyze Task    │ ← Complexity, domain, keywords                 │
│  ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜                                                │
│           │                                                         │
│           ā–¼                                                         │
│  ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”                                                │
│  │ Q-Learning      │ ← Historical success rates per agent           │
│  │ Lookup          │                                                │
│  ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜                                                │
│           │                                                         │
│           ā–¼                                                         │
│  ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”                                                │
│  │ Recommend:      │                                                │
│  │ security-arch   │ → 94% confidence (auth domain expert)          │
│  ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜                                                │
│                                                                     │
ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜

Route Commands

CommandWhat It DoesExample
route taskGet agent recommendationnpx ruflo@latest route task "implement OAuth2"
route explainUnderstand routing decisionnpx ruflo@latest route explain "task"
route coverageRoute based on test coveragenpx ruflo@latest route coverage

Example: Route a Task

bash
npx ruflo@latest route task "refactor authentication to use JWT"

# Output:
# ╔══════════════════════════════════════════════════════════════╗
# ā•‘                    ROUTING RECOMMENDATION                     ā•‘
# ╠══════════════════════════════════════════════════════════════╣
# ā•‘ Task: "refactor authentication to use JWT"                    ā•‘
# ā•‘                                                                ā•‘
# ā•‘ Recommended Agent: security-architect                         ā•‘
# ā•‘ Confidence: 94%                                                ā•‘
# ā•‘                                                                ā•‘
# ā•‘ Why this agent?                                                ā•‘
# ā•‘ • Domain match: authentication, security                       ā•‘
# ā•‘ • Historical success: 12/13 similar tasks (92%)                ā•‘
# ā•‘ • Expertise: JWT, OAuth, session management                    ā•‘
# ā•‘                                                                ā•‘
# ā•‘ Alternative agents:                                            ā•‘
# ā•‘ • coder (78% confidence) - general implementation              ā•‘
# ā•‘ • backend-dev (71% confidence) - API expertise                 ā•‘
# ā•šā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•

Coverage-Aware Routing

Routes tasks to agents based on test coverage gaps:

bash
npx ruflo@latest route coverage

# Finds untested code and routes to tester agent:
# • src/auth/jwt.ts - 23% coverage → tester
# • src/api/users.ts - 45% coverage → tester
# • src/utils/crypto.ts - 0% coverage → security-architect + tester

Routing Hooks

bash
# Route via hooks (preferred)
npx ruflo@latest hooks route "implement caching layer" --include-explanation

# Record outcome for learning
npx ruflo@latest hooks post-task --task-id "task-123" --success true --agent coder

How Q-Learning Improves Over Time

IterationActionResult
1Route "auth task" → coderāŒ Failed (missing security context)
2Route "auth task" → security-architectāœ… Success
3Route "auth task" → security-architectāœ… Success
NRoute "auth task" → security-architect94% confidence (learned)

The system remembers what works and applies it to future similar tasks.