Skip to main content

Overview

The DebateWithJudge module provides a sophisticated debate architecture with self-refinement through a judge agent. This system enables two agents (Pro and Con) to debate a topic, with a Judge agent evaluating their arguments and providing refined synthesis. The process repeats for N rounds to progressively refine the answer.

Installation

Architecture

Key Concepts

Attributes

Optional[Agent]
default:"None"
The agent arguing in favor (Pro position). Not required if using agents list or preset_agents.
Optional[Agent]
default:"None"
The agent arguing against (Con position). Not required if using agents list or preset_agents.
Optional[Agent]
default:"None"
The judge agent that evaluates arguments and provides synthesis. Not required if using agents list or preset_agents.
Optional[List[Agent]]
default:"None"
A list of exactly 3 agents in order: [pro_agent, con_agent, judge_agent]. Takes precedence over individual agent parameters.
bool
default:"True"
If True, creates default Pro, Con, and Judge agents automatically with optimized system prompts when no agents list or individual agents are supplied. Defaults to True, so DebateWithJudge() with no agent arguments works out of the box.
int
default:"3"
Maximum number of debate rounds to execute.
str
default:"str-all-except-first"
Format for the output conversation history.
bool
default:"True"
Whether to enable verbose logging.
str
default:"gpt-5.4"
The model name to use for preset agents.

Initialization Options

The DebateWithJudge class supports three ways to configure agents:

Option 1: Preset Agents (Simplest)

Use built-in agents with optimized system prompts for debates:

Option 2: List of Agents

Provide a list of exactly 3 agents (Pro, Con, Judge):

Option 3: Individual Agent Parameters

Provide each agent separately:

Methods

run()

Executes the debate with judge refinement process for a single task and returns the refined result.
Parameters:
  • task (str): The initial topic or question to debate
Returns: The formatted conversation history or final refined answer, depending on output_type Process Flow:
  1. Task Validation: Validates that the task is a non-empty string
  2. Agent Initialization: Initializes all three agents with their respective roles and the initial task context
  3. Multi-Round Execution: For each round (up to max_loops):
    • Pro agent presents an argument in favor
    • Con agent presents a counter-argument
    • Judge agent evaluates both arguments and provides synthesis
    • Judge’s synthesis becomes the topic for the next round
  4. Result Formatting: Returns the final result formatted according to output_type
Raises:
  • ValueError: If task is None or empty. (Invalid agent configuration or max_loops < 1 raise ValueError at construction time, in __init__, not in run().)

batched_run()

Executes the debate for multiple tasks sequentially.
Parameters:
  • tasks (List[str]): List of topics or questions to debate
Returns: List of final refined answers, one for each input task

Output Types

The output_type parameter controls how the conversation history is formatted:

Usage Examples

Quick Start with Preset Agents

Policy Debate with Custom Agents

Using Agent List

Batch Processing Multiple Topics

Business Strategy Debate with Conversation History

Best Practices

Agent Configuration: Use preset_agents=True for quick setup with optimized prompts. For specialized domains, create custom agents with domain-specific prompts. Consider using more powerful models for the Judge agent.
Choosing an Initialization Method: Use preset_agents=True for quick prototyping, agents=[...] list when you have agents from external sources, and individual parameters for maximum control.
Loop Configuration: Use 2-3 loops for most topics and 4-5 loops for complex, multi-faceted topics. More loops allow for deeper refinement but increase execution time.
Output Format: Use "str-all-except-first" for readable summaries (default), "dict" for structured analysis, "list" for conversation inspection, and "str" for complete history.
Performance: Batch processing is sequential — consider parallel execution for large batches. Each round requires 3 agent calls (Pro, Con, Judge). Memory usage scales with conversation history length.

Troubleshooting

Source Code

View the source code on GitHub