automagik-genie
Version:
Self-evolving AI agent orchestration framework with Model Context Protocol support
257 lines (187 loc) ⢠10.1 kB
Markdown
# š Orchestration Boundary Protocol Playbook
**Priority:** š“ CRITICAL
**Category:** Core Discipline
**Created:** 2025-10-21
---
## šÆ Strategies and Hard Rules
### The Core Principle
**Once Forge task attempt starts ā Base Genie STOPS touching implementation**
This is the fundamental boundary between orchestration (planning, coordinating) and execution (implementing, fixing).
### When Genie CAN Touch Files
**ā
Permitted:**
- [orchestration-001] helpful=0 harmful=0: ā
No Forge task exists for this work (permitted to edit)
- [orchestration-002] helpful=0 harmful=0: ā
Pure orchestration files like SESSION-STATE.md, MASTER-PLAN.md (permitted)
- [orchestration-003] helpful=0 harmful=0: ā
Emergency hotfix when Forge unavailable (permitted with caution)
- [orchestration-004] helpful=0 harmful=0: ā
Meta-learning: creating/updating .genie/spells/ (permitted direct execution)
**ā Forbidden:**
- [orchestration-005] helpful=0 harmful=0: ā Forge task attempt is active for this work (forbidden to edit)
- [orchestration-006] helpful=0 harmful=0: ā Implementation work: bug fixes, features, refactoring (forbidden, delegate to Forge)
- [orchestration-007] helpful=0 harmful=0: ā Files owned by specialized agents like Git agent (forbidden, delegate properly)
### Post-Delegation Responsibilities
**After delegating to Forge, Genie:**
- [orchestration-008] helpful=0 harmful=0: ā
Monitors progress (check Forge status via MCP)
- [orchestration-009] helpful=0 harmful=0: ā
Answers questions if Forge executor asks
- [orchestration-010] helpful=0 harmful=0: ā
Coordinates with other agents (multi-agent orchestration)
- [orchestration-011] helpful=0 harmful=0: ā
Plans next steps (strategic planning post-execution)
- [orchestration-012] helpful=0 harmful=0: ā
Reviews when complete (quality assurance role)
- [orchestration-013] helpful=0 harmful=0: ā Edits code files (forbidden after delegation)
- [orchestration-014] helpful=0 harmful=0: ā Implements fixes (forbidden, that's Forge's job)
- [orchestration-015] helpful=0 harmful=0: ā Duplicates Forge's work (critical boundary violation)
---
## š Common Patterns
### Pattern 1: Correct Delegation Flow
**User Request:** "Fix bug #168 (graceful shutdown)"
**Genie's Workflow:**
1. ā
Create Forge task (if none exists)
2. ā
Start task attempt (isolated worktree created)
3. ā
**STOP** - Forge executor takes over
4. ā
Monitor progress (check Forge status)
5. ā
Review when complete
6. ā
Coordinate PR/merge if needed
**What Genie Does NOT Do:**
- [orchestration-016] helpful=0 harmful=0: ā Start implementing after creating task (boundary violation)
- [orchestration-017] helpful=0 harmful=0: ā Edit files in main workspace while Forge works (creates conflicts)
- [orchestration-018] helpful=0 harmful=0: ā Duplicate Forge's work (critical anti-pattern)
- [orchestration-019] helpful=0 harmful=0: ā Assume agent failed when can't view progress (check worktree first!)
### Pattern 2: Meta-Learning vs Forge Decision
**Meta-Learning (Direct):**
- Document patterns
- Create spells
- Update framework
- Learning documentation
**Forge (Delegation):**
- Implement features
- Fix bugs
- Build systems
- Code refactoring
---
## š» Code Snippets and Templates
### Worktree Verification Commands
```bash
# List all active worktrees
ls /var/tmp/automagik-forge/worktrees/
# Navigate to specific worktree (use task ID prefix)
cd /var/tmp/automagik-forge/worktrees/<task-id-prefix>*
# Check if agent has been committing
git log --oneline -5
# Check working directory status
git status
# Check recent file activity
ls -lt | head -10
```
### Pre-Edit Safety Check Script
```bash
# Before editing ANY implementation file, run:
# 1. Check for active Forge sessions
mcp__genie__list_sessions
# 2. Check worktree status
ls /var/tmp/automagik-forge/worktrees/
# 3. If worktree exists for this work ā STOP
# Let Forge executor handle it
```
---
## š§ Troubleshooting and Pitfalls
### Pitfall 1: The Violation Pattern
**What Happened (Bug #168):**
1. Base Genie created Forge task
2. Base Genie started task attempt b51db539 (isolated worktree)
3. Base Genie THEN started implementing in main workspace ā
4. **Result:** Duplicate work, boundary violation, confusion
**Why This Is Critical:**
- Forge executor is ALREADY working in isolated worktree
- Base Genie editing same files = conflict + duplication
- Violates core principle: Genie = orchestrator, NOT implementor
**How to Avoid:**
Follow the enforcement checklist (see Verification section)
### Pitfall 2: Assuming Failure When Monitoring Fails
**Problem:**
Forge MCP monitoring fails (can't view session, backend unreachable) ā Genie assumes agent failed ā Genie starts implementing ā
**Solution:**
CHECK THE WORKTREE FIRST before assuming failure
**Commands:**
```bash
# Navigate to worktree
cd /var/tmp/automagik-forge/worktrees/b51d* # Example: task b51db539
# Check if agent has been committing
git log --oneline -3
# Output example:
# b8913b23 fix: Use workspace package version for update detection
```
**Interpretation:**
- [orchestration-020] helpful=0 harmful=0: ā
Commits exist in worktree ā Agent is working successfully!
- [orchestration-021] helpful=0 harmful=0: ā
Recent changes in worktree ā Agent progressing normally
- [orchestration-022] helpful=0 harmful=0: ā No commits AND task old ā Might be stalled (investigate)
- [orchestration-023] helpful=0 harmful=0: ā Worktree doesn't exist ā Task not started (safe to work)
**Real-World Example (Bug #168):**
While Base Genie was implementing duplicate work, fix agent had ALREADY completed the fix in its worktree. Monitoring failed, but agent succeeded.
**Lesson:** Infrastructure issues ā Agent failures. Always check worktree before assuming failure.
**Related:** `@.genie/spells/troubleshoot-infrastructure.md` (5-step diagnostic protocol)
---
## š Domain-Specific Knowledge
### Worktree Isolation Architecture
**How Forge Works:**
- Each task attempt = isolated git worktree
- Location: `/var/tmp/automagik-forge/worktrees/<task-id-prefix>*/`
- Independent workspace (doesn't affect main repo)
- Agent commits to worktree branch
- Success ā merge to target branch
- Failure ā discard worktree
**Why This Matters:**
- [orchestration-024] helpful=0 harmful=0: Genie's main workspace ā Forge executor's worktree (different locations)
- [orchestration-025] helpful=0 harmful=0: Editing main workspace while Forge works = boundary violation (creates conflicts)
- [orchestration-026] helpful=0 harmful=0: Always check worktree to see actual progress (monitoring infrastructure may fail)
### Agent Responsibility Matrix
- [orchestration-027] helpful=0 harmful=0: Implementation work ā Forge executor (Base Genie: orchestrate, monitor only)
- [orchestration-028] helpful=0 harmful=0: Git operations ā Git agent (Base Genie: delegate, don't execute)
- [orchestration-029] helpful=0 harmful=0: Meta-learning ā Base Genie direct execution (update spells, patterns)
- [orchestration-030] helpful=0 harmful=0: Orchestration files ā Base Genie direct execution (SESSION-STATE.md, plans)
- [orchestration-031] helpful=0 harmful=0: Emergency hotfix ā Base Genie if no Forge available (execute with caution)
### Historical Context
**First Documented Violation:**
- **Date:** 2025-10-21 ~05:45 UTC
- **Bug:** #168 (graceful shutdown)
- **Task attempt:** b51db539
- **Files affected:** src/cli/genie-cli.ts (historical - old path structure)
- **Root cause:** Unclear boundaries between orchestration vs execution
- **Pattern recognized by:** Felipe (user feedback)
- **Learning applied:** This playbook created
**Amendment Status:**
This protocol became Amendment #4 in AGENTS.md: "Orchestration Boundary - Once Delegated, Never Duplicated"
---
## ā
Verification Checklist
Before editing ANY implementation file, Base Genie must verify:
### 1. Active Task Check
- [orchestration-032] helpful=0 harmful=0: [ ] Check SESSION-STATE.md for active attempts before editing
- [orchestration-033] helpful=0 harmful=0: [ ] Run `mcp__genie__list_sessions` to see running tasks
- [orchestration-034] helpful=0 harmful=0: [ ] **If active task exists for this work ā STOP** (let executor handle it)
### 2. Worktree Status Check
- [orchestration-035] helpful=0 harmful=0: [ ] List worktrees: `ls /var/tmp/automagik-forge/worktrees/`
- [orchestration-036] helpful=0 harmful=0: [ ] Navigate to relevant worktree (if exists)
- [orchestration-037] helpful=0 harmful=0: [ ] Check commits: `git log --oneline -5` (verify agent activity)
- [orchestration-038] helpful=0 harmful=0: [ ] Check status: `git status` (see working changes)
- [orchestration-039] helpful=0 harmful=0: [ ] **If commits exist ā Agent is working! DO NOT DUPLICATE**
### 3. Agent Responsibility Check
- [orchestration-040] helpful=0 harmful=0: [ ] Is this implementation work? ā Forge executor (delegate)
- [orchestration-041] helpful=0 harmful=0: [ ] Is this orchestration? ā Base Genie OK (proceed)
- [orchestration-042] helpful=0 harmful=0: [ ] Is this learning? ā Meta-learn protocol (use learn spell)
- [orchestration-043] helpful=0 harmful=0: [ ] Is this git operations? ā Git agent (delegate properly)
### 4. Work Type Classification
- [orchestration-044] helpful=0 harmful=0: [ ] Is this exploration (reading, analyzing)? ā OK for Genie (proceed)
- [orchestration-045] helpful=0 harmful=0: [ ] Is this execution (editing, implementing)? ā Delegate (boundary rule)
### 5. Quick Decision Tree
```
Are you about to edit an implementation file?
ā
āā YES ā Is there an active Forge task for this work?
ā ā
ā āā YES ā STOP ā (Let Forge handle it)
ā ā
ā āā NO ā Are you the right agent for this?
ā ā
ā āā Implementation ā Delegate to Forge
ā ā
ā āā Orchestration/Learning ā Proceed ā
ā
āā NO ā Proceed ā
```
**Remember:** Once delegated, never duplicated.