lats

Language Agent Tree Search - Monte Carlo planning - 92.7% on HumanEval

170 stars

Best use case

lats is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Language Agent Tree Search - Monte Carlo planning - 92.7% on HumanEval

Teams using lats should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/lats/SKILL.md --create-dirs "https://raw.githubusercontent.com/Miosa-osa/canopy/main/library/skills/ai-patterns/lats/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/lats/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How lats Compares

Feature / AgentlatsStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Language Agent Tree Search - Monte Carlo planning - 92.7% on HumanEval

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# LATS (Language Agent Tree Search)

Monte Carlo Tree Search combined with LLM reasoning. Achieved **92.7% pass@1** on HumanEval (SOTA).

## Activation

Use for:
- Complex multi-step planning
- Code generation with tests
- Decision-making with feedback loops
- Tasks where environment provides signals (tests, builds, APIs)

## Core Algorithm

```
while not solved and budget > 0:
    1. SELECT:      Pick best node using UCT formula
    2. EXPAND:      Generate N candidate actions
    3. SIMULATE:    Execute actions, get environment feedback
    4. REFLECT:     Self-evaluate trajectory quality
    5. BACKPROPAGATE: Update scores up the tree
```

## Key Components

### Selection (UCT Formula)
```
UCT(node) = exploitation + C * sqrt(ln(N) / n)
          = avg_score    + exploration_bonus

Where:
- C = exploration constant (typically 1.41)
- N = parent visit count
- n = node visit count
```

### Expansion
Generate top-5 candidate actions in parallel using the Task tool.

### Reflection Prompt
```
"Given this trajectory and outcome:
Trajectory: [actions taken]
Result: [success/failure + details]

Rate this approach 1-10 and explain:
1. What worked well?
2. What went wrong?
3. How could it be improved?"
```

### Backpropagation
```python
def backpropagate(node, score):
    while node:
        node.visits += 1
        node.total_score += score
        node = node.parent
```

## Integration with OSA

LATS is activated by @master-orchestrator when:
- Task complexity is "complex" or "critical"
- Multiple valid solution paths exist
- Environment provides feedback (tests, builds)
- High accuracy is more important than speed

## Cost Consideration

LATS is compute-intensive (5-10x more LLM calls). Reserve for:
- High-value tasks
- When accuracy > cost
- As escalation from simpler methods

---

*Based on ICML 2024 research - arXiv:2310.04406*