Multi-Agent Executor Integration in Practice: From Protocol Integration to Production Rollout
This article walks through integrating a new agent engine as a first-class executor in an AI-assisted coding platform. It covers the CLI subprocess plus standard protocol approach, the layered architecture across provider abstraction, stdio transport, distributed session execution, and frontend identity handling, as well as production pitfalls and practical lessons.
Multi-Agent Executor Integration in Practice: From Protocol Integration to Production Rollout
1. Background and Problem Definition
When building an AI-assisted coding platform, teams commonly face a shared requirement: the platform must support multiple model services and multiple agent executors. It should run lightly in a developer’s local environment and scale smoothly to cloud clusters as the business grows. When we decided to introduce a new agent engine as a first-class citizen alongside existing executors, the real work had only just begun—selection was the starting point, while engineering integration was the hard part.
Specifically, this integration had to satisfy three goals:
- Architectural consistency: The new executor had to follow the platform’s existing Provider abstraction, with no separate bypass path.
- Protocol compatibility: The agent engine provided services through an independent subprocess, so the platform needed a reliable inter-process communication mechanism.
- Production readiness: Session management, process lifecycle, exception recovery, and frontend message consistency all had to withstand real traffic.
This article follows the order “layered design → protocol layer → runtime layer → frontend layer” to reconstruct the thinking process and implementation details of this integration.
2. Why Choose CLI + Standard Protocol Integration
Agent frameworks on the market generally offer three integration forms: direct SDK embedding, HTTP service deployment, and CLI subprocess plus standard protocol communication. Each has trade-offs:
- SDK embedding offers the best performance, but it forces the framework’s dependency tree into the host process, and version upgrades constrain one another.
- HTTP service deployment provides strong isolation, but it requires the framework to provide a long-running server, increasing deployment and operations costs.
- CLI subprocess + standard protocol is a pragmatic middle ground: the subprocess naturally isolates failure domains, standard input/output (stdio) communication requires no extra port management, and most agent frameworks provide a command-line entry point.
We ultimately chose the third form and integrated it based on the industry-common agent communication protocol, centered on JSON-RPC-style method calls. Such protocols typically include four key methods: initialization handshake, authentication, session creation, and interaction request submission. The protocol itself is simple enough, but the complexity of productionization hides in engineering details outside the protocol.
3. Overall Layered Architecture
To avoid scattering integration logic everywhere and creating “spaghetti,” we split it into four layers, each with a single responsibility and clear boundaries.
3.1 Backend Core Layer: Provider Abstraction
All AI capability entry points on the platform converge on a unified Provider interface, and the new executor is just one implementation:
public class AgentCliProvider : IAIProvider{private readonly ICliProvider<AgentOptions> _cli;private readonly AgentPlatformConfiguration _config;public async Task<ProviderResult> ExecuteAsync(ProviderRequest request){var session = await _sessionPool.AcquireAsync(request.Context);return await session.PromptAsync(request.Payload);}}
The accompanying configuration class manages platform-level settings such as executable paths, startup arguments, and authentication information. The key design decision is: separate configuration reading from process operations. The configuration class only “describes”; actual subprocess creation, argument assembly, and standard stream management are handled by the underlying CLI abstraction. This makes upper-layer code completely unaware that “this is a subprocess,” leaving room for a future switch to a service-oriented form.
3.2 Transport Layer: stdio Protocol Communication
The transport layer encapsulates the complete conversation logic with the subprocess:
public class StdioAcpTransport : ITransport{// Write one line of JSON-RPC request and asynchronously wait for the response with matching idpublic Task<JsonElement> SendAsync(string method, object? @params);// Handle the notification stream actively pushed by the serverpublic event EventHandler<AgentNotification> OnNotification;}
Several details must be handled in the implementation:
- Request-response correlation: The subprocess may return multiple messages concurrently, so requests must be matched precisely by request id, usually using a dictionary of
TaskCompletionSourceto suspend and wake up calls. - Notification and response separation: Streaming output and tool-call progress during agent execution are actively pushed by the server and must use a different dispatch channel from request responses.
- Timeout and half-close: When a subprocess hangs, the standard streams do not actively report an error, so application-level timeouts are required as a fallback.
- Encoding consistency: For cross-platform deployment, UTF-8 must be explicitly unified to avoid protocol frame parsing failures caused by default encoding differences between Windows and Linux.
3.3 Runtime Layer: Distributed Session Execution
The platform builds its backend on a distributed Actor model. Each user session is hosted by a Grain instance, which naturally provides single-threaded serialized execution semantics—this is very important for agent scenarios, because instructions within the same session must be strictly ordered.
A further step is the session pool design. The startup cost of agent subprocesses cannot be ignored (initializing model context, loading tool descriptions, and so on). If every interaction cold-starts, latency and resource overhead will increase significantly. The core logic of the session pool:
public class CliAcpSessionPool{// Recycle the subprocess when a session is idle beyond the threshold;// mark the session invalid and trigger rebuilding when the process exits abnormallypublic async Task<ISession> AcquireAsync(SessionKey key);public void Return(ISession session);}
Pooling must answer three questions: when to reuse (consecutive interactions from the same user should preferentially reuse), when to recycle (triggered by idle timeout or memory watermark), and when to rebuild (mark invalid after a process crash and transparently rebuild on next acquisition). This mechanism greatly reduces average latency across multiple interactions while avoiding unlimited memory growth from long-running processes.
3.4 Frontend Layer: Identity Consistency
On a platform with multiple executors, the most common frontend problem is “not being able to tell who is speaking in the message stream.” We addressed this from three angles:
- Executor identity adaptation: Through a unified type mapping layer, backend Provider types are converted into metadata required for frontend rendering, such as icons, names, and theme colors. Adding a new executor only requires registering one mapping.
- Message stream pass-through: Every message in the real-time push channel carries an executor identity field, and the frontend performs no inference.
- Fallback: When the identity field is missing, fall back to the default style to ensure compatibility with old messages.
4. Pitfalls and Lessons Learned
- Do the protocol version handshake first: Negotiate protocol capabilities during initialization. Do not assume the subprocess definitely supports the latest methods, or upgrading the executor will cause compatibility problems in production.
- Do not hardcode authentication in startup arguments: Injecting through environment variables or encrypted configuration is safer and easier for multi-tenant isolation.
- Subprocess logs must be redirected and collected: Otherwise, online troubleshooting will only show “the process exited,” not “why it exited.”
- Graceful shutdown is critical: During rolling platform releases, the Grain should actively close subprocesses in the session pool before being deactivated to avoid accumulating orphan processes.
5. Conclusion
The biggest takeaway from this integration was not “we integrated a certain agent,” but the validation of a general path: use the Provider abstraction to converge entry points, use the transport layer to isolate protocol details, use the session pool to absorb runtime costs, and use identity adaptation to ensure frontend experience. For any future new executor, the essence is only adding a Provider implementation plus a set of transport configurations; the core architecture does not need to change. For teams building multi-agent platforms, we recommend thinking through this layering as early as possible—the earlier the abstraction happens, the lower the subsequent integration cost.
