AI Skills AI技能 3h ago Updated 1h ago 更新于 1小时前 48

Why vLLM and SGLang Are Replacing Ollama for Agentic Workflows 为什么 vLLM 和 SGLang 正在取代 Ollama 用于智能体工作流

Agent loops repeatedly re-send nearly identical prompts across hundreds of steps, creating significant redundant computation vLLM and SGLang implement persistent prompt caching that retains context across loop iterations, dramatically reducing redundant token processing Ollama drops cached prompts after five steps, forcing re-computation and introducing substantial latency overhead in long-running agent workflows Prompt caching efficiency is a critical differentiator for frameworks targeting age Agent循环场景中会重复发送几乎相同的prompt数百次,造成大量重复计算 vLLM和SGLang框架在步骤间保持prompt缓存,有效减少重复推理开销 Ollama在五次请求后丢弃缓存,可能导致长Agent循环性能下降

68
Hot 热度
72
Quality 质量
65
Impact 影响力

Analysis 深度分析

TL;DR

  • Agent loops repeatedly re-send nearly identical prompts across hundreds of steps, creating significant redundant computation
  • vLLM and SGLang implement persistent prompt caching that retains context across loop iterations, dramatically reducing redundant token processing
  • Ollama drops cached prompts after five steps, forcing re-computation and introducing substantial latency overhead in long-running agent workflows
  • Prompt caching efficiency is a critical differentiator for frameworks targeting agentic and multi-step reasoning applications

Why It Matters

For AI practitioners building agent-based systems, the choice of inference framework directly impacts performance and cost at scale. Agent loops are increasingly common in production RAG pipelines, autonomous agents, and multi-step reasoning workflows, making prompt caching a practical concern rather than a theoretical optimization. Frameworks that fail to maintain cache across iterations can incur orders-of-magnitude more compute than necessary.

Technical Details

  • Prompt caching mechanism: In agent loops, the system prompt and prior conversation history remain largely static while only new tool outputs or responses change. Caching avoids re-processing the KV cache for unchanged prefix tokens.
  • vLLM and SGLang: Both frameworks support continuous batching with prefix caching, maintaining the KV cache across successive requests within an agent loop. This enables near-zero overhead for repeated prompt prefixes.
  • Ollama: Appears to clear or expire its prompt cache after approximately five inference steps, requiring full re-computation of the KV cache for the shared prompt prefix on subsequent calls.
  • Performance impact: In loops running hundreds of steps, the difference between persistent caching and no caching translates to dramatically higher latency, GPU utilization, and inference costs with uncached frameworks.

Industry Insight

  • Framework selection should prioritize caching behavior when designing agent systems; benchmarking prompt cache hit rates under realistic loop conditions is essential before committing to an inference backend.
  • As agentic workflows become standard, expect the industry to converge on persistent KV cache support as a baseline requirement, with vendors likely competing on cache eviction policies and memory efficiency.
  • Developers using Ollama for agent loops should consider implementing application-level prompt caching or switching to vLLM/SGLang for production workloads to avoid compounding latency and cost penalties.

TL;DR

  • Agent循环场景中会重复发送几乎相同的prompt数百次,造成大量重复计算
  • vLLM和SGLang框架在步骤间保持prompt缓存,有效减少重复推理开销
  • Ollama在五次请求后丢弃缓存,可能导致长Agent循环性能下降

为什么值得看

对于构建Agent系统的开发者来说,理解不同推理框架的缓存策略至关重要,这直接影响系统性能和运行成本。

技术解析

  • Agent循环场景下,prompt重复发送是常见模式,缓存机制可以显著减少重复计算
  • vLLM和SGLang采用持续缓存策略,在多次请求间保持KV cache
  • Ollama的缓存策略较为保守,五次后清除缓存,可能影响长Agent循环的性能

行业启示

  • 选择推理框架时需考虑Agent场景下的缓存行为
  • 缓存策略对系统性能和成本有显著影响
  • 不同框架在长期运行场景下的表现差异值得关注

Disclaimer: The above content is generated by AI and is for reference only. 免责声明:以上内容由 AI 生成,仅供参考。

LLM 大模型 Inference 推理 Agent Agent Open Source 开源 Deployment 部署