Skip to content

best-of-n

best-of-n generates N variants of a response in parallel using the same agent and prompt, then has a judge pick the best one.

  • Creative tasks where quality varies between runs (headlines, taglines, ideas)
  • High-stakes generation where you want the best of multiple attempts
  • Tasks where diversity of output improves selection
  • Any situation where running the same prompt multiple times and picking the best is valuable
agents/my-best-of-n/
├── AGENT.md ← pattern: best-of-n, n, config
└── judge.md ← judge system prompt
---
name: headline-generator
description: Generates the best possible headline for an article.
version: "1.0.0"
pattern: best-of-n
n: 5
call:
model:
role: writer
temperature: 0.9
---
Generate a single compelling, specific headline for the article.
The headline should be accurate, engaging, and under 70 characters.
Return only the headline — no explanation, no quotes.
---
call:
model:
role: thinker
temperature: 0.0
---
You receive N candidate headlines for the same article.
Each is labeled with its variant number.
Evaluate each headline on:
1. **Accuracy** — does it accurately represent the article?
2. **Engagement** — is it compelling and click-worthy?
3. **Clarity** — is it specific and not vague?
4. **Length** — is it under 70 characters?
Select the single best headline.
Call finish with key="done" and ONLY the winning headline as value (no explanation).
Terminal window
tama add best-of-n my-agent
Input → N identical agents run in parallel (each with temperature for variety)
variant-1 → headline attempt
variant-2 → headline attempt
variant-3 → headline attempt
...
judge receives all N variants labeled by number
judge picks the best → final output

Use temperature on the AGENT.md to control how different the variants are:

  • temperature: 1.0 — high variety, more creative divergence
  • temperature: 0.5 — moderate variety
  • temperature: 0.0 — all variants nearly identical (not useful for best-of-n)

The n field controls how many variants to generate. Typical values:

nUse case
3Quick selection, low cost
5Good balance of variety and cost
10Creative tasks, high quality bar