Designing and Building a Multi-Agent CLI Orchestration Tool: Unified Scheduling, Session Persistence, and Workspace Isolation
As LLM-powered coding assistants proliferate, developers often juggle multiple CLI agent tools that cannot share context, trace sessions, or run tasks in parallel without conflicts. This article explores, from an architectural perspective, how to build a CLI orchestration tool with unified multi-provider scheduling and multi-agent collaboration, breaking down its key design elements: a provider adaptation layer that normalizes heterogeneous outputs into event streams, a Supervisor pattern for spawning sub-agents, Git worktree-based workspace isolation, a skill system with MCP integration, and full observability through local persistence and monitoring panels.
Designing and Building a Multi-Agent CLI Orchestration Tool: Unified Scheduling, Session Persistence, and Workspace Isolation
As LLM-powered coding assistants become mainstream, developers routinely switch between multiple command-line agent tools: one excels at code completion, another at task planning, and yet another at web browsing and research. The fragmentation is obvious—context cannot be shared, sessions cannot be traced, and parallel tasks conflict over the same workspace. From an architectural standpoint, this article explores how to build a CLI orchestration tool featuring “unified multi-provider scheduling + multi-agent collaboration,” and breaks down its key technical designs layer by layer.
1. Why a Unified Scheduling Layer
Popular AI coding CLIs differ widely in interaction protocols, output formats, and session management. Developers working directly with these raw CLIs face three pain points:
- Fragmented context: Tasks cannot carry over between tools, forcing manual copy-paste;
- Lack of observability: Each tool produces output in a different format, making unified logging, auditing, and statistics difficult;
- No collaboration: A single CLI executes serially, with no ability for a primary agent to orchestrate sub-agents.
The core idea of a unified scheduling layer is to treat different CLIs and SDKs as “pluggable execution engines,” and to abstract a unified session model, event model, and task model on top of them.
2. The Provider Adaptation Layer: Normalizing Heterogeneous Outputs into Event Streams
The adaptation layer is the foundation of the tool. A centralized manager (call it the BridgeManager) governs all provider adapters, each of which handles three responsibilities:
- Process management: Launch the corresponding local CLI executable and manage its lifecycle and exit codes;
- Protocol conversion: Parse each CLI’s raw output—plain text, JSON lines, or streaming fragments—into structured events such as
message,tool_call,file_change, andthinking; - Capability mapping: Map provider-specific capability differences (e.g., image input support, structured output support) onto a unified capability description.
A typical event structure looks like this:
{"type": "tool_call","provider": "provider-a","session": "sess_8f2a","payload": {"tool": "file_edit","path": "src/main.ts","status": "running"},"ts": 1730000000}
Note that the adaptation layer is responsible only for “communication and parsing”—it does not ship with external CLI login states or executables. Users must ensure the commands are available on their machine or explicitly configure the executable path in settings. Provider configurations—commands, models, parameters, and environment variables—are best persisted in dedicated tables of a local database (such as SQLite), with support for enabling, disabling, and editing them in the UI.
3. Multi-Agent Collaboration: The Supervisor and Sub-Agent Spawning
A single agent is bounded by its context window and attention budget. With the Supervisor pattern, the primary agent can spawn multiple sub-agents to execute in parallel based on task complexity:
- Task decomposition: The Supervisor breaks a large task into subtasks, each bound to a provider and an independent session;
- Session relationship persistence: Parent-child sessions maintain reference relationships, so the entire session tree can be restored after a restart;
- Result aggregation: When a sub-agent finishes, its conclusions are returned to the Supervisor as a structured summary for final synthesis.
This pattern is especially suited for compound tasks that parallelize well, such as “refactor + add tests + update documentation.” In implementation, each sub-agent should maintain its own lifecycle state machine (pending → running → done/failed/cancelled), recorded locally for later tracing.
4. Git Worktree Isolation: An Engineering Safeguard for Parallel Tasks
Multiple agents modifying the same workspace simultaneously will inevitably conflict. Git’s native worktree mechanism provides an independent working directory for each task:
git worktree add ../proj-task-a task-agit worktree add ../proj-task-b task-b
Each sub-agent modifies code and runs tests in its own worktree, and the results are merged back into the main branch upon completion. This preserves the shared history of a single repository while achieving filesystem-level physical isolation, greatly reducing concurrency conflicts.
5. The Skill System and MCP Integration
The skill system aims to let teams accumulate reusable prompt engineering assets. A skill typically includes a prompt template, variable placeholders, the applicable provider scope, and invocation parameters. Projects can ship with a set of common skill templates (code review, test generation, documentation writing, etc.) while also supporting team-defined custom skills.
MCP (Model Context Protocol) integration addresses tool extensibility. Through built-in or external MCP servers, agents gain additional capabilities such as browser debugging, web search, and process control—all connected via a standard protocol and decoupled from any specific provider.
6. Observability and the Developer Toolchain
A mature orchestration tool should also provide a complete set of supporting panels:
- Built-in terminal and file browser: Execute commands and inspect code without leaving the tool;
- Editor integration: View and edit files using general-purpose editor components such as Monaco;
- Activity timeline: Display messages, tool calls, and file changes as a stream, with search and history replay;
- Usage statistics: Track token consumption and call counts per session and per provider to support cost accounting.
All state—provider configurations, sessions, tasks, workflows, skills, and MCP configurations—should be persisted locally, ensuring data sovereignty and offline availability.
7. Conclusion
At its core, this kind of multi-agent orchestration tool is an engineering infrastructure layer of “scheduling + parsing + persistence + isolation” built on top of heterogeneous AI coding CLIs. Its design principles can be summarized as follows: the adaptation layer normalizes event streams, Supervisor-based spawning enables parallel collaboration, worktrees provide workspace isolation, skills and MCP deliver capability extensibility, and local persistence plus monitoring panels deliver end-to-end observability. For teams looking to improve multi-tool collaboration efficiency, building or extending upon this architecture is a practical and viable path.
