Skip to main content

Compositional Prompting for LLM Reasoning: A Monte Carlo Tree Search Framework

Large language models are powerful, but getting them to reason effectively requires the right prompts. The problem? Most prompting strategies either rely on hand-crafted templates or simple trial-and-error.

We present a fundamentally different approach: treat prompting as a search problem.

The Core Idea

Instead of manually crafting the perfect prompt, what if we could systematically explore the space of possible prompts? Monte Carlo Tree Search (MCTS) excels at navigating large decision spaces—it’s the algorithm behind AlphaGo and other game-playing AI systems.

Our system applies MCTS to prompt engineering with a key innovation: a 5-dimensional action space that decomposes prompting into fundamental operations:

  1. Context: What background information to include
  2. Examples: Which few-shot examples to provide
  3. Constraints: What guidelines or restrictions to specify
  4. Format: How to structure the output
  5. Reasoning: What thinking strategies to encourage

Why This Matters

Traditional prompting approaches:

  • Require expertise and intuition
  • Don’t compose well (adding features can break existing prompts)
  • Lack systematic exploration

Our compositional approach:

  • Systematically explores prompt variations
  • Combines primitives in principled ways
  • Learns what works through search

The Search Process

# Simplified conceptual flow
while not converged:
    # MCTS exploration
    prompt = select_promising_prompt()

    # Try it with LLM
    result = llm.generate(prompt)

    # Evaluate quality
    score = evaluate(result)

    # Update search tree
    backpropagate(score)

The system learns which prompt components work well together, gradually building more effective prompts through systematic exploration.

Key Results

Our experiments show:

  • 30% improvement over baseline prompting on reasoning tasks
  • Discovers novel strategies not in hand-crafted prompts
  • Composes effectively across different task types

Applications

This framework is particularly useful for:

  • Complex reasoning tasks (math, logic, planning)
  • Domains where prompt engineering expertise is limited
  • Systems that need to adapt prompts dynamically
  • Research on understanding LLM behavior

Read the Full Paper

For technical details on the action space design, MCTS adaptation, and experimental results:

View Paper

The paper includes:

  • Formal specification of the 5-dimensional action space
  • MCTS algorithm adaptations for discrete prompt composition
  • Detailed experimental methodology and results
  • Analysis of discovered prompting strategies
  • Ablation studies on each dimension

Tags: LLM reasoning, Monte Carlo Tree Search, prompt engineering, compositional systems, AI search

Discussion