Grammar Search for Multi-Agent Systems

Mayank Singh, Vikas Yadav, Shiva Krishna Reddy Malay, Shravan Nayak, Sai Rajeswar, Sathwik Tejaswi Madhusudhan, Eduardo Blanco

TL;DR

This paper introduces "Grammar Search," a novel framework for automatically discovering effective Multi-Agent Systems (MASes). Instead of relying on LLMs to generate code freely, Grammar Search uses a context-free grammar to define a structured space of composable components, ensuring valid and interpretable MASes while achieving superior performance and efficiency on several benchmarks.

What Problem Does This Paper Address?

The field of agentic AI is increasingly leveraging Multi-Agent Systems (MASes) to tackle complex problems by coordinating multiple Large Language Models (LLMs). While early MASes were manually designed, this approach is labor-intensive and doesn't scale. Recent efforts have focused on automatic MAS search, but existing methods often struggle with generating syntactically invalid or semantically inconsistent MASes, leading to wasted computational resources and overly complex, uninterpretable systems. This paper aims to address these challenges by proposing a more structured, efficient, and reliable approach to MAS discovery.

Methods

The core innovation is "Grammar Search," a framework that uses a context-free grammar to define a structured search space for MASes. This grammar specifies how simple, composable components can be assembled into valid MASes. The components themselves can be manually designed or derived from existing MASes. By sampling from this grammar, the framework guarantees syntactically correct MASes and enables a structured search. The process involves:

  1. Grammar Definition: A context-free grammar defines non-terminals (input/output structures) and terminals (concrete components like "StepByStepReasoner" or "MajorityVoter").
  2. Component Composition: The grammar enforces rules for connecting components, ensuring that inputs and outputs align.
  3. MAS Generation: Sequences of components derived from the grammar form candidate MASes.
  4. Forced Sampling: To ensure all components are fairly explored, a "forced sampling" strategy is employed. This strategy prioritizes sampling sequences that include components that have been sampled less frequently, balancing exploration.
  5. Evaluation: Candidate MASes are evaluated on a validation set, and the best performing one is selected.

This approach avoids direct LLM code generation during the search phase, leading to greater efficiency and reliability.

Datasets

The paper evaluates its method on four datasets:

  • MATH: A dataset of 12,000 competition-style math problems.
  • AIME: A dataset of challenging math competition questions.
  • MMLU-Pro: A more difficult variant of the MMLU benchmark with 10 answer choices per question.
  • GPQA: Expert-authored questions designed to resist shallow web-search-based answering.

The authors also introduce specific validation and test set splits for these datasets, often creating larger validation sets to better guide the search.

Key Insights and Ideas

  • Structure over Free-Form: By imposing a grammatical structure, the authors demonstrate that it's possible to achieve superior performance and efficiency compared to unconstrained LLM-based code generation for MAS search.
  • Guaranteed Validity: The grammar-based approach inherently ensures that generated MASes are syntactically correct and runnable, eliminating wasted computation on invalid code.
  • Modularity and Interpretability: The use of composable components and a structured grammar leads to MASes that are inherently more modular and easier to understand and extend.
  • Forced Sampling for Coverage: A simple yet effective "forced sampling" strategy is crucial for ensuring that all components within the grammar are adequately explored, preventing bias towards more frequently sampled components.

Key Results

Grammar Search outperforms previous automatic MAS search methods on four out of five evaluated benchmarks and on average.

  • Accuracy: Grammar Search achieves higher accuracy than the next-best method (ADAS) by 0.8 points on average, and 2.5% absolute improvement on AIME. It also outperforms the strongest manually designed MAS (Multi-Agent Debate) by 1.4 points.
  • Efficiency: The framework significantly reduces search costs, with an average total search cost of $8.37 per MAS compared to $10.25 for ADAS, a reduction of about 12%. It also eliminates generation costs for invalid MASes.
  • Reliability and Simplicity: Grammar Search generates valid MASes 100% of the time, unlike ADAS which produces invalid MASes 23% of the time. The generated MASes are also shorter (4,391.5 characters vs. 8,611.8 for ADAS) and exhibit less code growth.

Limitations and Future Work

  • Grammar Constraint: The approach's expressivity is limited by the defined grammar. While extensible, it lacks the free-form creativity of direct LLM code generation.
  • Component Dependency: The performance of the generated MASes is dependent on the quality of the initial components defined in the grammar.
  • Search Strategy: While forced sampling is effective, more sophisticated search algorithms like Monte Carlo Tree Search or Thompson sampling might be necessary as the grammar expands with more components.

Future work could involve expanding the grammar with more components and exploring more advanced search algorithms to further enhance performance and coverage.

Summary updated

BibTeX
@inproceedings{singh2026grammar,
  author = {Mayank Singh and Vikas Yadav and Shiva Krishna Reddy Malay and Shravan Nayak and Sai Rajeswar and Sathwik Tejaswi Madhusudhan and Eduardo Blanco},
  title = {{Grammar Search for Multi-Agent Systems}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2026},
  doi = {10.18653/v1/2026.acl-long.75},
}
Figure