Multi-Agent Collaboration: Speeding Up LLM Inference and Engineering Practices
This article explores a new paradigm for multi-agent collaboration, focusing on how to reduce LLM inference latency and control costs in production. It explains why the main agent's throughput is often limited by the slowest step, why long-input performance matters more than output speed, and how prefix caching, KV cache compression, and conditional memory change the cost curve. It also covers attention and single-pass architectures, task-based model routing for subagents, asynchronous orchestration, and context governance, with practical guidance for evaluating models using your own workload.
1. The Starting Point: The Underestimated Waiting Cost of the Main Agent
In a multi-agent architecture, the main agent handles planning, task decomposition, and result aggregation, while subagents handle concrete execution such as retrieval, coding, and verification. When choosing models, many teams focus only on “single-model intelligence” and overlook a structural fact: the effective throughput of the main agent is often determined by the slowest step in the chain.
If the main agent must wait for a tool call to return after every reasoning step, the end-to-end latency becomes a serial sum of “inference latency + tool latency + re-inference latency after feeding results back.” In this case, raising generation speed from tens of tokens per second to over a hundred tokens per second brings very limited improvement to total time, because the bottleneck is not in the decoding stage at all. This is a classic Amdahl’s law problem: the smaller the share of the part that can be accelerated, the closer the overall gain gets to zero.
What really determines the experience is a combination of three metrics:
- Time to first token (TTFT): determines how responsive the interaction feels, and is strongly related to prefill compute and cache hit rate;
- Decoding throughput (TPS): determines long-form output and streaming experience;
- Cost per token under long context: determines whether you can keep an entire code repository, full logs, or a complete manual resident in context.
2. Why “Fast on Long Inputs” Matters More Than “Fast on Output”
In real agent tasks, the input side is far larger than the output side. Putting a whole repository into context, analyzing full logs, or keeping a specification manual resident can mean hundreds of thousands of input tokens, while the output may be only a few thousand tokens. This means the optimization focus should be on prefill and cache reuse.
Common industry practices include prefix cache reuse, chunked prefill, and KV cache compression and quantization. KV cache occupancy is the main source of memory and bandwidth pressure under long context, and its size can be approximated as:
KV_bytes ≈ 2 × layers × kv_heads × head_dim × seq_len × bytes_per_elem
As shown, cache overhead grows linearly with sequence length. Compressing the “global cache footprint per token” to a fraction of its original size is equivalent to multiplying the context length that fits within the same memory budget, while also lowering the cost per request. Common engineering techniques include multi-query/grouped-query attention (MQA/GQA) to reduce the number of KV heads, cache quantization (such as INT8/FP8), prefix sharing across requests and sessions, and sliding-window or tiered cache eviction policies.
3. Conditional Memory: Making “Bigger” Not “More Expensive”
The current mainstream approach is dense parameter scaling combined with mixture-of-experts (MoE) sparse activation: total parameter growth brings capability growth, while activated parameters determine the compute per inference. The implicit cost of this curve is that “intelligence is tightly coupled with cost.”
Conditional memory offers an orthogonal idea: externalize part of the knowledge as retrievable key-value memory, and inject it by conditional lookup only when needed, instead of stuffing everything into the backbone parameters. The engineering implications are:
- The backbone keeps a controllable activation size, and compute per inference does not grow linearly with the total amount of knowledge;
- The memory module is hit on demand, and the miss path has almost zero overhead;
- Knowledge updates can be handled by maintaining the memory store, without retraining the backbone.
In system design, the memory layer can be understood as “versionable external state,” used together with vector retrieval, object storage, and cache clusters. A sketch of the call skeleton is as follows:
def agent_step(query, ctx):mem = memory.lookup(query, top_k=4) # Conditional memory / retrieval hitprompt = build_prompt(ctx, mem) # Keep the prefix stable for better cache reuseplan = planner.infer(prompt) # Main agent planningif plan.needs_tool:obs = tool.run(plan.tool, plan.args) # Tool execution, made asynchronousreturn agent_step(query, ctx.append(obs))return plan.answer
The key engineering constraint is: keep the prompt prefix stable and place volatile content at the end, so as to maximize the prefix cache hit rate.
4. Attention Mechanisms and Single-Pass Structures: Deterministic Engineering Gains
Iterations in attention mechanisms (such as the evolution from early sparse/compressed schemes to second-generation variants) and single-pass multi-hop structures share the common goal of reducing compute and memory-access overhead without sacrificing long-range dependency modeling. For users, the meaning is three observable gains: more stable latency under long context, more predictable memory usage, and higher concurrency density.
It is worth emphasizing that these are general technical directions, and specific implementations and effects vary by model. When making a selection, you should rely on stress-test results from your own business rather than marketing claims.
5. Division of Labor: Which Model Should Subagents Use
A counterintuitive but common conclusion is that subagents do not need to use the strongest model. There are three reasons:
- Subagent tasks have narrow boundaries and strong verifiability (compilation, unit tests, retrieval hits), and rely little on “top-level planning intelligence”;
- Faster subagents shorten the asynchronous waiting window and reduce context drift caused by repeatedly interrupting the main agent’s attention;
- Costs scale with the number of calls, and the unit price of subagents has the largest impact on the total bill.
Therefore, the combination of “strong planning model + fast execution model” is often better than “the same strong model throughout.” For implementation, it is recommended to route by task tier:
routing:planner: { tier: strong, max_ctx: 200k }coder: { tier: fast, max_ctx: 128k }reviewer: { tier: fast, max_ctx: 64k }summarizer:{ tier: cheap, max_ctx: 32k }
6. Asynchronous Scheduling and Context Governance
Most stability problems in multi-agent systems are not model problems but orchestration problems. Four practical recommendations:
- Make all tool calls asynchronous; let the main agent first do planning that does not depend on results, and merge after results are fed back;
- Have subagents return structured summaries rather than raw long text, to avoid polluting the main context;
- Layer the context: a resident layer (specs/architecture), a session layer (tasks and intermediate artifacts), and a temporary layer (logs/retrieval snippets), with eviction policies defined;
- Instrument the full pipeline, separately tracking TTFT, TPS, cache hit rate, tool time, and cost per task, and use data to locate bottlenecks.
7. Conclusion
The most valuable perspective for evaluating a new model version is not benchmark rankings, but whether it changes the cost curve and latency curve of your system. When long-context caching is cheap enough, conditional memory externalizes knowledge, and the execution side is fast enough, the multi-agent architecture truly moves from “can run” to “use freely.” In related practice at Baidu AI Cloud, it is recommended to run small-scale canary stress tests on your own scenarios and drive continuous tuning of model selection and routing strategies with observable metrics.
