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. Preset agents inherit this setting.
str
default:"gpt-5.4"
The model name to use for preset agents.
The constructor raises ValueError if max_loops is less than 1, if agents does not contain exactly three Agent instances, or if no agents are supplied and preset_agents=False. When several options are given, agents wins over the individual parameters, which win over 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. Fresh Conversation: Clears the conversation, so each run starts empty
  3. Agent Briefing: Runs each of the three agents once on an introduction prompt that names its role, its opponents, and the task. These briefings are not recorded in the conversation
  4. Multi-Round Execution: For each round (up to max_loops):
    • Pro agent presents an argument in favor. From round 2 on, it is asked to improve on the judge’s previous evaluation
    • Con agent presents a counter-argument to Pro’s argument
    • Judge agent evaluates both arguments and provides synthesis. In the last round it is told this is the final evaluation
    • Each agent’s final answer, not its whole transcript, is recorded under its name and passed on
    • Judge’s synthesis becomes the topic for the next round
  5. Result Formatting: Returns the conversation formatted according to output_type
A run makes 3 + 3 * max_loops agent calls: three briefings, then three calls per round. 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: A list of formatted outputs, one for each input task, in input order

Output Types

The output_type parameter controls how the conversation history is formatted:
The task itself is not recorded in the conversation, so the first message is the Pro agent’s opening argument. The default "str-all-except-first" therefore leaves that argument out. Use "str" or "list" to see the full debate, or "final" for just the final synthesis.
The preset system prompts and every per-round prompt template live in swarms.prompts.debate_with_judge_prompts, for example PRO_AGENT_SYSTEM_PROMPT, CON_AGENT_SYSTEM_PROMPT, and JUDGE_AGENT_SYSTEM_PROMPT.

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" for the complete, labelled transcript, "final" for only the judge’s last synthesis, and "dict" or "list" for structured inspection. The default "str-all-except-first" omits the Pro agent’s opening argument.
Performance: Batch processing is sequential — consider parallel execution for large batches. Each run makes 3 briefing calls plus 3 agent calls per round (Pro, Con, Judge). Memory usage scales with conversation history length.

Troubleshooting

Source Code

View the source code on GitHub