Multi-agent · Free preview

Vote to Decide

Aggregate many answers

Ensembling runs the same question across several agents and aggregates their answers — a majority vote turns noisy individual guesses into one robust decision.

Aggregate many answers

In the last orchestrator lesson you fanned different subtasks out to workers and combined the distinct results. Here you fan the same question out to several agents — and now their outputs can conflict. A single agent can be confidently wrong: it hallucinates a "yes," and because you only asked once, you have no way to know. Sampling is noisy; betting the whole decision on one draw is the gamble.

The fix is ensembling: ask the same question to several agents (or the same agent several times at nonzero temperature) and combine their answers instead of trusting one. The simplest combiner is a majority vote — whichever answer the most agents gave wins. The intuition is statistical: if each agent is right more often than not and their errors are roughly independent, the majority is right far more often than any single member. Disagreement isn't noise to hide; it's the signal you aggregate.

Walk the build's case. Five agents answer a yes/no question: ["no", "yes", "yes", "no", "yes"]. You tally as you go — no seen first, then yes — ending no: 2, yes: 3, so the winner is yes (3/5). Note the tie-break: had it come back 2–2, you'd keep the option seen first, which is why you track first-seen order alongside the counts instead of trusting a map's iteration order. And you print the full tally, not just the winner — the breakdown is your evidence and your confidence signal (3/5 is a shakier call than 5/5).

Ensembling is the cheapest robustness you can buy: a few extra calls turn a fragile single guess into a decision that degrades gracefully. The cost is real (N× the compute), so you spend it where being wrong is expensive.

Tally how many votes each answer got while preserving first-seen order, pick the majority (ties to first-seen), and print winner: <answer> (<count>/<total>) followed by one <answer>: <count> line per option. Done looks like winner: yes (3/5) over a no: 2 / yes: 3 tally. The starter just echoes the first agent — make it actually count the room.

Ensembling trades a little compute for a lot of robustness: many ordinary answers, aggregated, beat one fragile guess.

In the full academy, you write and run this — live, graded:

// Five agents each answered the same yes/no question independently.
// They disagree — that's normal. Your job: aggregate them into ONE decision.
const answers = ["no", "yes", "yes", "no", "yes"];

// TODO: tally how many times each answer appears (preserve first-seen order),
//       pick the MAJORITY (most votes; ties go to whichever was seen first),
//       then print:
//         winner: <answer> (<count>/<total>)
//         <answer>: <count>   ← one line per option, in first-seen order

// Naive placeholder — just trusts the first agent. Replace it.
const winner = answers[0];
console.log(`winner: ${winner} (1/${answers.length})`);

🔒 Live code execution, real agent runs, mastery tracking and verifiable credentials unlock with the full academy.

This is 1 of 50 lessons.

The full academy: write real code, watch real agents run, and earn verifiable credentials — across 8 tracks, in a 3D campus.

Unlock the full academy — $100 →

14-day refund · 🔒 Stripe-secured checkout · lifetime access

More free lessons: An LLM Is a Function  ·  The Agent Loop  ·  Define a Tool  ·  Give an Agent a Tool  ·  Durable State

← The Agent Marketplace