Overview
TheAgentOrchestrator manages concurrent agents, multiplexes their event streams, and mediates permission relay flow between agents and consumers. Each agent runs independently with its own message history, but they share a common permission allowlist that grows as humans approve tools with “always”.
Quick Start
The Orchestrator API
Constructor
harness(optional): Custom agent harness. Defaults tocreateAgentHarness({ harness: createGeneratorHarness() }).
spawn(params)
Start a new agent and return its ID:events()
Async iterator yielding multiplexed events:agentId: Which agent produced this eventevent: The harness event (withrespondstripped from relay events)
resolveRelay(relayId, response)
Resolve a pending permission relay:approved: true: Execute the toolapproved: false: Reject with optional reasonalways: true: Add derived permission to shared allowlist
getPendingRelays()
Get all pending relays:cleanup()
Stop all agents and clean up resources:Event Multiplexing
The orchestrator usesAgentMultiplexer to race events from multiple agents:
- Events from all agents are interleaved in the order they occur
- Each event carries its
agentIdfor routing - Subagent events include
parentIdto preserve the call graph
Shared Permissions
The orchestrator maintains a shared allowlist that grows as users approve tools with “always”:always: true, the orchestrator:
- Calls the tool’s
derivePermission()to get a reusable pattern - Adds it to the shared allowlist
- All agents (current and future) auto-approve matching calls
Agent-Specific Permissions
Each agent can have its own permission overrides:- Agent-specific
deny→ immediate rejection - Shared allowlist (from “always” approvals) → auto-approve
- Agent-specific
allowlist→ auto-approve - Agent-specific
allowOnce→ approve once, consume - No match → relay event (pause for human)
Subagent Spawning
Agents can spawn child agents using theagent tool:
parentId in every event, forming a directed acyclic graph:
Example: Concurrent Task Execution
Example: Delegating to Specialists
File Timestamp Tracking
The orchestrator maintains a sharedFileTime tracker to prevent agents from editing stale files:
read and patch tools automatically coordinate through this shared tracker.
Lifecycle Management
Agents run until completion:cleanup() to forcibly stop all agents:
Debugging
Enable logging to trace orchestrator internals:Next Steps
Human-in-the-Loop
Build permission approval flows
Client Rendering
Render agent events in a UI
