Skip to content
←Back to Blog
How to Build a Multi-Agent Orchestrator from Scratch
Agent orchestrationMulti-Agent SystemsMCP

How to Build a Multi-Agent Orchestrator from Scratch

A first-principles teardown of T3 Code and Orca: MCP vs CLI+Skill injection, RPC trees vs persistent mailboxes, transactional outbox plus Dispatch fencing, and delta-synced context handoff.

Erwin (@ErwinWu000)November 30, 202611 min read20 views
ZH

I've been tearing apart the architectures of multi-agent orchestration tools like T3 Code and Orca lately.

Running models from different providers side by side feels great as a user. Once you put Claude Code and Codex at the same table, though, the hard parts have almost nothing to do with prompting. They are concrete systems engineering problems.

So I worked backward from a simple question:

If I were to build a multi-agent orchestration tool from scratch, what modules would I need from bottom to top, and what are the real engineering trade-offs in each layer?

Skip the boilerplate code. Here is the architecture from first principles, built around goals and trade-offs.

Orchestration Tools vs. Agent Harnesses

Before talking about architecture, we need to separate two concepts that get conflated constantly: Agent Harnesses & Orchestration Tools.

Official tools like Claude Code and Codex are native agent harnesses. They provide the execution environment (tool chains, prompt formatting, and agentic loops) around a model.

To get the most out of a model, its native harness is usually your best bet, because the model was post-trained specifically against that exact loop and tool format.

But wait, harnesses like OpenCode and DeepSeek Harness can also plug into multiple model providers to have different models share the same workspace. That still happens inside a single harness, where every model shares the same set of tools.

Tools like T3 Code and Orca sit a layer above. They are orchestration tools. They don't try to replace Claude Code or Codex underneath. They wrap those isolated, mutually unaware harnesses and turn them into a team. Running multiple models inside one harness is relatively straightforward. An orchestration tool exists to solve cross-harness collaboration.

Agent harness vs. orchestration tool: a single harness shares one toolset across models, while an orchestrator coordinates isolated harnesses
Left: multiple models inside one native harness share the same tools and loop. Right: an orchestration tool (T3 Code / Orca) sits above separate Claude Code and Codex harnesses, whose contexts are isolated and have no direct pipe.

The moment you put harnesses from different providers at the same table, four tightly linked engineering problems show up in order:

  1. Capability injection: How does an underlying model know it is running inside an orchestrator and can summon other agents?
  2. Inter-agent communication: Two agents have no direct pipe between them — how do messages and tasks move?
  3. State & fault tolerance: When unpredictable crashes happen, how do you keep global state intact?
  4. Context handoff: Each harness owns its own isolated session, how do you switch models without losing conversation history and prompt cache?

Step One: Letting the Model Know It Lives Inside an Orchestrator

The first job of an orchestrator is not scheduling. It is teaching the underlying model two things:

  • You are running inside my host environment,
  • You have the ability to summon other agents.

Today, there are two main ways to do this: MCP and CLI + Skill.

  • MCP (e.g., T3 Code): The orchestrator spins up an MCP server, registers actions like delegate_task as standard tools, and injects their JSON schemas directly into the model API's native tools parameter.
  • CLI + Skill (e.g., Orca): The system prompt points the model to a Skill manual. When collaboration is needed, the model reads the manual and runs the orchestrator's CLI commands in the terminal.
MCP vs. CLI + Skill: schema-driven tool calls with one round-trip each, versus an on-demand Skill manual and a single Bash pipeline
MCP loads tool schemas up front and pays one LLM round-trip per call; CLI + Skill reads a manual on demand and can fan out three tasks inside a single Bash pipeline.

Each approach comes with clear trade-offs:

  • Reliability & compliance: MCP wins. Parameter types and required fields ride on the model's native tool-calling protocol, backed by constrained decoding. Errors are rare. With CLI, the model hand-crafts shell strings. Misremembered flags, quoting bugs, and skipping the Skill manual to guess commands from memory all happen.
  • Complex workflow composition: CLI wins. In a single Bash call, the model can chain orchestration commands straight into a Unix pipeline. It can run git diff, parse it with jq, and loop over the output with for to fan out three sub-tasks at once. MCP can't do that. Every tool call is an isolated round-trip.
  • Integration cost: CLI is zero-friction. As long as an agent can run a terminal (a necessity for coding agents), it can join the orchestrator immediately. By contrast, MCP support in some agents still requires extra plugins or manual wiring.
  • Context overhead: CLI + Skill is much leaner. MCP loads the full JSON schema of every registered tool into context up front, paying the token tax even on turns where no orchestration happens. CLI + Skill loads on demand.
