---
description: Meta-Orchestration Architecture: System architecture overview with components, data flow, and design decisions. Understand the framework internals.
---
The Grammar Engine for AI Collaboration
Version: 1.0 (v3.12.0) Created: January 10, 2026 Status: Design Phase → Implementation
Transform Empathy Framework from static workflows to dynamic, composable agent orchestration - a system that intelligently spawns and customizes agent teams based on task requirements, learns from outcomes, and improves over time.
Metaphor: We've built the "words" (primitives), now we're building the "grammar" (composition rules) and "language understanding" (meta-orchestrator) to form unlimited "sentences" (solutions).
User runs: empathy workflow run health-check
→ Executes pre-defined workflow
→ Fixed agent composition
→ Manual tier selection
→ No learning from outcomes
User runs: empathy orchestrate "prepare for release"
→ Meta-orchestrator analyzes task
→ Dynamically composes agent team
→ Executes with optimal strategy
→ Learns from outcome
→ Reuses successful compositions
┌─────────────────────────────────────────────────────────┐
│ User Intent │
│ "prepare for release" / "boost test coverage" │
└─────────────────┬───────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────┐
│ META-ORCHESTRATOR │
│ ┌──────────────────────────────────────────────────┐ │
│ │ 1. Task Analyzer │ │
│ │ - Parse intent │ │
│ │ - Extract requirements │ │
│ │ - Determine complexity │ │
│ └──────────────────────────────────────────────────┘ │
│ ↓ │
│ ┌──────────────────────────────────────────────────┐ │
│ │ 2. Pattern Library Query │ │
│ │ - Check for similar tasks │ │
│ │ - Retrieve proven compositions │ │
│ │ - Assess success rate │ │
│ └──────────────────────────────────────────────────┘ │
│ ↓ │
│ Found proven composition? │
│ ↓ YES ↓ NO │
│ ┌─────────────────┐ ┌──────────────────────────┐ │
│ │ 3a. Load Config │ │ 3b. Compose Dynamically │ │
│ │ - Hydrate │ │ - Select agents │ │
│ │ - Customize │ │ - Choose strategy │ │
│ └─────────────────┘ │ - Set quality gates │ │
│ └──────────────────────────┘ │
└─────────────────┬───────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────┐
│ AGENT FACTORY │
│ ┌──────────────────────────────────────────────────┐ │
│ │ Agent Templates (Archetypes) │ │
│ │ ├─ test_coverage_analyzer │ │
│ │ ├─ security_auditor │ │
│ │ ├─ code_reviewer │ │
│ │ ├─ documentation_writer │ │
│ │ ├─ performance_optimizer │ │
│ │ └─ ... (extensible) │ │
│ └──────────────────────────────────────────────────┘ │
│ ↓ │
│ ┌──────────────────────────────────────────────────┐ │
│ │ Spawn & Customize Agents │ │
│ │ - Apply task-specific instructions │ │
│ │ - Select appropriate tier │ │
│ │ - Configure tools and capabilities │ │
│ └──────────────────────────────────────────────────┘ │
└─────────────────┬───────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────┐
│ EXECUTION STRATEGIES │
│ ┌─────────────────────────────────────────────────┐ │
│ │ Grammar Rules (Composition Patterns): │ │
│ │ 1. Sequential (A → B → C) │ │
│ │ 2. Parallel (A || B || C) │ │
│ │ 3. Debate (A ⇄ B ⇄ C → Synthesis) │ │
│ │ 4. Teaching (Junior → Expert validation) │ │
│ │ 5. Refinement (Draft → Review → Polish) │ │
│ │ 6. Adaptive (Classifier → Specialist) │ │
│ └─────────────────────────────────────────────────┘ │
└─────────────────┬───────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────┐
│ EXECUTION & AGGREGATION │
│ - Run agents per strategy │
│ - Monitor quality gates │
│ - Aggregate results │
│ - Generate actionable report │
└─────────────────┬───────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────┐
│ LEARNING & PERSISTENCE │
│ ┌──────────────────────────────────────────────────┐ │
│ │ Agent Configuration Store │ │
│ │ - Save successful compositions │ │
│ │ - Track success rate │ │
│ │ - Record quality scores │ │
│ └──────────────────────────────────────────────────┘ │
│ ↓ │
│ ┌──────────────────────────────────────────────────┐ │
│ │ Pattern Library Integration │ │
│ │ - Contribute learned patterns │ │
│ │ - Enable cross-task learning │ │
│ │ - Build organizational knowledge │ │
│ └──────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────┘
Purpose: Reusable agent archetypes that can be customized for specific tasks
Location: src/empathy_os/orchestration/agent_templates.py
@dataclass
class AgentTemplate:
"""Reusable agent archetype."""
id: str
role: str
capabilities: list[str]
tier_preference: str # "CHEAP", "CAPABLE", "PREMIUM"
tools: list[str]
default_instructions: str
quality_gates: dict[str, Any]
# Example templates
TEMPLATES = {
"test_coverage_analyzer": AgentTemplate(
id="test_coverage_analyzer",
role="Test Coverage Expert",
capabilities=["analyze_gaps", "suggest_tests", "validate_coverage"],
tier_preference="CAPABLE",
tools=["coverage_analyzer", "ast_parser"],
default_instructions="...",
quality_gates={"min_coverage": 80},
),
# ... more templates
}Purpose: Analyzes tasks and dynamically composes agent teams
Location: src/empathy_os/orchestration/meta_orchestrator.py
class MetaOrchestrator:
"""Intelligent task analyzer and agent composition engine."""
def orchestrate(self, task: str, context: dict) -> ExecutionPlan:
"""Analyze task and create execution plan."""
# 1. Parse task intent
requirements = self.task_analyzer.analyze(task, context)
# 2. Check pattern library for proven solutions
proven_composition = self.check_proven_compositions(requirements)
if proven_composition:
return self.load_composition(proven_composition)
# 3. Dynamically compose new agent team
return self.compose_agents(requirements)
def compose_agents(self, requirements: TaskRequirements) -> ExecutionPlan:
"""Create agent team based on requirements."""
agents = []
for capability in requirements.needed_capabilities:
template = self.select_template(capability)
agent = self.agent_factory.spawn(template, requirements)
agents.append(agent)
strategy = self.select_strategy(requirements)
return ExecutionPlan(agents=agents, strategy=strategy)Purpose: Spawns and customizes agents from templates
Location: src/empathy_os/orchestration/agent_factory.py
class AgentFactory:
"""Spawns agents from templates with task-specific customization."""
def spawn(self, template: AgentTemplate, requirements: TaskRequirements) -> Agent:
"""Create agent instance from template."""
# Customize tier based on requirements
tier = self.select_tier(template.tier_preference, requirements)
# Generate task-specific instructions
instructions = self.customize_instructions(
template.default_instructions,
requirements
)
return Agent(
id=f"{template.id}_{uuid.uuid4().hex[:8]}",
role=template.role,
tier=tier,
instructions=instructions,
tools=template.tools,
quality_gates=template.quality_gates,
)Purpose: Define composition patterns for agent coordination
Location: src/empathy_os/orchestration/strategies/
# Sequential Strategy (A → B → C)
class SequentialStrategy(ExecutionStrategy):
"""Execute agents one after another, passing results forward."""
async def execute(self, agents: list[Agent], context: dict) -> dict:
results = []
current_context = context
for agent in agents:
result = await agent.execute(current_context)
results.append(result)
current_context = {**current_context, **result}
return self.aggregate(results)
# Parallel Strategy (A || B || C)
class ParallelStrategy(ExecutionStrategy):
"""Execute all agents simultaneously, aggregate results."""
async def execute(self, agents: list[Agent], context: dict) -> dict:
tasks = [agent.execute(context) for agent in agents]
results = await asyncio.gather(*tasks)
return self.aggregate(results)
# ... More strategies (Debate, Teaching, Refinement, Adaptive)Purpose: Persist and retrieve successful agent compositions
Location: src/empathy_os/orchestration/config_store.py
@dataclass
class AgentComposition:
"""Saved agent configuration."""
id: str
task_pattern: str # "release_prep", "test_coverage_boost", etc.
agents: list[dict] # Serialized agent configs
strategy: str
quality_gates: dict
success_rate: float
avg_quality_score: float
usage_count: int
created_at: datetime
last_used: datetime
class AgentConfigurationStore:
"""Persist successful compositions."""
def save(self, composition: AgentComposition, outcome: dict):
"""Save composition with outcome metrics."""
# Update success rate
# Store in pattern library
# Persist to disk
def load(self, task_pattern: str) -> AgentComposition | None:
"""Retrieve best composition for task pattern."""
# Query pattern library
# Return highest success ratePurpose: Enable learning from execution outcomes
Location: Integration with existing src/empathy_os/pattern_library.py
# When orchestration completes:
pattern = Pattern(
id=f"orchestration_{task_id}",
agent_id="meta_orchestrator",
pattern_type="agent_composition",
name=task_pattern,
context={
"agents": [agent.role for agent in composition.agents],
"strategy": composition.strategy,
"requirements": requirements.to_dict(),
},
confidence=outcome["quality_score"],
)
pattern_library.contribute_pattern("meta_orchestrator", pattern)Use when: Tasks must be done in order, each depends on previous
Example: Test Coverage Boost
coverage_analyzer → test_generator → quality_validator
Use when: Independent validations, multi-perspective review
Example: Release Preparation
[security_audit || performance_check || code_quality || docs_check] → aggregator
Use when: Need multiple expert opinions, architecture decisions
Example: Architecture Review
[architect_scale || architect_cost || architect_simplicity] → synthesizer
Use when: Cost-effective generation with quality assurance
Example: Documentation Generation
junior_writer(CHEAP) → quality_gate → (pass ? done : expert_review(CAPABLE))
Use when: Iterative improvement, quality ladder
Example: API Documentation
drafter(CHEAP) → reviewer(CAPABLE) → polisher(PREMIUM)
Use when: Variable complexity, right-sizing needed
Example: Bug Triage
classifier(CHEAP) → route(simple|moderate|complex) → specialist(appropriate_tier)
Task Pattern: release_prep
Agents (Parallel):
- Test Coverage Analyzer (CAPABLE)
- Security Auditor (PREMIUM)
- Code Quality Reviewer (CAPABLE)
- Documentation Completeness Checker (CHEAP)
- Performance Validator (CAPABLE)
Strategy: Parallel → Weighted Aggregation
Quality Gates:
- Test coverage ≥80%
- No critical/high security issues
- Code quality score ≥7/10
- All public APIs documented
- Performance within SLA
Success Criteria: All quality gates pass
Task Pattern: test_coverage_boost
Agents (Sequential):
- Coverage Analyzer (CAPABLE) → Identify gaps
- Test Generator (CAPABLE) → Generate missing tests
- Quality Validator (CAPABLE) → Ensure test quality
Strategy: Sequential with feedback loops
Quality Gates:
- Coverage improvement ≥10%
- Test quality score ≥8/10
- All tests pass
Success Criteria: Coverage target met with high-quality tests
Task Pattern: security_deep_dive
Agents (Parallel → Synthesis):
- Security Auditor (focus: vulnerabilities) (PREMIUM)
- Security Auditor (focus: threat modeling) (PREMIUM)
- Security Auditor (focus: compliance) (PREMIUM)
- Code Reviewer (synthesize findings) (CAPABLE)
Strategy: Parallel → Debate → Synthesis
Quality Gates:
- All critical findings addressed
- Compliance requirements met
- Remediation plan generated
1. Execute orchestrated workflow
↓
2. Measure outcome:
- Quality score (0-100)
- Success/failure
- Time to completion
- Cost
↓
3. Update composition:
- Increment usage_count
- Update success_rate
- Adjust confidence
↓
4. Save to pattern library:
- Make available for future queries
- Enable cross-task learning
↓
5. Next similar task:
- Query returns proven composition
- Reuse with customization
- Continue improving
- Architecture design document
- Agent Template system
- Agent Factory
- Basic Meta-Orchestrator
- Sequential strategy
- Parallel strategy
Deliverable: Can compose simple agent teams
- Debate strategy
- Teaching strategy
- Refinement strategy
- Adaptive routing strategy
- Task Analyzer (requirement extraction)
Deliverable: All 6 composition patterns working
- Agent Configuration Store
- Pattern Library integration
- Success rate tracking
- Composition reuse logic
Deliverable: System learns from outcomes
- Release Preparation workflow
- Test Coverage Boost workflow
- Security Deep Dive workflow
- Quality gates implementation
- Weighted aggregation
Deliverable: Production-ready workflows
-
empathy orchestratecommand - Progress visualization
- Result aggregation UI
- Configuration management
- Documentation
Deliverable: User-facing interface
- Comprehensive test suite
- Performance optimization
- Error handling
- Logging and observability
- Production hardening
Deliverable: v3.12.0 Release
src/empathy_os/orchestration/
├── __init__.py
├── meta_orchestrator.py # Main orchestrator
├── agent_templates.py # Template definitions
├── agent_factory.py # Agent spawning
├── config_store.py # Composition persistence
├── task_analyzer.py # Requirement extraction
├── strategies/
│ ├── __init__.py
│ ├── base.py # ExecutionStrategy base class
│ ├── sequential.py # Sequential composition
│ ├── parallel.py # Parallel composition
│ ├── debate.py # Debate/consensus
│ ├── teaching.py # Junior → Expert
│ ├── refinement.py # Draft → Review → Polish
│ └── adaptive.py # Classifier → Specialist
├── compositions/ # Pre-built compositions
│ ├── __init__.py
│ ├── release_prep.py
│ ├── test_coverage_boost.py
│ └── security_deep_dive.py
└── aggregators/ # Result aggregation
├── __init__.py
├── weighted_score.py
├── consensus.py
└── priority_list.py
tests/orchestration/
├── test_meta_orchestrator.py
├── test_agent_factory.py
├── test_strategies.py
├── test_compositions.py
└── integration/
└── test_end_to_end.py
docs/
├── META_ORCHESTRATION_ARCHITECTURE.md # This file
├── ORCHESTRATION_GUIDE.md # User guide
└── COMPOSITION_PATTERNS.md # Pattern reference
Simple primitives that combine in powerful ways
System improves automatically through pattern library
Adaptive tier selection, appropriate agent for each task
Clear execution plans, visible agent decisions
Comprehensive testing, error handling, observability
- Agent Sandboxing: Agents execute in isolated environments
- Input Validation: Task requirements validated before execution
- Rate Limiting: Prevent runaway agent spawning
- Audit Logging: All orchestration decisions logged
- Quality Gates: Hard stops for critical failures
Phase 1 Success:
- Can compose 2+ agents (sequential and parallel)
- Execution completes successfully
- Results aggregated correctly
Phase 2 Success:
- All 6 composition patterns implemented
- Task analyzer extracts requirements accurately
- Strategy selection logic working
Phase 3 Success:
- Compositions persisted and retrieved
- Success rate tracking accurate
- Reuse improves performance >20%
Phase 4 Success:
- Release prep workflow catches real issues
- Test coverage boost achieves >10% improvement
- Quality gates prevent bad releases
Overall Success (v3.12.0):
- 80% of orchestrations succeed
- 50% of tasks reuse proven compositions
- Average quality score >75/100
- User satisfaction: "This is game-changing"
- ✅ Complete architecture design ← YOU ARE HERE
- Build Agent Template system → Week 1, Day 1
- Implement Agent Factory → Week 1, Day 2
- Create Meta-Orchestrator → Week 1, Day 3-5
- Build Sequential & Parallel strategies → Week 1, Day 6-7
- Natural language task parsing (GPT-4 integration)
- Visual composition builder (web UI)
- Cross-organization pattern sharing
- Federated learning (privacy-preserving)
- Custom agent template creation (user-defined)
- Real-time orchestration monitoring dashboard
Status: Architecture design complete, ready for implementation ✅ Next: Begin Phase 1 - Foundation (Agent Templates)