Skip to content

Repository files navigation

Politics Agent

An interactive AI-powered political debate simulation game where users engage with dynamically generated characters representing diverse political ideologies.

Overview

Politics Agent creates immersive debate experiences using AI-controlled characters. Each character has a distinct political perspective, personality, and argumentation style. Users navigate branching debate trees, exploring different political arguments and perspectives in an educational, roguelike-style experience.

Features

  • Dynamic AI Characters: Characters with unique political spectrums, tones, and debate styles generated via GPT-4o-mini
  • Branching Debates: Navigate through different argument paths, creating a tree of debate history
  • Multiple Perspectives: Classical political positions (liberal, conservative, social-democrat, etc.) plus creative/unusual ideologies
  • Educational Tools: Debug panels to visualize AI decision-making, character stats, and export functionality
  • Streaming Responses: Real-time character speech generation with SSE streaming
  • Session Persistence: Debate history saved to localStorage for session continuity

Tech Stack

  • Framework: Next.js 16 with App Router
  • Language: TypeScript 5 (strict mode)
  • UI: React 19 + Tailwind CSS 4
  • AI: OpenAI SDK (GPT-4o-mini)
  • Validation: Zod for schema validation
  • Testing: Vitest

Getting Started

Prerequisites

  • Node.js 18+
  • OpenAI API key

Installation

# Clone the repository
git clone https://github.com/your-username/politics-agent.git
cd politics-agent

# Install dependencies
npm install

# Create environment file
cp .env.example .env.local

Configuration

Create a .env.local file with your OpenAI API key:

OPENAI_API_KEY=your_openai_api_key_here

Running the Application

# Development server
npm run dev

# Production build
npm run build
npm start

Open http://localhost:3000 in your browser.

Project Structure

src/
├── agents/              # AI agent logic
│   ├── director-llm.ts  # Orchestrates debate turns
│   ├── character-llm.ts # Generates character speeches
│   └── schemas/         # Zod schemas for LLM outputs
├── app/
│   ├── api/             # Backend API routes
│   ├── components/      # React UI components
│   └── page.tsx         # Main application page
├── domain/              # Domain types and fixtures
├── hooks/               # Custom React hooks
└── lib/                 # Utilities (OpenAI client, context, storage)

API Endpoints

Endpoint Method Description
/api/debate/turn POST Process a debate turn
/api/debate/turn-stream POST Streaming debate turn
/api/personalities/generate POST Generate personality pool

How It Works

  1. Director Agent: Orchestrates each turn, managing topic focus, character intents, and navigation paths
  2. Character Agent: Generates contextual speeches based on character profiles and debate context
  3. Personality Generator: Creates unique political personas combining unexpected ideological elements

Character Intent Types

  • present_argument - Present a new argument
  • criticize - Challenge another position
  • reconcile - Find common ground
  • contextualize - Add historical/social context
  • question - Pose questions to other characters
  • defend - Defend a position under attack

Tone Variations

  • moderate - Balanced, measured responses
  • inflamed - Passionate, intense rhetoric
  • technical - Academic, detailed analysis
  • popular - Accessible, everyday language

Scripts

npm run dev          # Start development server
npm run build        # Build for production
npm run start        # Start production server
npm run lint         # Run ESLint
npm run test         # Run tests
npm run test:watch   # Run tests in watch mode
npm run validate     # Validate domain types

License

MIT

About

An interactive AI-powered political debate simulation where users engage with dynamically generated characters representing diverse ideologies. Features branching debate trees, multiple political perspectives, real-time streaming responses, and educational tools to visualize AI decision-making.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages