A well-built agent orchestrator
A generalized specification for a local or self-hosted orchestrator that coordinates many AI agents on real work, with Octet as the worked example (Octet is coming soon). It states the principles, the architecture, the controls and a conformance checklist, and cites the standards and published practice each one rests on.
Purpose and scope
An orchestrator turns a request into delegated work, runs that work through agents safely, and returns results a human can trust. It does not itself do the work. It owns five things:
- Decomposition: splitting a goal into units an agent can finish.
- Dispatch: giving each unit to an agent with exactly the context and authority it needs.
- Isolation: keeping concurrent work from colliding.
- Control: deciding what each agent may do, and who must approve what.
- Record: a durable, inspectable account of what happened and why.
Out of scope: the model itself, the editor, and the tools agents call. The orchestrator connects to these through open protocols (see Observability and standards).
Exactly one role can write, exactly one can merge, exactly one can leave the machine. Everything else is read-only.The least-privilege principle expressed as an org chart. O
Design principles
Prefer code over model for control flow
Anthropic distinguishes workflows (LLMs and tools orchestrated through predefined code paths) from agents (LLMs dynamically directing their own process), and advises finding the simplest solution possible and adding complexity only when needed. S (Building effective agents) The 12-factor-agents methodology reaches the same place: most production agents are primarily deterministic software with LLM steps inserted at key decision points, not open-ended loops. P (12-Factor Agents)
Orchestrator-workers fits unpredictable decomposition
A central model breaks a task down at runtime and delegates to workers; the surrounding control flow is still developer-written code. S P It suits multi-file code changes where the sub-steps cannot be known in advance.
Give each agent its own small context
Subagents with separate context windows let work proceed in parallel without polluting one another, and the lead should persist its plan to memory because long runs can exceed the context window. S (How we built our multi-agent research system) 12-factor agents likewise names “own your context window” and “small, focused agents” as core factors. P
Delegation briefs must be explicit
The multi-agent post found that the lead must write detailed, unambiguous task descriptions covering objective, output format, tools and task boundaries, and that agents misjudge how much effort a task deserves. S
Be honest about cost and fit
The same post reports multi-agent runs using roughly fifteen times the tokens of a chat interaction and being less effective for tightly interdependent tasks such as much coding work. S
Enforce policy outside the model
Controls that live in code cannot be talked out of firing; controls that live in a prompt can. P (Arthur: human-in-the-loop governance)
Least privilege, per task
Both OWASP’s agentic risk list and NIST-linked guidance converge on task-bounded access, runtime policy checks and short-lived credentials over standing entitlements. P (OWASP Agentic Top 10 overview, CSA on NIST’s agent standards initiative)
Derive, don’t store, display state
Persist durable facts (what each agent last reported, what has merged) and compute labels like “needs input” at read time. O This prevents status from drifting out of sync with reality and makes recovery after a crash straightforward.
Reference architecture
┌─────────────── UI / CLI / chat (clients) ───────────────┐
│ live view, approvals, diffs, audit, controls │
└───────────────────────────┬─────────────────────────────┘
│ local API + event stream
┌───────────────────────────────────▼─────────────────────────────┐
│ DAEMON │
│ Planner/Scheduler ── Policy Engine (deterministic) ── Audit │
│ │ │ log │
│ Session Manager ── Workspace Manager ── Identity Resolver │
│ │ │ │
│ Agent Adapters Git / worktrees Store (SQLite) │
└───────┬──────────────────────┬──────────────────────────────────┘
│ stdio / JSON-RPC │ isolated checkouts
┌────▼─────┐ ┌─────▼────────┐
│ Agents │ │ Tools (MCP) │
└──────────┘ └──────────────┘
Components
| Component | Responsibility | In Octet (coming soon) |
|---|---|---|
| Planner / Scheduler | Turns goals into units, tracks dependencies, enforces concurrency caps | Manual bead creation, dependency check in runBead |
| Session manager | Launches, supervises, resumes and stops agent processes | ClaudeCodeRunner behind an AgentRunner interface |
| Workspace manager | One isolated checkout per unit, cleaned up on completion | git worktrees under .octet/ |
| Policy engine | Allow / deny / ask for every action, by role and context | warden.ts |
| Identity resolver | Maps each project to exactly one credential set; no default | identity.ts |
| Store | Durable facts plus an append-only event log | SQLite with an events table |
| Event stream | Pushes changes to clients | server-sent events |
| Adapters | One per agent type, behind a common interface | one (Claude Code) |
Roles
Separate roles by authority, not by prompt. A useful minimum set, and the one Octet, coming soon, uses:
| Role | Authority | Writes code | Model-driven |
|---|---|---|---|
| Intake (Chair) | Creates goals, talks to the human | No | Yes |
| Coordinator (Marshal) | Decomposes, dispatches, merges approved units | No | Yes |
| Planner (Architect) | Writes plans and specs only | No | Yes |
| Investigator (Scout) | Read-only exploration | No | Yes |
| Builder (Engineer) | Edits files inside one worktree | Yes | Yes |
| Reviewer | Approves or rejects units | No | Yes |
| Guard (Warden) | Decides allow / deny / ask | No | No, deterministic |
| Deliverer (Courier) | The only role that leaves the machine (push, PR) | No | Yes, gated |
The rule that makes this work: exactly one role can write, exactly one can merge, exactly one can leave the machine. Everything else is read-only. This is the least-privilege principle (P7) expressed as an org chart. O
Work model
- Goal: one deliverable on its own branch.
- Unit of work (bead): small enough for one builder and one reviewer to finish in a single pass.
- Dependencies: explicit edges; a unit cannot start until everything it depends on has merged.
- States:
todo → running → in_review → (changes_requested ↺ running) → merged, plusfailed. Transitions are enforced in code, and illegal ones (merging an unreviewed unit) are errors. - Branches: goal branch from the default branch; unit branch from the goal branch; units merge into the goal branch, and only the deliverer moves the goal branch off the machine.
Idempotency
Every state transition and every external side effect should be safe to repeat. Durable-execution systems record each step and skip completed ones on replay, but replay does not remove the need for application-level idempotency keys on external actions, and model calls made outside a step boundary are where re-spend happens. P (Durable execution for AI agents compared) A small event log plus a step wrapper on SQLite covers much of the need before adopting a workflow platform. P
Isolation
- Filesystem: one git worktree per unit. No two agents share a working directory.
- Credentials: the child process environment is rebuilt per task. Inherited tokens and author variables from other identities are stripped, and only the project’s identity is injected.
- Network and remote: builders cannot push or open PRs. A guard compares a remote’s owner to the project’s account before any outbound action.
- Host: the orchestrator’s own API listens on loopback only, requires a per-session token, and rejects unexpected
Hostheaders to defeat DNS rebinding. O - Stronger sandboxing (containers or OS sandboxes for the builder process) is the next tier and is recommended when agents run with broad permission modes.
Security and governance
Threat model
OWASP’s Top 10 for Agentic Applications (published December 2025 by the OWASP GenAI Security Project) is the current reference list. P It is described here via secondary write-ups; read the primary document. Two entries matter most to an orchestrator:
- Agent goal hijack: instructions injected into data an agent reads redirect its goal. NIST’s CAISI frames this as indirect prompt injection and recommends adaptive, repeated testing, with task-specific results examined alongside aggregates. P
- Tool misuse and exploitation (ASI02): an agent uses a legitimate tool unsafely, through over-privileged tools, poisoned tool descriptions, or chains of tools whose combined effect nobody authorized. Mitigations: least-privilege tool scoping, treating tool descriptions as untrusted input, allowed-combination policies, and logging every call. P
Controls
| Control | Requirement |
|---|---|
| Role-based policy | Deterministic allow / deny / ask per role and action kind; deny by default |
| Reversibility gating | Approval is required before irreversible or outward-facing actions, not before every step. Over-gating produces rubber-stamping P |
| Gate placement | Do the preparation first, then ask: agent gathers, validates permissions, proposes, human approves, then execute, verify, log P |
| Meaningful approvals | Show the exact action, target, account and diff, not just a yes/no. Rejections feed back to the agent as feedback P |
| Prompt-injection posture | Treat all repository content, tool output and web content as untrusted data, never as instructions P |
| Short-lived credentials | Prefer per-task, expiring credentials to standing tokens P |
Audit log
A governance reference lists what to record: model decisions, tool calls with arguments and responses, human approvals and overrides with reviewer identity, outputs, and system state such as agent and model versions; stored append-only with cryptographic integrity checks and restricted access. P (Governance best practices) Log before executing a risky action, since logging afterward documents an incident while logging before can stop it. P Hash-chain entries so tampering is detectable O, and where the stakes justify it keep a copy outside the agent’s host. Retention depends on your regulatory context; verify it against your own obligations.
Observability
Use OpenTelemetry’s GenAI semantic conventions so any backend can read your traces. S Status: Development. (GenAI agent spans)
invoke_agent {name}: one agent run, the root of a trace; a sub-agent’s run nests under its caller.execute_tool {name}: one tool call, a child of the agent span.- Agent attributes include
gen_ai.agent.name,gen_ai.agent.idandgen_ai.conversation.id; tool spans carrygen_ai.tool.nameand a call id; token usage sits on the model-call spans. - Content capture is opt-in. Prompts, completions and tool arguments often contain sensitive data and should not be recorded by default.
Interoperability standards
Build adapters to open protocols instead of proprietary hooks, so the orchestrator is not locked to one agent or editor.
| Concern | Standard | Notes |
|---|---|---|
| Agent ↔ tools and data | Model Context Protocol (MCP) | HTTP transports should follow the MCP authorization spec (OAuth 2.1 practices, RFC 8707 resource indicators, tokens only for their intended server); stdio transports take credentials from the environment instead. S (MCP authorization) Several spec revisions exist, so pin the one you target. |
| Client ↔ coding agent | Agent Client Protocol (ACP) | JSON-RPC 2.0 over stdio, version negotiation and capability handshake at start, streaming responses; the client launches and drives the agent, and file access goes through protocol methods. P (ACP overview) Not to be confused with the unrelated REST-based “Agent Communication Protocol”. |
| Agent ↔ agent (across systems) | Agent2Agent (A2A) | Agent Card for discovery; task lifecycle submitted → working → input-required → completed / failed / canceled / rejected; HTTP, JSON-RPC 2.0 and SSE; Linux Foundation governance. P (reference implementation) Sources disagree on the current spec version, so verify at a2a-protocol.org before implementing. |
| Project instructions | AGENTS.md | An open Markdown format giving coding agents project-specific build, test and style instructions; stewarded with MCP under the Linux Foundation’s Agentic AI Foundation. S P (announcement) Applied: inject the repo’s AGENTS.md into every builder’s assignment. |
| Telemetry | OpenTelemetry GenAI | See Observability above. |
A2A’s task lifecycle is a good model for your own unit states, since input-required is the “waiting on a human” state your UI needs. O
Identity and multi-account work
Real users work across several accounts. The orchestrator must make the wrong account impossible, not just unlikely. O
- No default identity. A project without an explicit identity cannot start work.
- Identity profile = author name and email, one SSH key, and one forge login. Applied through environment variables on every child process, never through the user’s global git config.
IdentitiesOnly. Force the SSH client to offer only the project’s key, otherwise an agent can silently present the wrong one.- Remote ownership guard. Before starting work and before any push, the remote’s owner must match the identity’s user or an explicitly listed organization.
- Credentials stay with the deliverer. Builders hold no forge credentials.
- Verify on demand. A
doctorcommand checks each key and token against the forge.
Failure handling
| Failure | Behavior |
|---|---|
| Agent exits non-zero or produces no change | Unit marked failed, output tail recorded, can be re-run |
| Daemon restarts mid-run | On start, reconcile: running units with no live process become failed or are resumed; never silently stay “running” |
| Reviewer rejects | Unit moves to changes_requested; feedback is attached to the next assignment |
| Dependency fails | Dependents stay blocked and the reason is visible |
| Merge conflict | Surface to the coordinator or human; never auto-resolve silently |
| Approval pending too long | Time out to a visible state; do not proceed |
| Policy denial | Deny with a reason shown to the human; log it |
Conformance checklist
An orchestrator meets this reference if all of the following hold. Tick items as you verify them; nothing is saved or sent anywhere.
Sources and caveats
Primary or near-primary: Anthropic’s Building effective agents and multi-agent research system posts; the MCP authorization spec; the OpenTelemetry GenAI agent spans spec.
Secondary (treat as guidance): the OWASP agentic list as summarized by Cycode; NIST’s CAISI and IR 8596 draft as summarized by the Cloud Security Alliance; the 12-factor agents repository (a mirror of the original by HumanLayer); ACP, A2A, durable-execution and human-in-the-loop write-ups linked inline.