Debate Agent Implementation

Medium
Agents

Debate Agents for Better Reasoning

Debate between agents improves decision quality by surfacing opposing viewpoints.

Task

Build a debate system where:

  1. Agents argue for/against a topic over multiple rounds.
  2. Each rebuttal must address the opponent's last argument.
  3. A judge determines the winner based on argument quality (confidence scores).
  4. Return full transcript and winner.

Constraints

  • Minimum 2 agents (for/against).
  • Confidence must be between 0.0 and 1.0.
  • Winner: agent with highest average confidence across all rounds.
  • Tie-breaking: prefer 'for' stance.

Examples

Example 1:
Input: agents = [DebateAgent('pro', 'for', llm), DebateAgent('con', 'against', llm)] orchestrator = DebateOrchestrator(agents, rounds=2) orchestrator.run('Is Python better than Java?')
Output: {'winner': 'pro', 'rounds': 2, 'transcript': [...]}
Explanation: Two rounds of debate; pro agent wins by higher confidence score.

Starter Code

from typing import List, Dict, Tuple

class Position:
    def __init__(self, agent_id: str, stance: str, argument: str, confidence: float):
        self.agent_id = agent_id
        self.stance = stance  # 'for' | 'against' | 'neutral'
        self.argument = argument
        self.confidence = confidence  # 0.0 to 1.0

class DebateAgent:
    def __init__(self, agent_id: str, stance: str, llm_fn: callable):
        self.agent_id = agent_id
        self.stance = stance
        self.llm_fn = llm_fn
        self.positions: List[Position] = []

    def argue(self, topic: str, opponent_argument: str = '') -> Position:
        pass

    def rebut(self, opponent: 'DebateAgent', position: Position) -> Position:
        pass

class DebateOrchestrator:
    def __init__(self, agents: List[DebateAgent], rounds: int = 3):
        self.agents = agents
        self.rounds = rounds

    def run(self, topic: str) -> Dict:
        # TODO: Run debate and return winner + transcript
        pass

    def judge(self, transcript: List[Position]) -> str:
        # TODO: Return agent_id of winner based on confidence scores
        pass
Lines: 1Characters: 0
Ready
The AI Interview - Master AI/ML Interviews