English

XGrammar-2: Efficient Dynamic Structured Generation Engine for Agentic LLMs

Artificial Intelligence 2026-05-27 v3

Abstract

Modern LLM agents increasingly rely on dynamic structured generation, such as tool calling and response protocols. Unlike traditional structured generation with static structures, these workloads vary both across requests and within a request, posing new challenges to existing engines. We present XGrammar-2, a structured generation engine for dynamic agentic workloads. Our design is based on two key ideas: first-class support for tag-triggered structure switching, and fine-grained reuse across requests with different output structures. Concretely, XGrammar-2 introduces TagDispatch for dynamic structural dispatching and Cross-Grammar Cache for substructure-level cache reuse across grammars. It further improves efficiency with an Earley-based adaptive token mask cache, just-in-time compilation, and repetition state compression. Experiments show that XGrammar-2 achieves over 6x faster compilation than prior structured generation engines, and incurs near-zero end-to-end overhead in modern LLM serving systems.

Keywords

Cite

@article{arxiv.2601.04426,
  title  = {XGrammar-2: Efficient Dynamic Structured Generation Engine for Agentic LLMs},
  author = {Linzhang Li and Yixin Dong and Guanjie Wang and Ziyi Xu and Alexander Jiang and Tianqi Chen},
  journal= {arXiv preprint arXiv:2601.04426},
  year   = {2026}
}

Comments

10 pages, ACM CAIS 26

R2 v1 2026-07-01T08:55:15.126Z