CPU Orchestration • GPU Inference • Tool Execution — Multi-Turn Agent Loop
一个完整 Agent Task 的执行过程(Client-Heavy 模式,如 Cursor)。展示每个组件何时参与、数据如何流转。
从用户请求到 GPU kernel / 具体工具的完整分层展开。左侧: LLM 推理栈(Router → PD 分离 → GPU)。右侧: Tool 执行栈(Dispatch → 路径 → 具体工具)。
ReAct loop, planning, decision routing, multi-agent coordination, state machine
System prompt (16K+), history assembly, tool result injection, context window management
BPE/SentencePiece encode → token IDs; decode output IDs → text. Pure CPU.
Top-p/top-k/temperature sampling on logits; structured output parsing (JSON tool_call, code blocks)
Conversation state, KV cache metadata & eviction policy, prefix cache index, session lifecycle
Batch formation, priority queuing, preemption, continuous batching, KV budget allocation
Process all input tokens in parallel. Self-attention O(L²) + MLP. Determines TTFT.
Auto-regressive generation, 1 token/step. Weight + KV-cache loading from HBM dominates.
Per-session KV tensors. Grows with L(j) × C. Eviction needed when memory full.
Reuse KV from prior turns. Reduces prefill to incremental ΔL only. Hit rate h(Z).
FlashAttention / PagedAttention. GQA or MLA. TP all-reduce per layer.
Dense FFN or routed MoE. EP across GPUs. Small batch = few active experts.
Python/shell in isolated container. Process spawn + execution. CPU-bound compute.
Read/write/search files. Grep, glob, AST parsing. Disk I/O + CPU string ops.
HTTP requests, page rendering, content extraction. Network latency dominant.
Database queries, REST/gRPC, external service invocations. Network I/O bound.
Vector DB search, embedding, document chunking, re-ranking. CPU + optional GPU.
Truncation, summarization, structured output. Prepare ΔL tokens for next prompt.
Orchestrator 是 Agent 系统的控制中枢,向上对接用户请求,向下驱动 LLM 推理和工具执行。
它可以部署在 Client、Server、或两者之间,产生截然不同的系统特性。
| Dimension | A: Client-Heavy | B: Split | C: Server-Heavy |
|---|---|---|---|
| 代表产品 | Cursor, Claude Code | Manus, Devin | ChatGPT, Gemini |
| CPU 开销位置 | 用户设备 | 服务端 | 服务端 |
| 网络调用/轮 | 1 RTT (LLM API) | 0 (内部闭环) | 0 (内部闭环) |
| 8轮 task 额外延迟 | 0.8-3.2s (RTT×N) | ~0 | ~0 |
| 工具执行环境 | 本地真实环境 | 云端沙盒 | 云端沙盒 |
| 隐私 | 高(数据不离开本地) | 中 | 低(全上云) |
| 可扩展性 | 受限于用户设备 | 水平扩展 | 水平扩展 |
| GPU idle 问题 | Server 可服务其他用户 | Z 期间 GPU idle + KV 占显存 | Z 期间 GPU idle + KV 占显存 |
| 核心 trade-off | RTT 换 隐私+本地工具 | 复杂度 换 灵活性 | GPU 空闲 换 低延迟闭环 |
Orchestrator 通过路由层选择 dispatch 路径,不同路径的 CPU 开销和 Z 延迟差异显著。
Agent 系统的评价指标体系,覆盖延迟、吞吐、效率、成本四个维度。每个指标标注其测量位置(CPU / GPU / Tool / End-to-End)。