A sophisticated debate simulation system built with LangGraph where AI agents engage in structured arguments, complete with memory management, turn validation, and automated judging.
Please checkout the demo_video Watch the demo video
This system implements a technical assignment for creating a multi-agent debate workflow using LangGraph. Two AI agents with different professional personas engage in an 8-round structured debate on a user-defined topic, with comprehensive memory management and automated judgment.
- Multi-Agent Architecture: AgentA (Scientist) vs AgentB (Philosopher) with distinct personas
- Structured Debate Flow: Exactly 8 rounds with alternating turns (4 arguments per agent)
- Memory Management: Intelligent memory node that tracks and summarizes debate history
- Turn Validation: Ensures agents only speak in their assigned turns with no repeated arguments
- Automated Judging: Sophisticated JudgeNode that evaluates debate quality and declares winners
- Comprehensive Logging: Full state transitions and debate interactions logged
- DAG Visualization: Auto-generated Mermaid diagrams of the LangGraph architecture
- CLI Interface: Clean command-line interface for user interaction
- UserInputNode: Accepts debate topic at runtime
- AgentA: Scientist persona - argues in odd rounds (1, 3, 5, 7)
- AgentB: Philosopher persona - argues in even rounds (2, 4, 6, 8)
- MemoryNode: Stores and summarizes debate transcript
- ValidatorNode: Ensures turn compliance and argument uniqueness
- JudgeNode: Reviews entire debate and declares winner with justification
__start__ โ user_input โ agent_a โ agent_b โ memory โ validator
โ โ
agent_a โ-------------+
โ
judge โ __end__
- Python 3.9+
- Virtual environment (recommended)
# Clone the repository
git clone <repository-url>
cd debator-cli
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Install Playwright browsers (required by mermaid-cli for DAG generation)
playwright installlanggraph>=0.2.0- Core workflow orchestrationgoogle-generativeai==0.5.4- Gemini API integrationtransformers==4.57.0- Local model fallbackpython-dotenv==1.0.1- Environment configurationmermaid-cli==0.1.2- DAG diagram generationrich==14.2.0- Enhanced CLI output
Create a .env file with your Gemini API key:
GEMINI_API_KEY=your_gemini_api_key_hereTo start the debate simulation, simply run the main application script:
python app.pyNote
Model Usage: This project is designed to support both Hugging Face (HF) local models and the Gemini API.
- Default: We use the Gemini API (
gemini-2.0-flash) by default for its superior speed, reasoning capabilities, and faster processing times. - Fallback: Local HF models (e.g.,
google/flan-t5-base) are implemented as a robust fallback mechanism but are slower and resource-intensive.
Enter topic for debate (default: 'Should AI be regulated like medicine?'): Should AI be regulated like medicine?
Starting debate between Scientist and Philosopher...
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ Round 1 โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ Scientist โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ AI must be regulated due to high-risk applications in healthcare and finance, where algorithmic โ
โ decisions directly impact human lives and safety. โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
[... debate continues through 8 rounds ...]
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ Judge's Verdict โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ Judge's Summary โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ โโโโโโโโโโโโโโโโโโโโโโโโณโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Winner โ Rationale โ โ
โ โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ โ
โ โ Scientist (AgentA) โ The Scientist presented more grounded, risk-based arguments aligned โ โ
โ โ โ with public safety principles and practical regulatory frameworks. โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
debator-cli/
โโโ app.py # Main CLI application entry point
โโโ main.py # Debate orchestration logic
โโโ requirements.txt # Python dependencies
โโโ .env # Environment variables (API keys)
โโโ src/ # Core implementation modules
โ โโโ nodes.py # Agent, Memory, and Judge node definitions
โ โโโ langgraph_debate.py # LangGraph workflow construction
โ โโโ dag_gen.py # DAG diagram generation
โ โโโ state.py # State management schemas
โ โโโ logger_util.py # Logging utilities
โโโ records/ # Generated debate artifacts
โ โโโ [topic]/ # Topic-specific outputs
โ โโโ debate_log.txt # Full JSON log of debate
โ โโโ langgraph_dag.mmd # Mermaid DAG diagram
โ โโโ langgraph_dag.png # Visual DAG representation
โ โโโ debate_dag_dag.txt# Debate flow summary
โโโ README.md # This documentation
The system uses LangGraph's StateGraph with a comprehensive DebateState TypedDict:
class DebateState(TypedDict):
topic: str # Debate topic
persona_a: str # Persona for Agent A
persona_b: str # Persona for Agent B
round: int # Current round number (1-8)
transcript: List[dict] # Full transcript of all arguments
seen_texts: List[str] # Seen arguments for duplicate detection
current_agent: str # "AgentA" or "AgentB"
winner: Optional[str] # Winner determined by judge
rationale: Optional[str] # Judge's rationale
error: Optional[str] # Error message
last_speaker: Optional[str] # Last agent who spoke
last_text: Optional[str] # Last argument textEach agent is implemented with:
- Persona-specific prompts: Scientist focuses on evidence and safety, Philosopher on ethics and values
- Context awareness: Access to previous arguments and memory summaries
- Argument validation: Ensures unique, coherent responses using Jaccard similarity
- Fallback mechanisms: Local model backup when API fails
The MemoryNode provides:
- Transcript storage: Complete debate history with metadata
- Intelligent summaries: Periodic condensation of key points
- Context provision: Relevant memory for each agent's turn
- State isolation: Agents receive only necessary context
The JudgeNode implements:
- Comprehensive evaluation: Analyzes all arguments and interactions
- Scoring system: Weighted keyword analysis for relevance and persuasiveness
- Winner determination: Logic-based verdict with detailed rationale
- Quality assessment: Evaluates argument strength, coherence, and persuasiveness
The ValidatorNode ensures:
- Turn compliance: Agents only speak in assigned rounds
- Argument uniqueness: Prevents repetition using similarity analysis (>0.98 threshold)
- Logical flow: Maintains debate coherence
- Error handling: Graceful recovery from validation failures
- Comprehensive JSON logging: All state transitions and node interactions
- Timestamped events: Complete audit trail of debate execution
- Error tracking: Detailed error reporting and recovery
- Mermaid source: Editable graph definitions showing node connections
- PNG visualization: High-quality diagram images
- Flow documentation: Clear workflow representation with conditional routing
- Topic-specific folders: Organized by debate topic
- Complete transcripts: Full argument history with round metadata
- Judgment summaries: Winner declarations with detailed rationale
The system leverages LangGraph for:
- State management: Centralized state schema with type safety
- Workflow orchestration: Reliable node execution and transitions
- Conditional routing: Dynamic flow control based on debate state
- Error handling: Robust error recovery and logging
- Checkpointing: State persistence and recovery
- Primary: Gemini API: Advanced reasoning capabilities with
gemini-2.0-flash - Fallback: Local Transformers: Offline capability with FLAN-T5 base model
- Prompt engineering: Optimized for debate-specific tasks with persona guidance
- Response validation: Quality filtering and coherence checks
- Structured state: Pydantic models for type safety
- Efficient storage: Optimized transcript and summary management
- Context extraction: Intelligent memory retrieval for agents
- Scalable design: Handles extended debates efficiently
โ
LangGraph DAG Correctness: Fully functional StateGraph with proper state management and conditional routing
โ
Debate Round Control: Exact 8-round structure with alternating turns (AgentA: 1,3,5,7; AgentB: 2,4,6,8)
โ
Memory Handling: Comprehensive transcript and summary management with intelligent context provision
โ
Judge Logic: Sophisticated evaluation with scoring system and detailed justification
โ
State Validation: Turn compliance, argument uniqueness, and logical coherence enforcement
โ
CLI Interface: Clean, user-friendly command-line interaction with rich formatting
โ
Comprehensive Logging: Full JSON logging of all state transitions and node executions
โ
DAG Visualization: Auto-generated Mermaid diagrams with PNG export capability
- API Key Errors: Ensure GEMINI_API_KEY is properly set in
.env - Memory Issues: Check available disk space for large debate logs
- Import Errors: Verify all dependencies are installed correctly
- DAG Generation: Ensure mermaid-cli is installed for diagram generation
- Syntax Errors: Fixed f-string backslash issues in nodes.py
Enable verbose logging by setting environment variable:
export DEBUG=true
python app.py- API Rate Limits: Built-in retry mechanisms and exponential backoff
- Memory Usage: Efficient transcript storage with periodic cleanup
- Response Time: Optimized prompt engineering for faster AI responses
- Error Recovery: Robust fallback to local models when needed
- Multi-persona support: More than 2 debaters with different roles
- Real-time interface: Web-based debate visualization
- Custom personas: User-defined agent characteristics
- Debate analytics: Advanced metrics and insights
- Tournament mode: Multi-round debate competitions
This project is submitted as a technical assignment and demonstrates advanced LangGraph implementation and AI agent orchestration capabilities.
For issues, improvements, or questions regarding this implementation, please refer to the project documentation and code comments for detailed explanations of the architecture and design decisions.