Multi-Agent Executor Integration Architecture: A Practical Guide

    This article presents a practical, product-agnostic methodology for integrating AI agent executors into a coding assistance platform. It explains why onboarding an executor is more complex than expected, then walks through a four-layer decoupled design covering the backend core, transport, runtime, and frontend. Key engineering issues such as handshake and version compatibility, context growth, observability, security boundaries, and elasticity are addressed, followed by a phased rollout plan that turns integration work into predictable engineering tasks.

    1. Background: Why Integrating an Executor Is Harder Than It Looks

    When building an AI-assisted coding platform, teams usually face the same requirement: support single-machine usage for local developers while scaling smoothly to a multi-tenant cloud environment. This calls for an agent execution engine that can run in-process locally and also be hosted on the server side.

    Choosing the engine is not the hardest part. Many agent frameworks are available, but what really determines adoption cost is whether the framework provides a standardized access control protocol (ACP, a general concept for Agent Communication Protocol) and a pluggable tool system. The former determines whether the platform can handle initialization, authentication, session creation, and prompt delivery in a unified way. The latter determines whether the executor can be managed by the platform rather than remaining outside the system.

    The real difficulty is “fitting into a production system.” To be usable in production, an executor must at least answer these questions:

    • How are child processes safely launched, monitored, and reaped?
    • How is long-session context controlled to prevent unbounded growth?
    • How are sessions routed and recovered across distributed nodes?
    • How does the frontend correctly render the identity and message stream of different executors without being aware of underlying differences?
    • When adding a new executor, can the change surface be kept within an acceptable range?

    This article uses the practice of an AI-driven coding assistance platform (internal codename HagiCode) as a thread to abstract an integration methodology that is independent of any specific product. The platform backend is built on a distributed virtual Actor model (an Orleans-style framework), and the frontend uses React and TypeScript. The goal is to make a newly integrated agent executor a first-class citizen alongside existing coding executors, rather than a piece of bolt-on logic.

    2. Overall Design: Four-Layer Decoupling

    The core of the integration approach is layering, where each layer exposes only a narrow interface and upper layers remain unaware of lower-layer implementation details.

    2.1 Backend Core Layer

    This layer wraps a specific executor as the platform’s unified AI Provider.

    • Unified Provider entry point: Implement the platform-defined IAIProvider interface, exposing standard actions such as capability negotiation, session creation, prompt submission, and event subscription.
    • Configuration object: Describe the executable path, launch arguments, authentication information, timeout and retry policies, typically carried by a strongly typed Options class and injectable from environment variables or a configuration center.
    • Low-level CLI abstraction: The platform base library provides ICliProvider<TOptions>, handling child process launch, stdin/stdout pipes, exit codes, and zombie process cleanup in a unified way.

    Sample code:

    1. public interface IAIProvider
    2. {
    3. Task<ProviderCapabilities> NegotiateAsync(CancellationToken ct);
    4. Task<SessionHandle> CreateSessionAsync(SessionRequest req, CancellationToken ct);
    5. IAsyncEnumerable<AgentEvent> StreamAsync(SessionHandle h, Prompt p, CancellationToken ct);
    6. }
    7. public sealed class HermesCliProvider : IAIProvider
    8. {
    9. private readonly ICliProvider<ExecutorOptions> _cli;
    10. public async IAsyncEnumerable<AgentEvent> StreamAsync(
    11. SessionHandle h, Prompt p, [EnumeratorCancellation] CancellationToken ct)
    12. {
    13. await _cli.WriteAsync(h.Stdin, p.ToJson(), ct);
    14. await foreach (var line in _cli.ReadLinesAsync(h.Stdout, ct))
    15. yield return AgentEvent.Parse(line);
    16. }
    17. }

    2.2 Transport Layer

    The transport layer does one thing: reliably map structured protocol messages onto a byte stream. For local executors, standard input/output (stdio) is the simplest and most universal channel. For remote executors, it is replaced with WebSocket or a message queue, with no changes required in upper-layer code.

    Details that must be handled strictly include line-based framing with a maximum frame length limit, tolerance for non-UTF-8 output, side-channel collection of child process stderr (for diagnostics rather than business parsing), and heartbeats with idle timeouts.

    Protocol methods usually revolve around four actions: initialize (capability negotiation and version confirmation), authenticate (credential exchange), session/new (create a session and bind the working directory), and session/prompt (submit a round of prompts and receive incremental events).

    2.3 Runtime Layer

    The runtime layer solves “where to execute and how to reuse.”

    • Session Grain: Under the virtual Actor model, each session maps to a Grain with a stable identifier, naturally gaining single-threaded serial semantics and preventing protocol corruption from concurrent writes to the same session.
    • Session pool: Maintain a many-to-one mapping between executor child processes and platform sessions, keeping them when idle and reaping them only on timeout. The cost of frequently launching child processes (initialization handshake, dependency loading, index building) is far higher than reusing a process that has completed the handshake.
    • Sticky routing: The binding between sessions and processes must be persisted to external storage, so nodes can reattach by identifier after a restart instead of dropping sessions.

    2.4 Frontend Layer

    The frontend should contain no “if the executor is X then…” branches. The approach is to introduce an executor type adapter that maps the type identifier sent by the backend to icons, color schemes, display names, and capability toggles. The message stream stays ordered and identity-consistent through a real-time push channel (a bidirectional communication mechanism such as SignalR), ensuring that output from the same executor is always attributed correctly in the UI.

    3. Key Engineering Problems and Solutions

    Handshake and version compatibility. The capability set returned by initialize must be recorded and used for degradation: fall back to polling when streaming output is unsupported, and disable related UI when tool calling is unsupported. The version number is used only for compatibility checks, not for feature inference.

    Context growth. Long sessions must have window management at the runtime layer: truncate and summarize tool output, compress historical messages in segments, and set a token budget for each prompt round. These policies should be configurable and decoupled from the specific executor.

    Observability. Child process stderr, protocol round-trip latency, and per-round token consumption should all feed into a unified logging and monitoring/alerting system. Metrics are best reported with label dimensions (executor type, tenant, session state) to help locate long-tail latency.

    Security boundaries. Executors have file and command permissions and must run under a least-privilege account, with working directories constrained by a whitelist and credentials injected through a key management service rather than written into configuration files. Cloud scenarios also require restricting network egress at the container platform level.

    Elasticity and cost. Session pool capacity, idle reclamation time, and per-tenant concurrency limits together determine resource usage. It is advisable to combine these with an elastic scaling policy that reclaims container instances during business troughs while keeping the necessary hot instances to maintain first-token latency.

    Phase one focuses only on “getting it running”: connect the stdio transport and the four protocol actions, and verify message attribution with a minimal frontend page. Phase two adds the runtime: introduce the session pool and Grain persistence, and load-test the process count and memory curve under concurrent sessions. Phase three adds governance: integrate logging, monitoring and alerting, quotas, and auditing. Phase four converges the abstraction, compressing the change surface for a new executor to “one Provider implementation + one configuration + one frontend mapping.”

    Following this path, teams can turn integration work from unpredictable exploration into decomposable, verifiable engineering tasks.