Day 3 of 5
⏱ ~60 minutes
Multi-Agent Systems — Day 3

The Debate Pattern: AI Reviewing AI for Better Outputs

The debate pattern assigns one agent to generate and another to critique — then iterates until the output meets a quality bar. This produces significantly better results for high-stakes content.

Why Debate Produces Better Outputs

Single-agent outputs have a consistent blind spot: the agent does not know what it does not know. A critic agent catches logical errors, unsupported claims, and missing considerations that the original generator missed.

debate.js
import Anthropic from '@anthropic-ai/sdk';
import * as dotenv from 'dotenv';
dotenv.config();

const client = new Anthropic();

async function callAgent(system, message) {
  const response = await client.messages.create({
    model: 'claude-opus-4-5',
    max_tokens: 2048,
    system,
    messages: [{ role: 'user', content: message }]
  });
  return response.content[0].text;
}

const GENERATOR = 'You write thorough, well-structured analysis. Be specific and concrete.';
const CRITIC = `You are a rigorous critic. Review the work and identify:
1. Factual errors or unsupported claims
2. Missing important considerations
3. Logical weaknesses
4. Sections that are vague or generic

Be specific about each issue. Rate severity: [HIGH/MEDIUM/LOW].
End with: PASS (if quality is acceptable) or REVISE (if it needs work).`;
const REVISER = 'You improve drafts based on critique feedback. Address each HIGH and MEDIUM issue specifically.';

async function debateLoop(task, maxRounds = 3) {
  let currentOutput = await callAgent(GENERATOR, task);
  console.log('Initial draft generated.');
  
  for (let round = 1; round <= maxRounds; round++) {
    console.log(`
Critique round ${round}...`);
    
    const critique = await callAgent(
      CRITIC,
      `Review this work:

${currentOutput}`
    );
    
    console.log('Critique summary:', critique.slice(0, 200) + '...');
    
    // Check if critic approves
    if (critique.includes('PASS')) {
      console.log('Quality check passed!');
      break;
    }
    
    if (round < maxRounds) {
      console.log('Revising...');
      currentOutput = await callAgent(
        REVISER,
        `Original task: ${task}

Current version:
${currentOutput}

Critique:
${critique}

Revise to address the HIGH and MEDIUM issues.`
      );
    }
  }
  
  return currentOutput;
}

// Example: write a persuasive argument
const result = await debateLoop(
  'Write a persuasive case for why small businesses should adopt AI tools in 2026'
);
console.log('
FINAL OUTPUT:
', result);
Day 3 Exercise
Run the Debate Loop
  1. Run debate.js and compare the initial draft to the final output.
  2. Read the critique output — what did the critic catch?
  3. Increase maxRounds to 5. Does quality keep improving or plateau after round 2-3?
  4. Try a task where factual accuracy matters — notice how the critic flags unsupported claims.

Day 3 Summary

  • Debate loops: generate → critique → revise → repeat until PASS or max rounds.
  • The critic identifies specific issues; the reviser addresses them directly.
  • Quality usually plateaus after 2-3 rounds. More rounds add cost without proportional benefit.
  • Best for high-stakes content: analyses, persuasive writing, technical documentation.
Finished this lesson?