Orchestrata Ultimate / Specs / 005-multi-agent

005-multi-agent: Multi-Agent Coordination

The Multi-Agent Coordination system manages the lifecycle, communication, and escalation of Volks (agents) in Orchestrata. It supports lightweight Prolog agents, hierarchical agent organization, constitutional constraints, and the Junior Volk delegation system for parallel task execution.

At a glance

Item Value
Spec directory specs/005-multi-agent/
Status line in the spec Complete
Requirement IDs defined 48
With a @traces citation in src/ 25 (52.1%)
With a @traces citation in tests/ 0 (0.0%)
Tracked files 8
RTM page 005-multi-agent

Reading this spec

Multi-Agent Coordination manages the lifecycle, communication and escalation of Volks (agents). It supports lightweight Prolog agents, hierarchical agent organization, constitutional constraints, and the Junior Volk delegation system for parallel task execution.

The scope is a set of user stories: lightweight agent spawning, escalation paths, agent lifespan management, agent monitoring, constitutional constraints and agent escalation, followed by the Junior Volk stories: spawning junior Volks, senior-to-junior delegation, parallel delegation and synthesis, and browser-based free-tier access. Requirements use the REQ-005- prefix; the spec defines 48.

The design in the overview rests on a Volk Registry for discovery, hierarchical parent-child relationships, Prolog-driven constitutional validation, the CXP protocol for all inter-agent communication, and Junior Volk drivers for the CLI, an API and a browser. The aims are to coordinate specialized agents, resolve escalations and conflicts, enforce constraints across agents and manage the spawn, monitor and cleanup cycle.

In the code, the package is orchestrata_ultimate/agents. The largest tracers are orchestrata_ultimate/agents/lifecycle, orchestrata_ultimate/agents/escalation, orchestrata_ultimate/agents/runtime, orchestrata_ultimate/agents/hierarchy and orchestrata_ultimate/agents/prolog_bridge. The per-requirement view is on the RTM page.

The spec's status line reads Complete. It tracks 8 files and defines 48 requirement IDs. The full text follows below.

Measured coverage is 25 of 48 requirements cited by at least one @traces in src/ (52.1%), spread over 12 modules; the module citing the most of them is orchestrata_ultimate/agents/lifecycle (13 requirements). In tests/, 0 requirements are cited by a test-side @traces.

Coverage gaps: 23 requirements have no citing symbol. The largest untraced groups are REQ-005-NFR2 (1), REQ-005-NFR3 (1), REQ-005-US-007 (1). Untraced means no @traces names the ID; the behaviour may still exist in code that was never annotated. Test-side citations are thinner than code-side ones (0 against 25).

Requirements

Checkbox is the state recorded in the requirements checklist; Traced by is the count of src/ symbols whose @traces names the ID.

