Debate Agents Example
This example demonstrates how to create a sophisticated debate system with multiple agents playing different roles. It showcases dynamic agent interactions, role-based responses, and structured debate flow.
Overview
The Debate Agents example shows how to: - Create multiple specialized agents for different debate roles - Implement dynamic agent interactions - Manage debate flow and turns - Handle structured debate content - Integrate judging and evaluation
Implementation
Here's the complete implementation:
from datetime import datetime
from yosrai import Agent, Action, ContextFunctions
import agents_debate_prompts
# Selection Agent - Chooses debate participants
selection_agent = Agent(
agent_code='selection_agent',
agent_name='Selection Agent',
prompt_template=agents_debate_prompts.SELECTION_PROMPT,
outputs={'players_json': ContextFunctions.DEFAULT, 'players': ContextFunctions.JSON}
)
# Greeting Agent - Introduces the debate and participants
greeting_agent = Agent(
agent_code='greeting_agent',
agent_name='Greeting Agent',
agent_type='tool',
prompt_template=agents_debate_prompts.GREETING_PROMPT,
outputs={'greeting': ContextFunctions.DEFAULT}
)
# Player One Agent - First debate participant
player_one_agent = Agent(
agent_code='player_one_agent',
agent_name='Player One Agent',
prompt_template=agents_debate_prompts.PLAYER_ONE_PROMPT,
outputs={
'history': ContextFunctions.REPLIES,
'current_response': ContextFunctions.DEFAULT,
'messages': ContextFunctions.REPLIES
}
)
# Player Two Agent - Second debate participant
player_two_agent = Agent(
agent_code='player_two_agent',
agent_name='Player Two Agent',
prompt_template=agents_debate_prompts.PLAYER_TWO_PROMPT,
outputs={
'history': ContextFunctions.REPLIES,
'current_response': ContextFunctions.DEFAULT,
'messages': ContextFunctions.REPLIES
}
)
# Next Player Agent - Determines who speaks next
next_player_agent = Agent(
agent_code='next_player_agent',
agent_name='Next Player Agent',
agent_type='tool',
prompt_template=agents_debate_prompts.NEXT_PLAYER_PROMPT,
outputs={'next_player': ContextFunctions.DEFAULT}
)
# Judge Agent - Evaluates the debate
judge_agent = Agent(
agent_code='judge_agent',
agent_name='Judge Agent',
prompt_template=agents_debate_prompts.JUDGE_PROMPT,
outputs={'jury_response': ContextFunctions.DEFAULT, 'messages': ContextFunctions.REPLIES}
)
# Set up the workflow
action = Action('Debate Between Two Players')
action.Context(
query='',
greeting='',
players={'player_one': '', 'player_two': ''},
history=[],
no_of_rounds=1,
jury_response='',
date=datetime.now().strftime('%d-%m-%Y %H:%M:%S')
)
# Add agents to the action
action.add_agent(selection_agent)
action.add_agent(greeting_agent)
action.add_agent(player_one_agent)
action.add_agent(player_two_agent)
action.add_agent(next_player_agent)
action.add_agent(judge_agent)
# Define the workflow
action.add_link(selection_agent, greeting_agent)
action.add_link(greeting_agent, player_one_agent)
action.add_link_dynamic(player_one_agent, [player_two_agent, judge_agent], next_player_agent)
action.add_link_dynamic(player_two_agent, [player_one_agent, judge_agent], next_player_agent)
action.add_link(judge_agent, "END")
Workflow Visualization
The workflow shows the complex interaction between debate participants:
---
title: Two Players Debate
---
graph LR
START((Start)) --> selection_agent[Selection Agent]
selection_agent(Selection Agent) --> greeting_agent(Greeting Agent)
greeting_agent(Greeting Agent) --> player_one_agent(Player One Agent)
player_one_agent(Player One Agent) --> player_two_agent(Player Two Agent)
player_one_agent(Player One Agent) --> judge_agent(Judge Agent)
player_two_agent(Player Two Agent) --> player_one_agent(Player One Agent)
player_two_agent(Player Two Agent) --> judge_agent(Judge Agent)
judge_agent(Judge Agent) --> END((End))
Key Components
Selection Agent
Responsible for choosing debate participants:
selection_agent = Agent(
agent_code='selection_agent',
agent_name='Selection Agent',
prompt_template=agents_debate_prompts.SELECTION_PROMPT,
outputs={'players_json': ContextFunctions.DEFAULT, 'players': ContextFunctions.JSON}
)
Greeting Agent
Introduces the debate and sets the stage:
greeting_agent = Agent(
agent_code='greeting_agent',
agent_name='Greeting Agent',
agent_type='tool',
prompt_template=agents_debate_prompts.GREETING_PROMPT,
outputs={'greeting': ContextFunctions.DEFAULT}
)
Player Agents
Represent debate participants with structured responses:
player_one_agent = Agent(
agent_code='player_one_agent',
agent_name='Player One Agent',
prompt_template=agents_debate_prompts.PLAYER_ONE_PROMPT,
outputs={
'history': ContextFunctions.REPLIES,
'current_response': ContextFunctions.DEFAULT,
'messages': ContextFunctions.REPLIES
}
)
Next Player Agent
Controls debate flow and turn management:
next_player_agent = Agent(
agent_code='next_player_agent',
agent_name='Next Player Agent',
agent_type='tool',
prompt_template=agents_debate_prompts.NEXT_PLAYER_PROMPT,
outputs={'next_player': ContextFunctions.DEFAULT}
)
Judge Agent
Evaluates debate performance and determines outcome:
judge_agent = Agent(
agent_code='judge_agent',
agent_name='Judge Agent',
prompt_template=agents_debate_prompts.JUDGE_PROMPT,
outputs={'jury_response': ContextFunctions.DEFAULT, 'messages': ContextFunctions.REPLIES}
)
Example Interaction
Here's a sample debate interaction:
Selection Agent: "Selected participants: Data Analyst John vs Sports Strategist Sarah"
Greeting Agent:
Hello! Today 06-01-2025 21:00:16, we will witness a debate between
- Data Analyst John
- Sports Strategist Sarah
The topic of the debate is:
ManU vs Liverpool
Let's start the debate 🏁
Player One: "As a data analyst, I believe Manchester United has better historical performance metrics..."
Player Two: "From a strategic perspective, Liverpool's current squad depth and tactical flexibility..."
Judge: "After analyzing both arguments, Sarah's strategic analysis was more comprehensive..."
Best Practices
When implementing the Debate Agents pattern:
- Clear Roles: Define distinct responsibilities for each agent
- Turn Management: Implement robust turn-taking mechanisms
- Context Preservation: Maintain debate history and context
- Evaluation Criteria: Define clear judging criteria
- Dynamic Flow: Handle debate flow variations effectively
Use Cases
This pattern is ideal for: - Educational debate platforms - Decision-making systems - Argument analysis tools - Training simulations - Multi-perspective analysis
Next Steps
After implementing the Debate Agents pattern, you can: 1. Add more debate formats 2. Implement audience participation 3. Add real-time fact-checking 4. Enhance judging criteria 5. Add debate analytics