Zhuohang Bian, Feiyang Wu, Chengrui Zhang, Hangcheng Dong, Yun Liang, Youwei Zhuo (Peking University, SJTU) | 2026-04 | arXiv:2604.03143 Category: framework | Tags: multi-agent-serving, kv-cache-sharing, position-independent-caching, llm-inference, agent-systems Read: 2026-04-18
把 multi-agent All-Gather round 当作 KV Cache 复用的第一类单位,将 N 个智能体在同一轮中的共享内容的 PIC 复用代价从 O(N) 摊销到 O(1),并用 Master-Mirror 块稀疏 diff 将 per-agent 存储压缩 11–17×,使同一张 A100 可支撑最多 2.7× 的并发智能体数。
Motivation:以 GenerativeAgents、AgentSociety 为代表的多智能体模拟系统按"同步轮"推进:中心调度器收集所有 agent 上一轮的输出 $\mathcal{O}^t = \{O_1^t, \ldots, O_N^t\}$,再把完整集合分发给每个 agent 作为新一轮输入。每个 agent 的提示形如 $P_i^{t+1} = H_i^t \,\|\, \Pi_i(\mathcal{O}^t)$:前缀是自己的私有历史 $H_i^t$,长度各异;后段是同一组共享输出块,但在不同 agent 里出现在不同的绝对位置。这种 All-Gather 通信结构导致:①prefix caching 一旦私有历史不同就彻底失效;②PIC(CacheBlend/EPIC 等)虽然能在任意 offset 复用,但必须对每个 agent 单独做一次 RoPE 旋转+重要位置选择,N 个 agent 就要跑 N 遍;③即便成功复用,最终 N 份 KV Cache 仍然是 91–97% 块级相同的密集副本,直接撑爆显存。
Method:TokenDance 把优化单位从"单请求"提升到"一整轮 All-Gather"。三大组件:(1) Round-Aware Prompt Interface 用保留分隔符 token 打标 logical block 边界,让运行时可以按 segment 做 content-based hashing,识别跨 agent 的共享块;(2) Collective KV Cache Reuse:KV Collector 把同一轮中 prompt 长度、cache span、slot mapping 兼容的请求组成一个 group,layer-wise 同步推进,在 check layer 上把 N 个请求的 Q/K 拼成一个大 batch 做一次 RoPE + 一次 key-difference 分析,选出的 important positions 集合直接复用到后面所有层;(3) Diff-Aware Storage + Fused Restore:一轮里挑出偏差最小的 Master 保留完整 cache,其余以 block-sparse K/V diff 表示,仅记录差异块索引和值;回读时用 ping-pong buffer 在 Master 传输路径中就近 merge diff 并做 RoPE recover,避免显式构造 dense Mirror。
Results:在 A100-80G 上用 Qwen2.5-7B/14B 评测 GenerativeAgents 与 AgentSociety:

What it shows:三个 agent 在同一轮中的 prompt 组成——各自的私有历史 $H$(长度不一)加上同一组共享输出块 $O_1, O_2, O_3$,但因为 $\Pi_i$ 给每个 agent 的块顺序不同,同样的 $O_1$ 在不同 prompt 中出现在不同的绝对 offset。
Why it matters:这张图直接解释了为什么 prefix caching 在 multi-agent 场景彻底失效——前缀 bit 对 bit 相同是 prefix caching 的先决条件,而 $H$ 长度不等就把对齐打破了。它也是 TokenDance "round-aware" 设计的出发点:内容相同但位置不同,就必须用 content-based segment hashing 而不是 position-based chunk hashing。
Detailed description:左侧列出 3 个 agent 的完整 prompt,每个 prompt 顶部是长度不一的 $H_i$ 块(浅色),底部是标注了 $O_1/O_2/O_3$ 的共享块(三种深色),图中用竖直虚线对齐同色块展示它们在 token 轴上的偏移差异。最右侧的标注强调"same content, different absolute positions"。