ID Done Requirement Traced by
REQ-005-US-001-001 yes As a developer, I can spawn lightweight Prolog agents that handle specialized tasks without creating process overhead 10
REQ-005-US-002-001 yes As a system architect, I can define agent escalation paths that automatically promote issues requiring broader context 3
REQ-005-US-003-001 yes As a developer, I can configure agent lifespans to automatically terminate agents when their task is complete 6
REQ-005-US-004-001 yes As a system operator, I can monitor agent spawning metrics and performance to ensure system health 3
REQ-005-US-005-001 yes As a developer, I can define constitutional constraints that prevent agents from violating system invariants 3
REQ-005-US-006-001 yes As an agent, I can escalate to a higher-level agent when I encounter situations outside my constitutional bounds 4
REQ-005-FR1-001 yes Agent spawn time < 100ms (measured from request to first query execution) 3
REQ-005-FR2-001 yes Escalation path resolution < 10ms (measured from escalation trigger to parent agent identification) 3
REQ-005-FR3-001 yes Agent lifecycle management with automatic cleanup when task completes 22
REQ-005-FR4-001 yes Constitutional constraint validation at agent spawn and during execution 13
REQ-005-FR5-001 yes Hierarchical agent organization with parent-child relationships 18
REQ-005-FR6-001 yes Agent context isolation with controlled fact visibility 2
REQ-005-FR7-001 yes Escalation mechanism with automatic parent notification 6
REQ-005-FR8-001 yes Performance metrics collection for agent spawn, query, and escalation operations 4
REQ-005-NFR1-001 yes System maintains performance with 100+ concurrent lightweight agents 4
REQ-005-NFR2-001 yes Agent spawn overhead < 1MB memory per agent none
REQ-005-NFR3-001 yes Constitutional validation adds < 5ms to spawn time none
REQ-005-NFR4-001 yes Escalation paths are deterministic and reproducible 3
REQ-005-NFR5-001 yes System remains responsive during agent cleanup operations 9
REQ-005-AC1-001 yes Agent spawn time verified < 100ms in benchmark tests 1
REQ-005-AC2-001 yes Escalation path resolution verified < 10ms in benchmark tests 2
REQ-005-AC3-001 yes Constitutional constraints validated at spawn and runtime 9
REQ-005-AC4-001 yes Parent-child relationships maintained correctly during escalation 14
REQ-005-AC5-001 yes Automatic cleanup verified for completed agents 5
REQ-005-AC6-001 yes Performance metrics collected and accessible via monitoring interface 13
REQ-005-US-007-001 no As a senior volk, I can spawn junior volks with configurable ACP drivers so that I can delegate implementation tasks to specialized coding tools none
REQ-005-US-008-001 no As a senior volk, I can delegate tasks to junior volks via CXP packets and receive their output through the same protocol none
REQ-005-US-009-001 no As a senior volk, I can fan out the same task to multiple junior volks in parallel, evaluate all outputs, and synthesize the best elements into a final deliverable none
REQ-005-US-010-001 no As the system, I can drive browser-based free-tier LLM chat interfaces via automation so that junior volks can use Qwen Chat, DeepSeek, and Kimi at zero cost none
REQ-005-FR9-001 no Junior volk spawns with driver initialization — CLI driver <500ms, API driver <200ms, Browser driver <5s none
REQ-005-FR10-001 no Senior-to-junior delegation uses standard CXP packets routed through Postman, identical to senior-to-senior communication 2
REQ-005-FR11-001 no Parallel delegation sends same CXP task packet to N junior volks simultaneously (max 5 per senior volk) none
REQ-005-FR12-001 no Senior volk receives all junior outputs, compares quality, selects best elements, and produces synthesized final output none
REQ-005-FR13-001 no Browser driver manages Playwright sessions with login persistence, timeout handling, and session recovery none
REQ-005-FR14-001 no Free-tier quota tracking per ACP — system tracks remaining quota and falls back to alternative ACPs when exhausted none
REQ-005-FR15-001 no Driver interface is uniform — senior volk code is identical regardless of whether junior uses CLI, API, or browser backend none
REQ-005-FR16-001 no Junior volk output is always a CXP packet with work_status and payload — driver converts ACP-native output to CXP format none
REQ-005-NFR6-001 no CLI/API driver task kickoff response < 500ms (p95) none
REQ-005-NFR7-001 no Browser driver task kickoff response < 5s (p95) including page load none
REQ-005-NFR8-001 no Senior volk synthesis decision < 30s (p95) for comparing up to 5 junior outputs none
REQ-005-NFR9-001 no Browser sessions remain stable for up to 30 minutes of interaction none
REQ-005-NFR10-001 no System degrades gracefully when all free-tier quotas are exhausted — falls back to paid ACPs or alerts human none
REQ-005-AC7-001 no Junior volk spawned with CLI driver produces output within 60s for a simple coding task none
REQ-005-AC8-001 no Junior volk spawned with Browser driver produces output within 120s for a simple coding task none
REQ-005-AC9-001 no Comparison delegation with 3 junior volks produces 3 distinct outputs and senior selects/synthesizes none
REQ-005-AC10-001 no Quota exhaustion on one ACP triggers automatic fallback to alternative ACP none
REQ-005-AC11-001 no All junior volk communication uses CXP — no direct ACP-native protocol exposed to senior volk 2
REQ-005-AC12-001 no Browser driver handles session timeout and re-authenticates without data loss none

Code that traces this spec