Dimension MCP (e.g., T3 Code) CLI + Skill (e.g., Orca)
Call Reliability High Medium
Workflow Composition Weak Strong
Integration Cost Medium Very low
Context Overhead Higher Low

The Core Problem: How Do Agents Talk to Each Other?

Once a model can invoke the orchestrator, the real architectural problem begins:

When Agent A wants Agent B to do a task or answer a question, how does that message actually deliver?

Agents never talk directly. The orchestrator is always the middleman. How you design that middle layer splits into two very different communication models: RPC Execution Trees (request/response delegation bound to a coordinator) and Persistent Mailbox Queues (an Actor model design with long-lived, addressable agents).

1. The T3 Code Style: RPC Execution Tree

The RPC model feels just like async function calling.

A coordinator agent calls a delegation tool, spawns a sub-worker, receives a thread handle, and moves on to other work while asynchronously waiting for the worker to finish and return its output.

The upside is simplicity. The orchestrator barely needs to manage intermediate runtime state.

The cracks show up as soon as collaboration gets non-trivial. Say a backend worker is halfway through writing code and doesn't know an API field in the spec. Because a pure RPC model is built around request/response return values, the sub-agent has to stop and surface the question back to the coordinator as a partial result. Even if the orchestrator supports resuming the same thread handle afterward, every back-and-forth still has to bounce through the coordinator as a fresh round-trip.

RPC execution tree: a blocked worker returns and dies, the coordinator relays the question and spawns a new worker instance
In the RPC model, a worker blocked on a question returns it as a partial result and exits; the coordinator spawns a new instance with the answer. Workers have no direct link, so every question bloats the main thread's context.

That creates two immediate bottlenecks:

  • The coordinator turns into a message relay, managing fragmented resume cycles or re-delegations that bloat the main thread's context.
  • Worker agents cannot talk to each other. If Worker A needs one field name from Worker B, the question has to be delivered through the coordinator. The whole team's ceiling is capped by a single bottleneck.

2. The Orca Style: Persistent Mailbox Queue

The Mailbox model borrows from the Actor Model that every active agent is a real, persistent entity with its own inbox address.

Take that same blocked worker as example. Instead of tearing down and starting over, it sends a message addressed to the right teammate and suspends in place. The orchestration tool intercepts the message and checks the recipient's state. If the recipient is busy running tools, the message waits in the queue until that turn wraps up. Once the reply arrives, the orchestration tool wakes the suspended worker right where it left off.

This breaks free from ephemeral, call-and-dispose execution. You get true bidirectional async messaging and direct peer-to-peer communication between workers without bothering the coordinator. The trade-off is engineering weight: the orchestration tool now owns routing, queuing, suspension, and wake-up lifecycle management.

Persistent mailbox queue: workers suspend in place while the orchestrator routes, queues and wakes them
In the Mailbox model, Worker A suspends in place after sending its question; the orchestrator queues the message, delivers it when Worker B is idle, and wakes A with the reply. The coordinator is not involved.

Interestingly, this convergence is not limited to third-party orchestrators: frontier native harnesses are also adopting the Mailbox pattern for multi-turn collaboration. The main difference is where the mailbox lives:

  • Local JSON files: Claude Code's Agent Teams gives each teammate a local JSON inbox file.
  • In-memory queues: Codex Multi-Agent V2 maintains queues in process memory.
  • External database: Orca persists mailboxes in SQLite to support durability and dependency triggers.

State Persistence & Fault Tolerance

Beneath interfaces and messaging sits state management and crash recovery.

Strip away the buzzwords and the baseline is simple: all of these tools persist runtime state in an external database or JSON files cooperating with locks. What differs is which stage of the failure lifecycle each pattern protects against. It's reliable dispatch before execution vs. stale-write isolation after execution.