What it shows:同样 250 个子请求,multi-agent workload(10 sessions × 25 rounds)与 250 个独立 request 在 A100-80G + Qwen2.5-14B 上的对比。左:latency-vs-request-index 曲线,multi-agent 从头就顶着 136 s 的 P99,而独立请求从低位逐渐爬到 125 s;右:peak KV Cache footprint,multi-agent 占 41.5 GiB(99.3% pool),独立请求只占 24.8 GiB(59.2%)。
Why it matters:用实测说明"即便总 workload 一样,只要 cache 需要跨轮 coexist 就会把内存池撑爆并触发 preempt/swap"。这是 TokenDance 把 storage 列为一等公民的经验证据——就算 prefill 再快,不砍每 agent 存储都救不了 scaling。
Detailed description:(a) 横轴是 request index (0-250),纵轴是子请求 latency,两条曲线颜色区分 multi-agent vs independent;(b) 条形图展示两种 workload 的 peak KV Cache 占用,标注绝对值与百分比。

What it shows:TokenDance 的三块组件并列:①round-aware prompt interface 保留块结构;②collective KV Cache reuse 把 N 个请求组成 group 做一次 RoPE+diff;③diff-aware storage + fused restore 把 per-agent cache 压成 Master + sparse diffs。
Why it matters:一图说清论文的"先暴露结构 → 共享计算 → 共享存储"三段式设计原则。它也明示了本文的 design rule:"把 round structure 留给 runtime 看见"和"每个请求一份语义 cache,但共享所有真正公共的东西"。
Detailed description:顶部是 application 侧的多 agent prompts(带 separator token 标注分段),中部是 runtime 的 block-level scheduler 把 N 个兼容 request 汇入 KV Collector;底部是 storage 层,画出 Master 与 Mirror 的关系以及回读时的 fused restore 路径。各组件之间用带标注的箭头表示数据流(token → KV → diff)。

What it shows:三种路径对比。T1:vLLM 从零算所有层;T2:per-request PIC,N 个 agent 各自 RoPE + diff + selective recompute;T3:TokenDance 把 N 个请求的 Q/K 拼成一个 batch 做一次 RoPE,在 check layer 做一次 important-position 选择,后续层直接用这个集合刷新每个请求的 K/V。
Why it matters:这是 compute 侧的核心 diagram。它展示了"从每请求摊销 → 每轮摊销"的粒度跃迁,也呼应了本文的"amortize group-wide work once per round"原则。Section 6.3 的 2.57× speedup 就是这个 diagram 的量化结果。
Detailed description:左侧画出 3 个 agent 的 prompt(共享块颜色相同,排列顺序不同);右侧是三条 compute timeline:T1 横排 3 条独立 prefill;T2 横排 3 条 PIC reuse(RoPE + diff + recompute 被画成重复色块);T3 把 3 个 agent 的操作合并,RoPE 和 diff 只画一遍(大色块),重算部分保留每请求独立。

What it shows:左边 3 份近乎相同的 recovered KV Cache,仅在 10–20% 位置不同;右边是 TokenDance 的存储布局——Master 保留一份完整 cache,Diff 2 / Diff 3 只记录与 Master 不同的块的索引和 K/V correction。
Why it matters:这是 memory 侧的关键 figure。它直接对应 11–17× 的压缩比来源,也解释了为什么要和 collective reuse 共享同一个 reuse plan(reuse plan 里有 Master 选择和 important positions,直接被存储层消费)。
Detailed description:左侧 3 个 agent 的 cache 以同色/异色格子表示共享块/私有差异;右侧 Master 仍然是密集张量形状,Diff 2/3 缩成块稀疏结构(只有几个高亮块 + 索引列表)。箭头标注 "Diff = block-sparse (indices, values)"。