Module Symbols Requirements
orchestrata_ultimate/agents/communication 6 4
orchestrata_ultimate/agents/constraints 11 4
orchestrata_ultimate/agents/escalation 9 9
orchestrata_ultimate/agents/exceptions 1 1
orchestrata_ultimate/agents/hierarchy 18 7
orchestrata_ultimate/agents/interfaces 3 3
orchestrata_ultimate/agents/lifecycle 14 13
orchestrata_ultimate/agents/pool 6 3
orchestrata_ultimate/agents/prolog_bridge 17 5
orchestrata_ultimate/agents/runtime 19 8
orchestrata_ultimate/agents/volks/base 1 2
orchestrata_ultimate/orchestrator/pipeline_escalation 1 2

Checklists

checklists/code_review.md

Code Review Checklist — Google Python Style Guide

Reference: https://google.github.io/styleguide/pyguide.html

1. Formatting
2. Imports
3. Naming Conventions
4. Type Hints (Required for Public APIs)
5. Docstrings (Google Style)
6. Code Quality
7. Whitespace
8. Strings
9. Testing Requirements
10. Project-Specific Rules

Quick Reference
# Format code
uv run black packages/ tests/
uv run isort packages/ tests/

# Lint
uv run flake8 packages/ tests/

# Type check
uv run mypy packages/

# Run tests (use local-ci, not raw pytest)
ci/local-ci.sh test

checklists/constitutional.md

Constitutional Constraints Checklist

Article I: Agent Identity and Scope
Article II: Fact Visibility and Isolation

Article III: Escalation Rights and Obligations

Article IV: Lifecycle Management
Article V: Performance Constraints
Article VI: Resource Limits
Article VII: Error Handling
Article VIII: Query Constraints
Article IX: Inter-Agent Communication
Article X: Monitoring and Observability
Article XI: Constitutional Amendment
Validation Requirements

Junior Volk Constitutional Amendments
Article IX Addendum: Senior-Junior Communication
Article XII: Junior Volk Constraints
Article XIII: ACP Driver Safety
Junior Volk Validation Requirements

checklists/requirements.md

The requirement list above comes from this file; 25 of 48 checkbox items are ticked.

checklists/testing.md

Testing Checklist

Performance Tests
Agent Spawn Performance
Escalation Performance
Query Performance
Functional Tests
Agent Lifecycle
Constitutional Constraints
Escalation Mechanism
Hierarchy Management
Integration Tests
System Integration
Error Handling
Concurrency
Regression Tests
Performance Regression
Functional Regression
Acceptance Tests
User Story Validation
End-to-End Scenarios
Test Data Requirements
Test Environment

Junior Volk Tests
Junior Volk Lifecycle
ACP Driver Tests
CLI Driver
API Driver
Browser Driver
Delegation Pattern Tests
Chat-to-Completion
Kick-Off
Comparison
Synthesis Tests
Browser Automation Tests
Junior Volk Integration Tests

Other tracked files

Full spec text

Verbatim from specs/005-multi-agent/spec.md; headings are pushed down two levels.

SPEC-005: Multi-Agent Coordination

Metadata


Overview

What

The Multi-Agent Coordination system manages the lifecycle, communication, and escalation of Volks (agents) in Orchestrata. It supports lightweight Prolog agents, hierarchical agent organization, constitutional constraints, and the Junior Volk delegation system for parallel task execution.

Why
How

User Scenarios & Stories

US-001: Lightweight Agent Spawning (Critical)

As a developer I want to spawn lightweight Prolog agents So that I can handle specialized tasks without process overhead

Acceptance Criteria:


US-002: Agent Escalation Paths (Critical)

As a system architect I want to define agent escalation paths So that issues requiring broader context are automatically promoted

Acceptance Criteria:


US-003: Agent Lifespan Management (High)

As a developer I want to configure agent lifespans So that agents automatically terminate when tasks complete

Acceptance Criteria:


US-004: Agent Monitoring (High)

As a system operator I want to monitor agent spawning metrics So that I can ensure system health

Acceptance Criteria:


US-005: Constitutional Constraints (Critical)

As a developer I want to define constitutional constraints So that agents cannot violate system invariants

Acceptance Criteria:


US-006: Agent Escalation (Critical)

As an agent I want to escalate to higher-level agents So that situations outside my bounds are handled

Acceptance Criteria:


US-007: Junior Volk Spawning (P1)

As a senior volk I want to spawn junior volks with configurable drivers So that I can delegate implementation tasks

Acceptance Criteria:


US-008: Senior-to-Junior Delegation (P1)

