Week 15 • Day 3Week 15

Day 3:Parallel Map-Reduce Agents & Majority Voting Ensembles

Battle-tested daily lesson note • 100% runnable code, interview Q&A, test suite & interactive quiz

Day 3: Parallel Map-Reduce Agents & Majority Voting Ensembles

1. First-Principles Math: Condorcet's Jury Theorem for Agent Ensembles

Suppose we run MM independent reasoning agents (or diverse prompt/temperature samples) on a high-stakes classification or root-cause identification task, where each individual agent has accuracy p>0.5p > 0.5.

By Condorcet's Jury Theorem, the probability Pmajority(M,p)P_{\text{majority}}(M, p) that a majority vote of MM (odd) agents is correct is: Pmajority(M,p)=∑k=⌈M/2⌉M(Mk)pk(1−p)M−kP_{\text{majority}}(M, p) = \sum_{k = \lceil M/2 \rceil}^{M} \binom{M}{k} p^k (1 - p)^{M - k}

Example Calculation (p=0.80p = 0.80)

  • Single Agent (M=1M = 1): P=80.0%P = 80.0\%
  • 3-Agent Ensemble (M=3M = 3): P=(32)(0.8)2(0.2)+(33)(0.8)3=0.384+0.512=89.6%P = \binom{3}{2}(0.8)^2(0.2) + \binom{3}{3}(0.8)^3 = 0.384 + 0.512 = 89.6\%
  • 5-Agent Ensemble (M=5M = 5): P=94.21%P = 94.21\%

2. Map-Reduce over Log Shards

When an incident spans 500,000 log lines across N regional clusters, a single context window overflows.

  • Map Phase: Partition logs into NN regional shards; run NN stateless MapperAgent instances in parallel to extract structured ShardAnomalySummary objects.
  • Reduce Phase: A single ReducerAgent aggregates the NN compact summaries into a global diagnosis.

In Simple English: Wisdom of Crowds Voting (PmajorityP_{\text{majority}})

Suppose a complex bug classifier is right p=75%p = 75\% of the time on a single try:

  • Ask 1 agent once: 75% chance of being right.
  • Ask 3 independent agents (M = 3) in parallel (with slight prompt/temperature diversity) and take the majority vote (2 or 3 agree):
    • Chance all 3 are right: $0.75^3 = 42.2%$
    • Chance exactly 2 are right: $3 \times 0.75^2 \times 0.25 = 42.2%$
    • Combined Majority Accuracy: $42.2% + 42.2% = \mathbf{84.4%}$ — nearly +10% higher reliability in the exact same wall-clock latency because all 3 ran at once!
Week 15 Day 3: Parallel Map-Reduce Agents & Majority Voting Ensembles | 6-Month AI Engineer Roadmap · DataArena