Inference and Serving Infrastructure

SGLang

SGLang treats multi-call prompting, agent control flow, and structured outputs as language-model programs, then accelerates them with a Python DSL plus runtime optimizations such as RadixAttention and compressed-FSM decoding.

6Claims
6Evidence

Why It Matters

For agents, SGLang is the serving/runtime bridge: it gives a programming surface for LM workflows and a backend that reuses KV state across calls instead of treating each call as an unrelated request.

Problem

  • LLM applications increasingly use multiple generation calls, prompting techniques, control flow, tool interaction, and structured inputs/outputs.
  • Developers often implement LM programs with brittle string manipulation, output parsing, manual parallelism, and ad-hoc synchronization.
  • General inference engines such as vLLM, TGI, and TensorRT-LLM optimize individual calls without knowing the multi-call program structure.
  • Existing engines often discard KV cache after a request, missing reuse opportunities across calls with shared prefixes.
  • Structured output decoding often masks next-token probabilities one token at a time, even when constraints permit multi-token progress.

Key gap: The paper asks how to both program and efficiently execute structured multi-call LLM workflows rather than isolated model invocations.

Method

Expose LM-program structure through a Python DSL, represent prompt state as a stream, execute branches asynchronously, retain and index KV cache in a radix tree for prefix reuse, and speed structured decoding with compressed automata.

  • Write the LM workflow as a Python-embedded SGLang program using generation and control-flow primitives.
  • Interpret the program while maintaining prompt state streams and asynchronous primitive execution.
  • When a generation call arrives, match its prefix against the RadixAttention tree.
  • Reuse matching KV-cache blocks and insert newly generated suffixes into the radix tree.
  • Evict cached prefixes with LRU-like policy when memory pressure requires it.
  • Compile structured output constraints into a compressed finite-state machine.
  • Skip token-by-token work where the FSM has deterministic multi-token paths.
  • For API-only models, speculatively issue likely future calls to hide multi-call latency.

Claims

C1 · paper-supported

Modern LM applications increasingly require multiple generation calls, control flow, advanced prompting, and structured inputs/outputs.

Scope: Abstract and Introduction.

  • E-lm-programs: The paper states LLMs are used for complex tasks requiring multiple generation calls, advanced prompting, control flow, and structured inputs/outputs, and names these workloads language model programs.

C2 · paper-supported

SGLang consists of a frontend language and runtime: the frontend simplifies programming with generation and parallelism primitives.

Scope: Abstract and Introduction.

  • E-frontend: The frontend is a Python-embedded DSL with primitives for generation and parallelism control, including examples using gen, select, fork, and structured regex output.

C3 · paper-supported

RadixAttention reuses KV cache across generation calls by maintaining an LRU cache in a radix tree for efficient matching, insertion, and eviction.

Scope: Introduction and Section 3.

  • E-radixattention: The runtime maintains an LRU cache of KV cache entries in a radix tree, enabling efficient prefix matching, insertion, eviction, and cache-aware scheduling across calls.

C4 · paper-supported

Compressed finite-state machines speed structured output decoding by collapsing deterministic multi-token constraint paths into a single step when possible.

Scope: Abstract and Introduction.

  • E-compressed-fsm: The runtime compiles constraints into a compressed finite-state machine that can collapse multi-token deterministic paths and decode multiple tokens at once.

C5 · paper-supported

SGLang also supports API-only models and introduces API speculative execution for multi-call programs where the local runtime cannot directly control the model engine.

Scope: Introduction.

  • E-api-speculation: The paper says SGLang supports API-only models like GPT-4 and introduces API speculative execution to optimize multi-call programs for those models.

C6 · paper-supported

Across workloads including agent control, reasoning, few-shot learning, JSON decoding, RAG, multi-turn chat, and multimodal tasks, SGLang reports up to 6.4x higher throughput than compared systems.

Scope: Abstract and Introduction.

  • E-throughput: Experiments on models such as Llama-7B/70B, Mistral-8x7B, LLaVA-v1.5-7B, and LLaVA-NeXT-34B across agent control, reasoning, few-shot, JSON, RAG, multi-turn chat, and multimodal workloads report up to 6.4x higher throughput than Guidance, vLLM, and LMQL-style baselines.

Agent Infrastructure Takeaways

  • Agent workflows are LM programs. A serving runtime that sees the program can optimize across calls; an HTTP API that sees only isolated prompts cannot.
  • Prefix sharing is everywhere in agents: system prompts, tool schemas, retrieval context, task state, and branch roots should not be recomputed blindly.
  • RadixAttention turns prompt structure into a cache key and makes cache reuse a scheduler concern.
  • Structured output is a serving problem, not just parser cleanup. JSON/tool-call constraints can change decode speed.
  • The frontend/runtime split is useful: agent code should express control flow, while the runtime owns KV reuse, parallelism, constrained decoding, and API speculation.
  • SGLang is a bridge between agent frameworks and inference engines because it exposes enough structure for the engine to optimize agent-like workloads.

Caveats

  • The paper is an arXiv preprint and was under review in the version read.
  • The largest speedup depends on workloads with reusable prefixes or structured-output opportunities.
  • A DSL can simplify some workflows but also adds its own programming model and operational surface.
  • API speculative execution can spend money or rate limit budget on branches that are not ultimately needed.
  • RadixAttention cache management must compete with ordinary serving memory pressure and may evict useful prefixes.
  • SGLang improves execution efficiency; it does not by itself solve tool authorization, durable execution, or semantic correctness.