As a senior volk I want to delegate tasks to junior volks via CXP So that work is distributed

Acceptance Criteria:


US-009: Parallel Delegation and Synthesis (P1)

As a senior volk I want to fan out tasks to multiple junior volks So that I can select the best output

Acceptance Criteria:


US-010: Browser-Based Free-Tier LLM (P1)

As the system I want to drive browser-based LLM chat interfaces So that junior volks can use free tiers at zero cost

Acceptance Criteria:


US-011: Code Review Loop (Critical)

As a U:Vz (VizInt) agent I want to participate in an iterative review-fix cycle with U:Qa So that code quality is ensured before completion

Acceptance Criteria:


Functional Requirements

Agent Management
Requirement Target
Agent spawn time < 100ms
Escalation path resolution < 10ms
Concurrent lightweight agents 100+
Memory overhead per agent < 1MB
Junior Volk Requirements
Requirement Target
CLI driver initialization < 500ms
API driver initialization < 200ms
Browser driver initialization < 5s
Parallel delegation max 5 per senior
Senior synthesis decision < 30s (p95)
Browser session stability 30 minutes
Code Review Loop Requirements
Requirement Target
Review cycle time < 300s (5 minutes)
MAX_REVIEW_CYCLES 3 iterations
Review checklist items 8-item Google Python style
Auto-fix single issues Enabled by default
Escalation on max cycles Automatic to U:Ox
Issue categorization style, type, complexity, docstring, security, test
Constitutional Constraints

Technical Design

Architecture
┌─────────────────────────────────────────────────────────┐
│           Multi-Agent Coordination                       │
├─────────────────────────────────────────────────────────┤
│  ┌─────────────┐  ┌─────────────┐  ┌─────────────┐     │
│  │    Volk     │  │  Escalation │  │  Constitutional│    │
│  │   Registry  │  │   Manager   │  │   Validator   │     │
│  └──────┬──────┘  └──────┬──────┘  └──────┬──────┘     │
│         │                │                │             │
│  ┌──────┴──────┐  ┌──────┴──────┐  ┌──────┴──────┐     │
│  │   Agent     │  │   Junior    │  │     ACP     │     │
│  │   Runtime   │  │   Volk Mgr  │  │   Drivers   │     │
│  └─────────────┘  └─────────────┘  └─────────────┘     │
├─────────────────────────────────────────────────────────┤
│  CLI Driver │ API Driver │ Browser Driver (Playwright)  │
└─────────────────────────────────────────────────────────┘
Volk Hierarchy
U:Ox (Orchestrator)
├── U:PS (Postman)
├── U:Vz (VizInt)
│   └── Junior Volks (CLI/API/Browser)
├── U:Qa (QA)
├── U:Ar (Architect)
├── U:Ux (UX)
├── U:PM (PM)
└── U:Cx (Concierge)
ACP Driver Interface
class ACPDriver(Protocol):
    async def initialize(self) -> bool: ...
    async def send_task(self, task: CXPPacket) -> str: ...
    async def get_response(self, task_id: str) -> CXPPacket: ...
    async def cleanup(self) -> None: ...

class CLIDriver(ACPDriver): ...
class APIDriver(ACPDriver): ...
class BrowserDriver(ACPDriver): ...
Pipeline Sequence
U:Cx → [U:Ar] → U:Vz → U:Qa → HUMAN
Code Review Loop Architecture

The U:Qa (QA Volk) implements an iterative review-fix cycle to ensure code quality before completion. This section documents the complete flow including CXP subjects, routing, and escalation.

CXP Subjects for Review Flow
Subject From To Payload
review_code U:Cx, U:Ox, U:Vz U:Qa {file_path, review_type, standards}
fix_issues U:Qa U:Vz {review_id, issues[], summary}
review_complete U:Qa U:Ox {review_id, final_status, issues_remaining}
Complete Flow
1. Task Request → U:Cx receives user requirement
2. U:Cx → U:Vz: "build feature X"
3. U:Vz generates code → ready for review
4. U:Vz → U:Qa: "review_code" (subject: review_code)
5. U:Qa analyzes code against standards
   - Style (flake8, black)
   - Type hints (mypy)
   - Complexity
   - Documentation
