Skip to main content
SGLang provides a powerful frontend language that makes it easy to program LLM applications with intuitive primitives and control flow. The frontend language is designed to simplify complex prompting workflows, enable advanced features like parallel sampling and streaming, and work seamlessly with various backend providers.

Key Features

Intuitive Programming Model

The SGLang frontend uses Python decorators and a state-based programming model that feels natural for Python developers:

Advanced Control Flow

Parallel Sampling: Fork execution to generate multiple responses in parallel
Conditional Logic: Use Python’s native control flow with generated outputs

Execution Modes

Single Execution: Run a single request and get results
Batch Processing: Process multiple inputs efficiently
Streaming: Stream outputs in real-time
Async Streaming: Asynchronous iteration for concurrent applications

Core Concepts

State Object

The state object (s) is the central construct in SGLang functions. It maintains:
  • The conversation history
  • Generated variables and their values
  • Role context (system, user, assistant)
  • Images and video data for multimodal models

Variables

Generated text is automatically stored in named variables:

Composition

SGLang functions can be composed and reused:

Constrained Generation

SGLang supports various forms of constrained generation: Choice Selection: Choose from predefined options
Regular Expressions: Constrain output format with regex
JSON Schema: Generate structured JSON output

Next Steps