Before dispatch, T3 Code focuses on reliable delivery. It is built as a multi-client synced control plane, so state consistency across clients comes first. The orchestrator has to both update database state and spawn local or remote agent processes. If the app crashes right after marking a task running in the DB before the process actually starts, you get a zombie task on restart.

T3 Code solves this with the Transactional Outbox pattern. State updates and pending dispatch commands are committed inside the same database transaction, and a background loop scans and executes them, keeping every connected client strictly in sync even after disconnects or crashes.

State fault tolerance: T3 Code's transactional outbox vs. Orca's Task/Dispatch separation
T3 Code commits the state update and the spawn command in one database transaction, then dispatches from a background loop. Orca tracks an active Dispatch ID per task, so a stale worker's report is dropped while the current worker's is accepted.

After dispatch, Orca focuses on parallel multi-terminal worktree scheduling to isolate stale workers. Suppose a task goes to Worker A, Worker A hangs, and the coordinator times it out and reassigns the task to Worker B. Minutes later, Worker A wakes up from the dead and overwrites Worker B's fresh output.

To close that hole, Orca splits the logical Task from each concrete Dispatch attempt. Every reassignment mints a new Dispatch ID. When a stale worker reports back with an expired ID, the orchestrator drops it on the floor.

These two patterns aren't competing alternatives, and a production orchestrator often needs both. Outbox retries can themselves produce duplicate dispatches, so fencing with a Dispatch ID is the natural second line of defense.

Context Handoff When Switching Models

One last design worth studying is T3 Code's Context Handoff.

If you use orchestration tools daily, you know this workflow:

In a single thread, you use Codex for turns 1–3 to build the implementation 👉 on turns 4–5 you switch to Claude Code to design a refactor 👉 on turn 6 you switch back to Codex to apply the changes.

The naive approach on turn 6 is to open a fresh Codex session and replay turns 1–5 from scratch. That hurts in two ways:

  1. Codex's prompt cache from turns 1–3 is completely invalidated, so you pay full token cost again.
  2. Worse, all the file contents Codex inspected via tool calls during turns 1–3 are gone. It has to re-read the codebase all over again.
Dual-layer context handoff: AppThread keeps the full ledger while ProviderThread syncs only the missing turns into each native session
AppThread records turns 1–6; ProviderThread knows Codex's native session is synced through turn 3, so switching back pastes only turns 4-5 as a delta. The turns 1–3 prompt cache and tool memory stay intact.

T3 Code solves this by splitting a conversation into two layers:

  • AppThread (the user-facing ledger) records the complete conversation from turn 1 through turn 6.
  • ProviderThread (the engine mapping table) tracks each underlying harness's native session ID (Codex, Claude Code, etc.) alongside a cursor marking the last turn synced into that session.

When you switch back to Codex on turn 6, the orchestration tool checks the table, sees Codex's native session is already synced through turn 3, and realizes it is only missing turns 4 and 5. So it reuses the original Codex native session and appends only the two missing turns as a delta. If you switch back to Claude Code on turn 7, the exact same thing happens.

Note: keep prompt cache TTL in mind (typically a few minutes to an hour depending on the provider).

Putting It All Together

Stack these four layers and you have the full skeleton of a multi-agent orchestration tool:

  • Capability injection: MCP for strict tool compliance vs. CLI + Skill for pipeline flexibility and low context overhead.
  • Communication: RPC execution trees for simplicity vs. persistent Mailbox queues for true async peer-to-peer collaboration.
  • State & fault tolerance: Transactional Outbox to survive crashes, and Task/Dispatch separation to fence out stale workers.
  • Context handoff: Dual-layer thread tracking with delta sync to preserve each harness's cache and tool memory.

In the next article, we will explore other aspects of orchestration tools:

  • How do you drive the harness at the lower level?
  • How do you avoid conflicts when multiple agents are working?
  • How do you manage the work permissions of different agents?

After the next article, you'll have everything you need to build a simple orchestrator from scratch.


Sources and attribution

Primary source: Erwin (@ErwinWu000), "How to Build a Multi-Agent Orchestrator from Scratch," X Article, November 30, 2026. The architecture analysis, diagrams and trade-off comparisons belong to the original author. This is a collected edition with light copyediting; the follow prompt for Part 2 was removed.

Related Articles

As an Amazon Associate, we earn from qualifying purchases.