6. IF issues found:
   - U:Qa → U:Vz: "fix_issues" with issue list
   - U:Vz applies fixes
   - Increment cycle count
   - IF cycle_count < MAX_REVIEW_CYCLES:
     - GOTO step 5 (re-review)
   - ELSE:
     - U:Qa → U:Ox: escalation (MAX_CYCLES_REACHED)
7. ELSE (no issues):
   - U:Qa → U:Ox: "review_complete" (approved: true)
8. U:Ox routes to next step in workflow
MAX_REVIEW_CYCLES Configuration
# In orchestrata-qa configuration
MAX_REVIEW_CYCLES: int = 3  # Maximum iterations
REVIEW_TIMEOUT_SECONDS: int = 300  # 5 minutes per cycle
ESCALATE_ON_MAX_CYCLES: bool = True
AUTO_FIX_ON_SINGLE_ISSUE: bool = True  # Auto-fix if only 1 issue
Review Checklist (Google Python Style)
Kernel Routing for Review Cycles

The Kernel must support recursive routing:

  1. Detect fix_issues subject
  2. Extract cycle count from packet metadata
  3. Route back to U:Qa for re-review
  4. Track cycle count - increment on each fix_issues round-trip
  5. Escalate to U:Ox when cycle_count >= MAX_REVIEW_CYCLES
# In orchestrata-kernel routing logic
def route_packet(packet: CXPacket) -> str:
    if packet.subject == "fix_issues":
        cycle_count = packet.metadata.get("review_cycle", 0) + 1
        packet.metadata["review_cycle"] = cycle_count
        if cycle_count >= MAX_REVIEW_CYCLES:
            return "U:Ox"  # Escalate
        return "U:Qa"  # Re-review
    # ... other routing
Issue Types
Type Source Example Severity
style flake8 E501 line too long warning
type mypy Missing return type error
complexity AST Function > 40 lines warning
docstring Google style Missing docstring info
security bandit Hardcoded password error
test Coverage < 90% coverage warning
Escalation to U:Ox

When MAX_REVIEW_CYCLES is reached with remaining issues:

# U:Qa sends escalation to U:Ox
escalation = CXPacket(
    subject="escalation",
    from_agent="U:Qa",
    to_agent="U:Ox",
    payload={
        "reason": "MAX_REVIEW_CYCLES_EXCEEDED",
        "review_id": "rev_123",
        "file_path": "packages/.../kernel.py",
        "issues_remaining": 3,
        "issue_summary": {
            "errors": 1,
            "warnings": 2,
            "infos": 0
        },
        "cycles_completed": 3
    }
)
U:Vz Fix Handler

U:Vz must handle fix_issues packets:

# In orchestrata-vizint volk handler
async def handle_fix_issues(packet: CXPacket) -> Dict[str, Any]:
    issues = packet.payload["issues"]
    file_path = packet.payload["file_path"]
    
    fixed = []
    failed = []
    for issue in issues:
        try:
            apply_fix(file_path, issue)
            fixed.append(issue)
        except Exception as e:
            failed.append({**issue, "error": str(e)})
    
    return {
        "fixed": len(fixed),
        "failed": len(failed),
        "issues": failed  # Send back for re-review
    }
Code Review Loop Architecture

The U:Qa (QA Volk) implements an iterative review-fix cycle to ensure code quality before completion. This section documents the complete flow including CXP subjects, routing, and escalation.

CXP Subjects for Review Flow
Subject From To Payload
review_code U:Cx, U:Ox, U:Vz U:Qa {file_path, review_type, standards}
fix_issues U:Qa U:Vz {review_id, issues[], summary}
review_complete U:Qa U:Ox {review_id, final_status, issues_remaining}
Complete Flow
1. Task Request → U:Cx receives user requirement
2. U:Cx → U:Vz: "build feature X"
3. U:Vz generates code → ready for review
4. U:Vz → U:Qa: "review_code" (subject: review_code)
5. U:Qa analyzes code against standards
   - Style (flake8, black)
   - Type hints (mypy)
   - Complexity
   - Documentation
6. IF issues found:
   - U:Qa → U:Vz: "fix_issues" with issue list
   - U:Vz applies fixes
   - Increment cycle count
   - IF cycle_count < MAX_REVIEW_CYCLES:
     - GOTO step 5 (re-review)
   - ELSE:
     - U:Qa → U:Ox: escalation (MAX_CYCLES_REACHED)
