Multi-Agent Executor Integration Architecture: A Practical Guide
This article explains how to integrate multiple heterogeneous AI agent executors into an existing distributed system through a unified abstraction. It covers the core design principles, a layered architecture spanning the backend core, transport, runtime, and frontend, and practical details such as a versioned JSON message protocol over standard input/output, session pooling, concurrency control, session affinity in a distributed runtime, frontend identity consistency, and security baselines. A final checklist helps teams verify that adding a new executor requires only implementing one interface and extending one mapping table.
1. Background: Why Integrating an Agent Is More Complex Than It Looks
When building an AI-assisted coding platform, teams often face a typical requirement: they want developers to enjoy a low-latency, offline-capable coding agent experience on their local machines, while also allowing team collaboration and large-scale tasks to scale elastically in the cloud. This dual goal of “local and cloud” directly determines that the underlying execution engine cannot be a standalone script. It must be a runtime component that can be uniformly scheduled, observed, and metered.
There are many agent frameworks available on the market, and the evaluation criteria are highly similar: whether there is a standardized integration protocol, whether the tool-calling system is extensible, whether it can be hosted as a subprocess by a host system, whether it supports session-level state retention, and whether it is easy to deploy in containers. What really determines success is often not the feature list, but two points: the degree of protocol standardization and the extensibility of the tool system. These determine whether the host system can adapt to multiple executors with one codebase, rather than writing separate branching logic for each executor.
It is worth emphasizing that this article does not recommend or review any specific product. Instead, it abstracts this type of requirement into a general engineering problem: how to integrate multiple heterogeneous agent executors through a unified abstraction in an existing distributed architecture, and make them operable in production.
2. Overall Design Principles: Define the Contract First, Then the Implementation
The most common mistake in practice is to start writing adapter code first and then retrofit the abstraction. The correct order is to define the contract first and then implement the adapter.
Four principles are recommended:
- Unified entry principle: All executors expose the same interface to the upper layer, and upper-layer business code does not need to know whether the underlying layer is a local process, a cloud service, or a hybrid mode.
- Protocol-first principle: Use a standardized session protocol as the interaction baseline, abstracting “start, authenticate, create session, send prompt, receive increments” into a limited set of methods.
- Lifecycle hosting principle: Process creation, health checks, timeout recycling, and abnormal restarts of subprocesses are all managed uniformly by the host, and the business layer does not hold process handles.
- Identity consistency principle: The identity of an executor in the frontend message stream must be stable, avoiding the same executor appearing as different roles in different views.
3. Layered Architecture: Each Layer Solves One Type of Problem
A sustainable integration solution should divide responsibilities into clear layers. The following layers can be directly mapped to common backend distributed frameworks and frontend component systems:
- Backend core layer
- Unified executor interface (such as
IExecutorProvider): defines a minimal method set for capability queries, session creation, prompt submission, and result subscription. - Platform configuration object: carries configuration items such as executable path, startup arguments, authentication credential references, timeouts, and concurrency limits. Configuration must support injection via environment variables and secret management; hardcoding is prohibited.
- Low-level command-line hosting abstraction: encapsulates subprocess startup, standard stream reading and writing, exit codes, and signal forwarding.
- Unified executor interface (such as
- Transport layer
- Standard input/output transport implementation: exchanges versioned JSON messages with the executor subprocess through standard streams. Messages must contain the three-part structure of
id,method, andparamsto facilitate correlating requests and responses. - Protocol method set:
initialize(capability negotiation and version confirmation),authenticate(credential exchange),session/new(create a session and bind the working directory and tool whitelist),session/prompt(submit a prompt and receive incremental events).
- Standard input/output transport implementation: exchanges versioned JSON messages with the executor subprocess through standard streams. Messages must contain the three-part structure of
- Runtime layer
- Distributed execution unit (virtual actor form): uses the session ID as the sharding key to ensure that requests for the same session land on the same execution unit, naturally obtaining serialization and state affinity.
- Session pool: uses the triple of “executor type + working directory + tool set” as the reuse key to reuse established subprocesses and avoid the hundreds of milliseconds of cold-start overhead caused by frequent launches.
- Frontend layer
- Executor visual identity component: drives icons and color schemes with a type enum; adding a new executor only requires extending the mapping table.
- Type adapter: maps backend enums to frontend display models, isolating protocol fields from the UI model.
- Real-time push channel: stably pushes incremental events, tool-call status, and error codes to the session view through a long-lived connection.
Sample code (interface contract, language-agnostic):
interface IExecutorProvider {Capabilities GetCapabilities();Task<SessionHandle> CreateSession(SessionRequest request);IAsyncEnumerable<AgentEvent> Stream(SessionHandle handle, PromptRequest prompt);Task DisposeSession(SessionHandle handle);}
4. Transport Layer Details: Making “Process Communication” a Debuggable Protocol
The advantage of standard input/output transport is zero extra dependencies and natural adaptation to both container and local forms; the disadvantage is difficult troubleshooting. Three things must be completed in engineering:
- Unified message envelope: All messages carry a protocol version and message ID, and responses fill back the same ID; when versions do not match, return an explicit error code instead of failing silently.
- Graded incremental events: Distinguish “text increments,” “tool call start/end,” “state changes,” and “fatal errors,” and the frontend performs different rendering and retry strategies accordingly.
- Timeout and heartbeat: Set shorter timeouts (seconds) for initialization and session creation, use idle timeouts for the prompt stream (for example, no event for 60 seconds is considered abnormal), and periodically send heartbeat frames to detect subprocess fake death.
A common failure is a subprocess that is “alive but no longer outputs.” This kind of fake death can only be identified by heartbeats and idle timeouts, not by exit codes.
5. Session Reuse and Concurrency Control
Frequently creating subprocesses brings three types of cost: startup latency, memory usage, and repeated authentication handshakes. Key points of session pool design:
- Reuse key design: Include the context that affects execution results in the key, avoiding reuse across working directories that could cause file read/write confusion.
- Capacity and eviction: Set a global limit and a per-executor limit, adopt idle-first eviction, and prohibit recycling of sessions that are in use.
- Concurrency semantics: Strictly serialize the same session; different sessions can run in parallel; prompt submission must support cancellation tokens, and when canceling, send an interrupt to the subprocess rather than directly killing the process, to preserve the scene for diagnosis.
- Cold-start fallback: When the pool is full, queue instead of expanding infinitely; when the queue times out, return a retryable error and let the upper layer decide whether to degrade to another executor.
6. Distributed Runtime: Session Affinity and Fault Recovery
In a distributed framework, using the session ID as the sharding key yields three direct benefits: requests are naturally serialized, state does not need to be externalized, and migration costs during scaling are controllable. Note:
- State minimization: The execution unit only retains session metadata and a summary of the most recent tool call; long-text context is handed over to external object storage to avoid loss on node restart.
- Idempotent prompts: Assign a business-side unique key to each prompt so that it can be safely replayed after node failure recovery, avoiding repeated execution of tools with side effects.
- Observability: Link a unified trace identifier for each session, covering the four stages of subprocess startup, protocol round trips, tool calls, and frontend push. Metrics should include at least startup time, first-token latency, event interval, and error rate.
- Resource isolation: Set concurrency quotas by tenant or team to prevent a single large task from occupying all execution slots.
7. Frontend Consistency and Experience Details
What the frontend needs to solve is not “whether it can display” but “whether the identity is stable.” Recommendations:
- Use a centralized type mapping table to maintain the mapping from executor enums to icons, names, and capabilities; prohibit scattered conditional judgments within components.
- The executor identifier in the message stream is issued by the backend and persisted to the session record, so historical messages still belong to the correct executor after refreshing the page.
- Tool calls are presented as collapsible cards showing start and end states; on failure, display the error code and suggested action rather than the raw stack trace.
8. Security and Compliance Baseline
- Credentials enter the configuration only as references; actual values are injected by the secret management service and uniformly masked in logs.
- Tool whitelists are issued per session, and file system access is limited to the subtree of the working directory.
- All subprocesses run under a least-privilege account, with a read-only root file system in the container and only the necessary workspace mounted.
- Full-chain auditing: record who used which type of executor to perform what operation on which repository and when.
9. Implementation Checklist
- Is the contract unique, and does adding a new executor require only implementing the interface and extending the mapping table?
- Does the protocol carry a version and message ID, and can error codes distinguish retryable from non-retryable?
- Does the session pool have limits, eviction, and queuing strategies?
- Are heartbeats and idle timeouts in place to identify fake death?
- Are cancellation semantics and idempotent replay implemented?
- Is the frontend identity persisted and traceable?
- Are the three security baselines of credentials, permissions, and auditing complete?
By advancing according to the above layers, the workload of integrating a new executor can be reduced from “changing the full stack” to “implementing one interface plus one mapping table,” while maintaining consistency between local and cloud forms. This is the key to the sustainable evolution of a multi-executor platform.