What it shows:2×2 布局(GenerativeAgents/AgentSociety × Qwen2.5-7B/14B)。每格左图是 round latency vs agent count(QPS=10,虚线 1500 ms SLO),右图是"最多能撑住 SLO 的 agent 数 vs QPS"。TokenDance(橙)在所有配置、QPS 全程都高于 vLLM、CacheBlend Ordinary Path、CacheBlend 三个 baseline。
Why it matters:论文最重要的一张图。它证明了本文的核心 claim:"在同样 SLO 下能跑的 agent 更多"。特别突出了两个规律:①agent 多了 TokenDance 的优势更大(因为复用和去重都是 per-round 摊销);②模型越大优势越明显(cache per agent 翻倍,去重绝对收益翻倍)。
Detailed description:4 个子图,每个含两条面板:左侧折线图(x=agent count 1–10, y=round latency, 4 条曲线),右侧折线图(x=QPS 1–16, y=max agents under SLO)。TokenDance 橙色曲线在所有子图都位于底部(latency)或顶部(capacity);SLO 虚线横跨左面板。
| Workload | Model | Metric | vLLM prefix | CacheBlend | TokenDance |
|---|---|---|---|---|---|
| GenerativeAgents | Qwen2.5-7B | Max agents @ QPS=16 | 2 | 4 | 8 |
| GenerativeAgents | Qwen2.5-14B | Max agents @ QPS>8 | 1 | ≤2 | 4 |
| AgentSociety | Qwen2.5-7B | Max agents @ QPS=4 | 3 | 3 | 4 |
| AgentSociety | Qwen2.5-14B | Max agents @ QPS=16 | <1 | <1 | 2 |
Takeaway:2.7× 并发 agent 数的提升来自 compute 摊销 × 存储压缩 两侧收益的乘积;14B 上优势更大,因为 per-agent KV footprint 翻倍。
| Model | Compression ratio | Avg changed blocks per Mirror | Implied capacity for N=10 |
|---|---|---|---|
| Qwen2.5-7B | 11.2× | 53.2 / (500–700) | 1.8 caches (vs 10) — 5.6× ↓ |
| Qwen2.5-14B | 17.5× | 59.6 / (500–700) | 1.5 caches (vs 10) — 6.7× ↓ |
Takeaway:Mirror 只需 Master 的 5.7–8.9%,模型越大压缩越狠(因为差异块数目近似不变,但 per-token cache 变大)。
| Workload | Scenarios (ID) | Δ rounds-to-first-divergence |
|---|---|---|
| GenerativeAgents | Meet and Greet (1), Valentine's Day (2) | 0.0% |
| GenerativeAgents | Election Discussions (3), Winning the Election (4) | 3.3–11.9% |
| AgentSociety | Information Outbreak (5) | 0.0% |
| AgentSociety | Pre-Landfall (6), Hurricane (7), Economic Stabilization (8) | 3.3–11.9% |
Takeaway:所有偏离都是底层 CacheBlend PIC 选择性重算的数值扰动放大,TokenDance 的 collective grouping 只变执行顺序不变数值结果。
时代定位:2023–2025 年 LLM serving 的三波浪潮——PagedAttention(空间)、Continuous Batching(时间)、Chunked Prefill(P-D 交织)——已经把"单请求串行模型"里能砍的 overhead 几乎砍完。紧接着的是 disaggregated serving(Mooncake、Splitwise)和 PIC(CacheBlend、EPIC、KVLink、KVComm)这两个 2024–2025 的方向,但它们都停留在"单请求"视角。TokenDance 站在 2026 年回望这条时间线,指出下一个系统性红利来自"请求间结构"而不是"请求内结构"——把 All-Gather 作为第一类 schedule 单位。
为何不可 X(约束推导):
| 替代方案 | 在多 agent All-Gather 里是否可行? | 不可的根本原因 |
|---|---|---|
| Prefix caching(vLLM/SGLang 默认) | ❌ | 需要 prefix byte-aligned 相同;$H_i$ 长度各异后,$O_1$ 的绝对 offset 在不同 agent 里不同,token-0 对齐的 trie 直接 miss。 |
| Per-request PIC(CacheBlend) | ⚠ 部分可行 | 能匹配任意位置,但 RoPE 旋转 + diff 分析的复杂度与请求数成线性关系,N 个 agent 就是 N 次重复。 |
| 完全共享单份 KV | ❌ | $H_i$ 产生的 context 会污染后续 attention(跨 agent 信息泄漏);而且 RoPE 作用后 K 的位置依赖不同,语义上就是不同的张量。 |
| KV 去重 = CDN 式的内容寻址存储 | ⚠ 粒度不对 | 若按 token 级 content-hash 去重,metadata 爆炸且每 hit 需要跨表查询;按 block 级又不能直接发 attention(RoPE 位置不同)。 |
| offload 到 CPU/SSD + prefetch(Mooncake/CacheGen) | ⚠ 单向优化 | 对 idle cache 有效,但对"必须在线的 N 份 cache 同时进 attention"无帮助;且 round-to-round 的高重用率意味着 prefetch 也只是把重复数据搬来搬去。 |
| 更高级的 eviction/quant(H2O/KIVI) | ✅ 正交 | 可与本文正交叠加,但不解决"N 份近乎相同的 cache 同时 alive"这个 root cause。 |
破局:一句话的"aha"——"N 个 agent 的 prompt 里,$O$ 块 bit-level 相同但 position 不同;位置差异可以通过一次 group-wide RoPE 校正,内容冗余可以用 block-sparse diff 压缩;所以 compute 和 storage 两侧都可以从 per-request 升级到 per-round"。
核心技术壁垒:Reuse plan 的跨组件流转。看似简单的"挑一个 Master + 其他人存 diff",实际上要求:①collective reuse 在 check layer 的 important-position 集合必须精确反映每个 Mirror 相对 Master 的差异分布(否则 diff 里要么遗漏要么冗余);②Diff backend 要在 write 时消费 plan、在 read 时按 block 产出 indices+values;③fused restore 的 ping-pong buffer 与 diff 元数据的对齐、与 attention tile 对齐、与 paged memory 的 slot 对齐——三个对齐同时满足。这套"plan → store → restore"的端到端一致性,比单独实现任一组件都要难,作者用 3K 行 Python + 500 行 CUDA 才把四个子系统粘起来。
设计绑定批判:本文 implicitly 绑定了 (i) All-Gather 通信模式(若实际是 DAG/chain-of-thought 会失效),(ii) RoPE 位置编码(方法强依赖 RoPE 的数学可逆性),(iii) CacheBlend 风格的 selective recompute(提供"位置集合→修正 K/V"的语义),(iv) LMCache + vLLM V1 的 paged KV 数据模型(block 对齐、slot mapping 可见)。任何一条松动都要重写一大块。
[Agent t outputs {O_1..O_N}] → [Scheduler: assemble prompts with separators]
→ [Round-Aware Interface: segment tokenization]
→ [KV Collector: group compatible requests]
→ [Layerwise collective prefill: shared RoPE + batched diff @ check layer]
→ [Per-request selective recompute at important positions]
→ [Reuse plan: Master + per-request diff metadata]
→ [Diff-Aware Storage: write Master dense + Mirrors as block-sparse]
→ [Decode phase: standard per-request autoregressive]
→ [Next round: fused restore (ping-pong buf) → attention → agent t+1 outputs]
| Stage | Input → Output | Location | Latency scale | Data format & size |
|---|---|---|---|---|
| Application | Agent outputs $\mathcal{O}^t$ | CPU | < 1 ms | string blocks |
| Prompt assembly | $\mathcal{O}^t + H_i^t$ + separators | CPU | < 1 ms | token IDs, len $L_i$ |
| Segment hashing | tokens → segment IDs | CPU | <1 ms | hash table per segment |
| Grouping | N requests → K compatible groups | CPU | ~ ms | group metadata |
| Collective prefill | Q/K per layer → corrected K/V | GPU HBM | ~100s ms | $[N, L, H, D]$ batched |
| Reuse plan | per-request deviation scores | GPU→CPU | < 1 ms | index lists |
| Diff serialize | Mirror dense → (indices, K/V) | GPU→CPU/Storage | ~ms | sparse blocks |
| Fused restore | Master chunk + diff → paged KV | GPU HBM | 0.1–0.6 ms/mirror/layer | ping-pong buffers |
| Attention + decode | KV → next token | GPU HBM | TPOT scale | standard |
| Alternative | 减少 compute? | 减少 storage? | 与 paged KV 兼容? | 精度损失? |
|---|---|---|---|---|
| Per-request PIC | ❌ N 次重复 | ❌ | ✅ | 轻微(本文承继) |
| Token-level content hashing | ⚠ 有收益但 metadata 爆炸 | ⚠ 随机访问代价大 | ❌ | ❌ |
| Agent-aware scheduler only | ❌ | ❌ | ✅ | ❌ |
| KV quant/evict | ❌ | ✅ 1.5–4× | ✅ | 视方法而定 |
| Disaggregated pool | ❌ | ⚠ pool 够大但 HBM peak 不变 | ✅ | ❌ |
| TokenDance (collective + Master-Mirror) | ✅ 1.2–2.57× | ✅ 11–17× | ✅ | 同底层 PIC |
真正难复刻的是 Algorithm 1(Fused Diff Restore) 的在线链路:ping-pong buffer 切换 + 每层按 paged KV slot map 写回 + block 稀疏 merge + RoPE recover,同一条 transfer 里完成。如果任何一个 phase 错位(比如在 swap 前写回、diff indices 与 page boundary 未对齐、RoPE recover 被放在 attention 里而非 transfer 里),就会失去论文观察到的"dense materialization 零次"的关键 invariant,从而 restore latency 回到 dense 的 1.8–2×。这段逻辑藏在 500 行 CUDA/C++ 里,是 TokenDance 的核心壁垒。
| Innovation | Mechanism | Benefit | Cost/Tradeoff |
|---|---|---|---|
| Round-Aware Prompt Interface | Application 插入 reserved separator token;runtime 用 segment hash 取代 chunk hash | 让 runtime 识别共享 block | 需要 application 改 prompt 拼装(一行改动);非 All-Gather workload 回退 |
| Collective KV Cache Reuse | group N requests → batched RoPE + batched important-position check → per-request refresh | RoPE+diff cost 从 O(N) 摊销到 O(1) | 对 group 兼容性有约束;fallback path 必不可少 |
| Diff-Aware Storage (Master-Mirror) | 1 dense Master + block-sparse diff per Mirror;共享 reuse plan | per-agent storage −94%, compression 11–17× | 选 Master 的 heuristic;diff metadata 额外开销 |
| Fused Diff Restore | ping-pong buffer + layerwise transfer + in-place sparse merge + RoPE recover | restore latency 1.3–2.6× 优于 dense | CUDA kernel 实现;对 paged-KV slot map 依赖 |
| Scenario | Workload pattern | SLO/Goal | Why baseline fails |
|---|---|---|---|
| Social simulation (GenerativeAgents) | 10s agents × 10s rounds, 短私有历史 | 1500ms round latency | 跨轮 cache 共存 + prefix 失效 |
| Agent society simulation | 100s agents × long history | 同上 | 14B 模型里单 cache 就 ~50 MB,10 agents 直接撑爆 |
| Multi-agent coding (ChatDev/MetaGPT) | 少量 agent + 长共享代码库 | 交互延迟 | 本文未直接测,但模式符合 All-Gather(代码被 redistribute) |
| RAG + multi-agent tool use | 外部知识 blocks 在 agents 间共享 | 端到端 latency | 类似问题,但 retrieval context 可能更异构 |
Primary bottleneck:memory-capacity-bound(N 份 cache 撑爆 HBM),次要 compute-bound(PIC 反复劳动)。TokenDance 同时攻两边。
| Metric | Definition | Unit | Direction |
|---|---|---|---|
| Round latency | 完成一轮所有 agent 的端到端时间 | ms | ↓ |
| Max agents @ SLO | 在 1500ms round SLO 下最多支撑多少 agent | — | ↑ |
| Compression ratio | dense KV size / (Master + diffs) size | × | ↑ |
| Restore latency / mirror / layer | 一个 Mirror 在一层上的回读时间 | ms | ↓ |
| Rounds-to-first-divergence | 与 vLLM 基线相比第几轮首次输出不同 | rounds | ↑ (closer to full trace = better) |
| Optimization | Metric | Baseline | After | Gain | Conditions |
|---|---|---|---|---|---|
| Collective reuse | Prefill speedup vs serial PIC | 1× | 2.57× | 2.57× | 10 agents, QPS=1, GenerativeAgents/Qwen2.5-7B |
| Collective reuse | Prefill speedup @ high QPS | 1× | 1.3–1.5× | — | QPS=16 |
| Master-Mirror | KV footprint compression | 1× | 11.2× | 11.2× | Qwen2.5-7B |
| Master-Mirror | KV footprint compression | 1× | 17.5× | 17.5× | Qwen2.5-14B |
| Fused restore | Per-mirror restore latency | 0.59 ms | 0.43 ms | 1.37× | 10 agents, QPS=1, 7B |
| Fused restore | Peak speedup vs dense | 1× | 2.6× | 2.6× | 3 agents, QPS=4, 7B |
| End-to-end | Max agents under SLO (14B) | 1 | 4 | 4× | GenerativeAgents, QPS>8 |
| End-to-end | Latency reduction vs vLLM | 1× | up to 2.3× | — | 跨 workload |
| End-to-end | KV storage reduction vs vLLM | 1× | −94% | ~17× | 累积 |
baseline vLLM: memory-bound (KV pool saturation → preempt/swap)
→ after CacheBlend PIC: compute-bound (N 次 RoPE+diff)
→ after collective reuse: memory-bound again (N 份 dense cache)
→ after Master-Mirror: moderate both compute & memory
→ after fused restore: residual bottleneck = attention itself + scheduling overhead >10 agents
作者在 Q2 末段明确指出"beyond 10 agents, scheduling overhead grows and partially offsets"——下一阶段瓶颈会回到调度层。
,一次性改动;非 All-Gather workload 自动走 fallback。| Layer | Impact |
|---|---|
| Algorithm | 间接利好 multi-agent RL rollout 的 inference 阶段 |
| Kernel | 新增 paired block-sparse KV diff kernel;与 FlashAttention/FlashInfer 有对齐机会 |
| LLM | 对模型架构无要求,但当前绑 RoPE + 一阶 KV(未讨论 MLA) |
| Agent | 给 multi-agent runtime 提供 round-aware 的一级接口,是本文最大的受益面 |
| Ops | 需要观察 group 形成率、fallback 率、diff 大小分布等新指标 |
| Feature | TokenDance | vLLM prefix | CacheBlend | EPIC/KVLink | Tokencake |
|---|---|---|---|---|---|
| Continuous batching | ✅ (承继 vLLM) | ✅ | ✅ | ✅ | ✅ |
| Paged attention | ✅ | ✅ | ✅ | ✅ | ✅ |
| Position-independent reuse | ✅ (via backend) | ❌ | ✅ | ✅ | part |
| Collective (round-level) reuse | ✅ unique | ❌ | ❌ | ❌ | ❌ |
| Cross-agent KV dedup | ✅ unique | ❌ | ❌ | ❌ | ❌ |
| Agent-aware scheduling | partial | ❌ | ❌ | ❌ | ✅ |
| Multi-node | unknown | ✅ | unknown | unknown | ✅ |
| Quantization | orthogonal | ✅ | orthogonal | orthogonal | orthogonal |