7. ELSE (no issues):
   - U:Qa → U:Ox: "review_complete" (approved: true)
8. U:Ox routes to next step in workflow
MAX_REVIEW_CYCLES Configuration
# In orchestrata-qa configuration
MAX_REVIEW_CYCLES: int = 3  # Maximum iterations
REVIEW_TIMEOUT_SECONDS: int = 300  # 5 minutes per cycle
ESCALATE_ON_MAX_CYCLES: bool = True
AUTO_FIX_ON_SINGLE_ISSUE: bool = True  # Auto-fix if only 1 issue
Review Checklist (Google Python Style)
Kernel Routing for Review Cycles

The Kernel must support recursive routing:

  1. Detect fix_issues subject
  2. Extract cycle count from packet metadata
  3. Route back to U:Qa for re-review
  4. Track cycle count - increment on each fix_issues round-trip
  5. Escalate to U:Ox when cycle_count >= MAX_REVIEW_CYCLES
# In orchestrata-kernel routing logic
def route_packet(packet: CXPacket) -> str:
    if packet.subject == "fix_issues":
        cycle_count = packet.metadata.get("review_cycle", 0) + 1
        packet.metadata["review_cycle"] = cycle_count
        if cycle_count >= MAX_REVIEW_CYCLES:
            return "U:Ox"  # Escalate
        return "U:Qa"  # Re-review
    # ... other routing
Issue Types
Type Source Example Severity
style flake8 E501 line too long warning
type mypy Missing return type error
complexity AST Function > 40 lines warning
docstring Google style Missing docstring info
security bandit Hardcoded password error
test Coverage < 90% coverage warning
Escalation to U:Ox

When MAX_REVIEW_CYCLES is reached with remaining issues:

# U:Qa sends escalation to U:Ox
escalation = CXPacket(
    subject="escalation",
    from_agent="U:Qa",
    to_agent="U:Ox",
    payload={
        "reason": "MAX_REVIEW_CYCLES_EXCEEDED",
        "review_id": "rev_123",
        "file_path": "packages/.../kernel.py",
        "issues_remaining": 3,
        "issue_summary": {
            "errors": 1,
            "warnings": 2,
            "infos": 0
        },
        "cycles_completed": 3
    }
)
U:Vz Fix Handler

U:Vz must handle fix_issues packets:

# In orchestrata-vizint volk handler
async def handle_fix_issues(packet: CXPacket) -> Dict[str, Any]:
    issues = packet.payload["issues"]
    file_path = packet.payload["file_path"]
    
    fixed = []
    failed = []
    for issue in issues:
        try:
            apply_fix(file_path, issue)
            fixed.append(issue)
        except Exception as e:
            failed.append({**issue, "error": str(e)})
    
    return {
        "fixed": len(fixed),
        "failed": len(failed),
        "issues": failed  # Send back for re-review
    }

Integration Points

Component Integration
orchestrata-kernel Volk registry and routing
orchestrata-postman CXP packet delivery
orchestrata-governance Constitutional validation
orchestrata-cxp Inter-agent communication

Revision History

Date Version Author Changes
2026-03-07 1.0 Mohamed Initial specification
2026-03-07 1.1 Mohamed Added U:Qa code review loop functionality: review-fix cycle flow, fix_issues CXP subject, MAX_REVIEW_CYCLES configuration, recursive routing
2026-03-07 1.1 Mohamed Added U:Qa code review loop functionality: review-fix cycle flow, fix_issues CXP subject, MAX_REVIEW_CYCLES configuration, recursive routing

Success Criteria

  1. Spawn: <100ms agent spawn time verified
  2. Escalation: <10ms path resolution verified
  3. Constraints: Constitutional validation at spawn and runtime
  4. Delegation: Junior volk produces output within 60s (CLI) / 120s (Browser)
  5. Parallel: Comparison delegation produces synthesized output
  6. Quota: Automatic fallback when free-tier quotas exhausted

Dependencies


Gap Findings

FR-MA-SPIKE-1: U:Qa in Pipeline
FR-MA-SPIKE-2: Deployment Context Awareness
FR-MA-SPIKE-3: Concierge Fast Path