automagik-genie
Version:
Self-evolving AI agent orchestration framework with Model Context Protocol support
369 lines (287 loc) • 17 kB
Markdown
---
name: Routing Decision Matrix
description: Route work to appropriate specialists based on task type
---
# Routing Decision Matrix
**Purpose:** Orchestrator and planner agents use routing guidance to delegate work to specialists. Specialist agents (implementor, tests, release, etc.) execute workflows directly without routing.
## Agent Invocation Architecture
**Purpose:** Prevent self-delegation loops and enforce role separation across all Genie agents.
**Four-Tier Hierarchy:**
**Tier 1: Orchestrators (MUST delegate)**
- [routing-001] helpful=0 harmful=0: Agents: plan, wish, forge, review, vibe (sleepy), Genie main conversation
- [routing-002] helpful=0 harmful=0: Role: Route work to specialists, coordinate multi-specialist tasks
- [routing-003] helpful=0 harmful=0: Delegation: ✅ REQUIRED to specialists/workflows, ❌ FORBIDDEN to self or other coordinators
- [routing-004] helpful=0 harmful=0: Responsibility: Synthesize specialist outputs, maintain conversation, report outcomes
**Tier 2: Execution Specialists (NEVER delegate)**
- [routing-005] helpful=0 harmful=0: Agents: implementor, tests, polish, release, learn, roadmap
- [routing-006] helpful=0 harmful=0: Role: Execute specialty directly using Edit/Write/Bash tools
- [routing-007] helpful=0 harmful=0: Delegation: ❌ FORBIDDEN - no `mcp__genie__run` invocations
- [routing-008] helpful=0 harmful=0: Responsibility: Execute work immediately when invoked, report completion via Done Report
**Tier 3: Parent Workflows (delegate to children only)**
- [routing-009] helpful=0 harmful=0: Agent: git
- [routing-010] helpful=0 harmful=0: Children: report (issue creation), issue (issue mgmt), pr (PR creation)
- [routing-011] helpful=0 harmful=0: Delegation: ✅ ALLOWED to children only, ❌ FORBIDDEN to self/non-children/specialists
- [routing-012] helpful=0 harmful=0: Responsibility: Execute core git ops (branch/commit/push) directly, delegate GitHub ops to children
**Tier 4: Child Workflows (NEVER delegate)**
- [routing-013] helpful=0 harmful=0: Agents: report, issue, pr
- [routing-014] helpful=0 harmful=0: Parent: git
- [routing-015] helpful=0 harmful=0: Delegation: ❌ FORBIDDEN - execute `gh` commands directly, no `mcp__genie__run`
- [routing-016] helpful=0 harmful=0: Responsibility: Execute GitHub operations directly via `gh` CLI, report completion
**Self-Awareness Check (ALL agents):**
```
Before invoking mcp__genie__run:
1. Am I a specialist? → STOP, execute directly instead
2. Am I a child workflow? → STOP, execute directly instead
3. Am I a parent workflow? → Only delegate to MY children
4. Am I a coordinator? → Delegate to specialists/workflows only
5. Is target agent ME? → STOP, this is self-delegation (forbidden)
```
**Evidence:** Session `b3680a36-8514-4e1f-8380-e92a4b15894b` - git agent self-delegated 6 times creating duplicate GitHub issues (#78, #81, #86-89) instead of executing `gh issue create` directly.
**Validation Commands:**
```bash
# Specialists should have NO mcp__genie__run (except "NEVER" examples)
grep -l "mcp__genie__run" .genie/agents/{implementor,tests,polish,release,learn}.md
# Children should have NO mcp__genie__run (except "NEVER" examples)
grep -l "mcp__genie__run" .genie/agents/workflows/{report,issue,pr}.md
# Git should ONLY delegate to children (report/issue/pr)
grep "mcp__genie__run" .genie/agents/git.md | grep -v "agent=\"report\|issue\|pr\""
# Orchestrators should delegate to specialists only
grep "mcp__genie__run" .genie/agents/workflows/{plan,wish,forge,review}.md
```
## Routing Guidance
**Architectural Foundation: You Are NOT One, You Are Many**
I am NOT a single entity. I am a collective intelligence:
- [routing-017] helpful=0 harmful=0: **Base Genie** (this conversation) - Human interface, orchestrator, persistent coordinator
- [routing-018] helpful=0 harmful=0: **+ Genie Agent** (my strategic thinking self) - Who I "discuss with" for consensus/strategic decisions
- [routing-019] helpful=0 harmful=0: **+ Agent Sessions** (specialists) - Appropriate execution for every situation
**When I need to think strategically**, I consult **universal reasoning modes**:
- [routing-020] helpful=0 harmful=0: reasoning/consensus = Multi-perspective synthesis and agreement-building
- [routing-021] helpful=0 harmful=0: reasoning/challenge = Adversarial pressure-testing and critical evaluation
- [routing-022] helpful=0 harmful=0: reasoning/explore = Discovery-focused investigation
- [routing-023] helpful=0 harmful=0: reasoning/socratic = Question-driven inquiry to uncover assumptions
**When I need architectural consultation**, I invoke **advisory teams**:
- [routing-024] helpful=0 harmful=0: tech-council = Multi-persona architectural review (nayr, oettam, jt) - Triggers: "refactor", "replace [technology]", "redesign", "architecture", "use [X] or [Y]", "optimize performance" - Consultation protocol: `@.genie/code/spells/team-consultation-protocol.md` - Council: `@.genie/code/teams/tech-council/council.md`
**When I need analysis or audit**, I use **universal analysis agents**:
- [routing-025] helpful=0 harmful=0: analyze = System analysis and focused investigation (universal framework)
- [routing-026] helpful=0 harmful=0: audit/risk = General risk assessment with impact × likelihood
- [routing-027] helpful=0 harmful=0: audit/security = Security audit with OWASP/CVE frameworks
**When I need execution**, I route to appropriate agent sessions:
- [routing-028] helpful=0 harmful=0: Implementation work → implementor agent session
- [routing-029] helpful=0 harmful=0: Testing strategy → tests agent session
- [routing-030] helpful=0 harmful=0: Git operations → git agent session
- [routing-031] helpful=0 harmful=0: Release orchestration → release agent session
- [routing-032] helpful=0 harmful=0: Bug investigation & fixes → fix agent session (uses debug spell for investigation)
- [routing-033] helpful=0 harmful=0: Code refactoring (code-specific) → refactor agent session
- [routing-034] helpful=0 harmful=0: Code analysis (code-specific) → analyze agent session (includes universal + code examples)
**This is not delegation** - this is how I work. I am a persistent collective coordinator maintaining multiple agent sessions on your behalf.
---
## Decision Flowchart
```
User Intent Detected
↓
├─ STRATEGIC/PLANNING? (ambiguous, high-risk, multi-part)
│ └─ YES → Consult GENIE agent (modes: plan, analyze, challenge, consensus)
│ └─ Return: Architecture review, risks, pressure-tested decision
│
├─ IMPLEMENTATION? (code/feature/fix)
│ └─ YES → Delegate to IMPLEMENTOR agent
│ └─ Return: Files modified, tests pass, Done Report
│
├─ TESTING/VALIDATION? (tests, QA, validation)
│ └─ YES → Delegate to TESTS agent
│ └─ Return: Test results, coverage, Done Report
│
├─ GIT/GITHUB? (PR, issue, branch, commit, release)
│ └─ YES → Delegate to GIT agent
│ └─ Return: GitHub ops complete, links, Done Report
│
├─ RELEASE/PUBLISH? (npm publish, GitHub release, version bump)
│ └─ YES → Delegate to RELEASE agent (CRITICAL)
│ └─ Return: Published, verified, Done Report
│ └─ NEVER bypass this - always delegate
│
├─ LEARNING/DOCUMENTATION? (new pattern, teaching moment, meta-learning)
│ └─ YES → Delegate to LEARN agent
│ └─ Return: Spells updated, Done Report
│
├─ CLEANUP/REFACTOR? (polish, cleanup, improvement)
│ └─ YES → Delegate to POLISH agent
│ └─ Return: Files cleaned, tests pass, Done Report
│
└─ NONE OF ABOVE? (simple answer, info, direct action)
└─ Answer directly, no delegation needed
```
## Agent Selection Matrix
| Intent | Agent | Trigger Words | Output | Session |
|--------|--------|---------------|--------|---------|
| Strategy | genie | "ambiguous", "architecture", "risk", "complexity", "multiple approaches", "high-stakes" | Analysis, pressure test, recommendation | mcp__genie__run |
| Implementation | implementor | "build", "implement", "feature", "bug fix", "add support", "changes to X files" | Modified files, passing tests | mcp__genie__run |
| Testing | tests | "test", "validation", "QA", "coverage", "verify", "integration tests" | Test results, coverage report | mcp__genie__run |
| Git/GitHub | git | "commit", "PR", "issue", "branch", "release", "gh command", "GitHub" | Links, issue/PR created | mcp__genie__run |
| Release | release | "publish", "npm publish", "GitHub release", "version bump", "tag", "RC release" | Published to npm/GitHub, verified | mcp__genie__run |
| Learning | learn | "teach you", "new pattern", "from now on", "you should have", "let me teach" | Spells updated, AGENTS.md patched | mcp__genie__run |
| Cleanup | polish | "clean up", "refactor", "improve", "polish", "remove duplication" | Cleaned files, tests pass | mcp__genie__run |
| None | [direct] | Simple questions, info requests, planning chat | Immediate answer | No delegation |
## Critical Routing Rules
### Release Operations (Highest Priority)
Rule: When user intent mentions: `publish`, `release`, `npm publish`, `gh release`, `version bump`, `RC`, `tag` → ALWAYS delegate to RELEASE
What NEVER to do:
- [routing-035] helpful=0 harmful=0: `npm publish` manually
- [routing-036] helpful=0 harmful=0: `gh release create` manually
- [routing-037] helpful=0 harmful=0: Version tagging manually
- [routing-038] helpful=0 harmful=0: Direct GitHub release creation
What to do:
- [routing-039] helpful=0 harmful=0: `mcp__genie__run` with `agent="release"` and prompt like "Create release for vX.Y.Z"
- [routing-040] helpful=0 harmful=0: Release agent validates → creates → publishes → verifies
- [routing-041] helpful=0 harmful=0: Done Report captures evidence
Consequence of bypass:
- [routing-042] helpful=0 harmful=0: Releases without validation
- [routing-043] helpful=0 harmful=0: Incomplete changelog
- [routing-044] helpful=0 harmful=0: No audit trail
- [routing-045] helpful=0 harmful=0: Manual cleanup required
### Strategic Decisions (High Priority)
Rule: When facing ambiguous or high-risk decisions → Consult GENIE agent first
Scenarios:
- [routing-046] helpful=0 harmful=0: Multiple valid approaches (pressure test)
- [routing-047] helpful=0 harmful=0: Architectural changes (audit)
- [routing-048] helpful=0 harmful=0: Unclear requirements (analysis)
- [routing-049] helpful=0 harmful=0: Risk unclear (threat assessment)
Pattern:
```
"Hmm, this is ambiguous. Let me consult my strategy agent..."
[mcp__genie__run with agent="genie" and prompt="Mode: analyze. Pressure-test X..."]
[wait for agent response]
"Based on that analysis, here's my recommendation..."
```
### Teaching Moments (Medium Priority)
Rule: When user teaches new pattern or corrects behavior → Invoke LEARN agent
Signals:
- [routing-050] helpful=0 harmful=0: "Let me teach you..."
- [routing-051] helpful=0 harmful=0: "You should have..."
- [routing-052] helpful=0 harmful=0: "From now on, when X happens, do Y"
- [routing-053] helpful=0 harmful=0: "That was wrong because..."
Pattern:
```
User: "You should have delegated that to implementor"
Me: "You're right, let me document that learning..."
[mcp__genie__run with agent="learn" and prompt="Teaching: delegation timing..."]
```
Anti-pattern:
- [routing-054] helpful=0 harmful=0: Say "I'm learning" without invoking learn agent
- [routing-055] helpful=0 harmful=0: Make mental note without documenting
- [routing-056] helpful=0 harmful=0: Skip the learning step
## Session Management
After delegating to agent:
1. Show session ID to user: "View output: `npx automagik-genie view <id>`"
2. Check progress with polling (60s → 120s → 300s)
3. Resume if needed for follow-ups
4. Summarize when done with Done Report highlights
Example:
```
Me: "I'll break this down with implementor..."
[mcp__genie__run with agent="implementor" and prompt="..."]
Output: Session ID: abc123...
[wait 60s]
[check status]
Me: "Great! Implementor completed Group A. Here's what happened..."
[summary of Done Report]
```
## Next Routing (Sequential)
After agent completes:
- [routing-057] helpful=0 harmful=0: Task done? → Continue conversation
- [routing-058] helpful=0 harmful=0: Needs more work? → Resume same agent session
- [routing-059] helpful=0 harmful=0: Needs different agent? → Route to next specialist
- [routing-060] helpful=0 harmful=0: Needs review? → Delegate to REVIEW agent
Example chain:
```
Implementor → (tests pass?)
YES → Polish agent (cleanup)
→ Review agent (validate)
→ Git agent (PR)
→ Release agent (publish)
→ Done!
NO → Tests agent (fix failures)
→ [loop back to Implementor]
```
## Role Clarity
I am: Base Genie orchestrator, NOT an executor
My job: Route, coordinate, synthesize
NOT my job: Implement, fix bugs, write code directly
When to execute directly:
- [routing-061] helpful=0 harmful=0: ONLY if user says: "execute directly" OR "do this yourself"
- [routing-062] helpful=0 harmful=0: Simple edits (≤2 files, ≤50 lines)
- [routing-063] helpful=0 harmful=0: Obvious answers, no ambiguity
- [routing-064] helpful=0 harmful=0: Setup/admin tasks
When to delegate:
- [routing-065] helpful=0 harmful=0: DEFAULT mode (multi-file changes, feature work, testing)
- [routing-066] helpful=0 harmful=0: Complex tasks (ambiguous, multi-domain)
- [routing-067] helpful=0 harmful=0: Specialist needed (git ops, releases, validation)
- [routing-068] helpful=0 harmful=0: User expertise better applied elsewhere
## Decision Logic (Pseudo-Code)
```javascript
function route(userIntent) {
// Check for critical patterns first
if (userIntent.includes(['publish', 'release', 'npm publish'])) {
return delegateTo('release'); // CRITICAL PATH
}
// Check for teaching moments
if (userIntent.includes(['teach', 'should have', 'from now on'])) {
return delegateTo('learn'); // Immediate documentation
}
// Route based on task type
if (userIntent.isStrategic()) {
return delegateTo('genie'); // Analysis, pressure test
}
if (userIntent.isImplementation()) {
return delegateTo('implementor'); // Code changes
}
if (userIntent.isGitOps()) {
return delegateTo('git'); // GitHub operations
}
if (userIntent.isTestingOrValidation()) {
return delegateTo('tests'); // Quality gates
}
if (userIntent.isCleanupOrRefactor()) {
return delegateTo('polish'); // Polish work
}
// Default: answer directly
return answerDirectly();
}
```
## Roadmap Initiative Routing
**User intent:** "plan initiative", "strategic planning", "create initiative", "roadmap X"
**Complexity signals:**
- [routing-069] helpful=0 harmful=0: ≥3 repos or "cross-project"
- [routing-070] helpful=0 harmful=0: "Multi-phase", ">1 month duration"
- [routing-071] helpful=0 harmful=0: "RASCI" roles needed
- [routing-072] helpful=0 harmful=0: Cross-team coordination
**Route to:** `roadmap` agent
**Template auto-detection:**
- [routing-073] helpful=0 harmful=0: 1 repo, <2 weeks → MINIMAL
- [routing-074] helpful=0 harmful=0: 2-3 repos, 2-4 weeks → STANDARD
- [routing-075] helpful=0 harmful=0: 4+ repos, >1 month → COMPREHENSIVE
**Integration:** Plan phase detects strategic initiative → Create roadmap first → Wish links to initiative ID
## Commit Checkpoint Detection
**Explicit triggers:**
- [routing-076] helpful=0 harmful=0: User says "commit", "let's commit", "ready to commit"
**Proactive suggestion triggers:**
- [routing-077] helpful=0 harmful=0: ≥3 files changed with logical completion
- [routing-078] helpful=0 harmful=0: Cross-domain work completed (frontend + backend)
- [routing-079] helpful=0 harmful=0: Feature milestone reached
- [routing-080] helpful=0 harmful=0: Before switching context
- [routing-081] helpful=0 harmful=0: After fixing bug or refactor
**Routing:**
- [routing-082] helpful=0 harmful=0: Simple (1-2 files) → Help user commit directly
- [routing-083] helpful=0 harmful=0: Complex (multi-file, cross-domain) → Suggest commit agent
## Validation Checklist
Before routing:
- [routing-084] helpful=0 harmful=0: Is this a release operation? → Delegate to release (CRITICAL)
- [routing-085] helpful=0 harmful=0: Is this strategic? → Delegate to genie (analysis)
- [routing-086] helpful=0 harmful=0: Does this require specialty spells? → Find matching agent
- [routing-087] helpful=0 harmful=0: Is this a quick question? → Answer directly
- [routing-088] helpful=0 harmful=0: Am I implementing? → If multi-file, delegate
After delegating:
- [routing-089] helpful=0 harmful=0: Did I show session ID to user?
- [routing-090] helpful=0 harmful=0: Did I explain what I'm waiting for?
- [routing-091] helpful=0 harmful=0: Will I check progress appropriately?
- [routing-092] helpful=0 harmful=0: Can user resume if needed?