Portfolio-building game with trash-talking AI and behavioral coaching
Market Mayhem is an educational investing game that uses a multi-agent AI system to teach behavioral finance through gameplay. Players face realistic market scenarios while a trash-talking Villain AI tries to induce fear and FOMO. At the end, they receive a personalized behavioral profile and coaching.
Unlike typical trading simulations with random outcomes, Market Mayhem uses real historical price paths. Every outcome is based on actual market data, making it both educational and realistic.
- ๐ค 6 AI Agents working together (LangGraph + Google Gemini)
- ๐ Historical Replay - Real price paths, not random outcomes
- ๐ Villain AI - Trash-talking hot takes with cognitive biases
- ๐ง Behavioral Profiling - Learn your investing psychology
- ๐ฐ Real-Time News - Live headlines via Tavily API
- ๐ Data Tab - Consensus, contradiction score, historical outcomes
- ๐จ Beautiful UI - Next.js with Tailwind CSS and Framer Motion
- ๐ WebSocket - Real-time game updates
- ๐ Observability - Full tracing with Opik + LangSmith
- Event Generator - Creates realistic market scenarios
- Portfolio Agent - Manages player portfolios
- News Agent - Fetches headlines and computes consensus
- Price Agent - Historical outcome replay (core innovation!)
- Villain Agent - Generates biased hot takes
- Insight Agent - Behavioral profiling and coaching
Backend:
- FastAPI + WebSocket
- LangGraph (multi-agent orchestration)
- Google Gemini Pro (LLM)
- Tavily (news API)
- yfinance (historical data)
- PostgreSQL (Supabase)
Frontend:
- Next.js 14 + TypeScript
- Tailwind CSS
- Framer Motion
- WebSocket client
Observability:
- Opik (Comet ML)
- LangSmith
- Python 3.10+
- Node.js 18+
- API Keys:
- Google (Gemini Pro)
- Tavily (news)
- Supabase (optional)
- Opik (optional)
- LangSmith (optional)
git clone https://github.com/yourusername/market-mayhem.git
cd market-mayhemcd backend
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txt
# Configure environment
cp ../env.example .env
# Edit .env and add your API keys
# Run backend
python main.pyBackend will start at http://localhost:8000
cd frontend
npm install
# Configure environment
cp .env.local.example .env.local
# Edit .env.local if needed
# Run frontend
npm run devFrontend will start at http://localhost:3000
# Test backend (in project root)
pip install httpx rich
python test_backend.py-
Build Your Portfolio
- Select 2+ stocks from the ticker universe
- Allocate your $1,000,000 budget
- Choose your risk profile (Risk-On, Balanced, Risk-Off)
-
Play 3 Rounds
- Read the market event
- Listen to the Villain's hot take (intentionally misleading!)
- (Optional) Open the Data tab to see:
- Recent headlines with stance (Bull/Bear/Neutral)
- News consensus
- Contradiction score (how much Villain contradicts news)
- Price patterns
- Historical outcomes for similar events
- Make your decision: SELL ALL, SELL HALF, HOLD, or BUY
- See the outcome based on real historical data
-
Get Your Report
- Behavioral profile (Rational / Emotional / Conservative / Balanced)
- Personalized coaching tips
- Performance summary
Divhacks2025/
โโโ backend/
โ โโโ domain/ # Pure business logic (DDD)
โ โโโ infrastructure/ # Agents, tools, adapters
โ โโโ application/ # Use case handlers
โ โโโ prompts/ # Agent prompts
โ โโโ main.py # FastAPI app
โ
โโโ frontend/
โ โโโ app/ # Next.js pages
โ โโโ components/ # React components
โ
โโโ database/
โ โโโ schema.sql # PostgreSQL schema
โ โโโ seed_historical_cases.py # Data seeder
โ
โโโ design/ # Architecture docs
โโโ test_backend.py # Automated tests
โโโ README.md # This file
- PROJECT_COMPLETE.md - Full project summary
- DEPLOYMENT_GUIDE.md - How to deploy
- BACKEND_COMPLETE.md - Backend details
- design/ - Architecture and design docs
- database/README.md - Database setup
- backend/infrastructure/observability/README.md - Observability
Backend (Render):
- Push to GitHub
- Create new Web Service on Render
- Connect repo, set build command:
pip install -r requirements.txt - Set start command:
uvicorn main:app --host 0.0.0.0 --port $PORT - Add environment variables
Frontend (Vercel):
cd frontend
vercel --prodSee DEPLOYMENT_GUIDE.md for detailed instructions.
# Backend unit tests
python test_backend.py
# Frontend tests
cd frontend
npm test
# End-to-end test
# 1. Start backend: python backend/main.py
# 2. Start frontend: cd frontend && npm run dev
# 3. Open http://localhost:3000
# 4. Play through a complete gameMost trading games use random price movements. Market Mayhem is different:
- Real Historical Data - Every outcome uses actual price paths from yfinance
- Matching Algorithm - Finds similar historical cases by ticker, event type, and horizon
- Educational - Players see what really happened in similar scenarios
- No RNG - Outcomes are deterministic based on historical data
Example:
- Event: "Apple reports Q4 earnings beat of 15%"
- System finds: Actual Apple earnings beat from 2023-05-15
- Applies player decision to real price path from that date
- Shows actual 3-day outcome (+4.28% in this case)
The game uses 6 specialized ReAct agents orchestrated by LangGraph:
โโโโโโโโโโโโโโโโ
โ Supervisor โ
โโโโโโโโฌโโโโโโโโ
โ
โโโโโดโโโโโ
โ Agents โ
โโโโโโโโโโ
โโ Event Generator (creates scenarios)
โโ Portfolio Agent (manages positions)
โโ News Agent (fetches headlines)
โโ Price Agent (historical replay)
โโ Villain Agent (trash-talking)
โโ Insight Agent (coaching)
Each agent has specialized tools and prompts. The supervisor coordinates them to create the complete game experience.
Implementation: 100% Complete โ
- โ Backend (FastAPI + LangGraph)
- โ Frontend (Next.js + TypeScript)
- โ Database schema (PostgreSQL)
- โ All 6 AI agents
- โ Historical replay system
- โ WebSocket real-time updates
- โ Observability (Opik + LangSmith)
- โ Full documentation
- โ Deployment guides
- โ Testing scripts
This project is complete and production-ready. Feel free to fork and adapt for your own use!
MIT License - See LICENSE for details
Built using concepts from:
- Behavioral Finance - Cognitive biases in investing
- Domain-Driven Design - Clean architecture
- Multi-Agent Systems - LangGraph orchestration
- ReAct Agents - Reasoning and acting with LLMs
Developed for DivHacks 2025
Built with:
- LangGraph & LangChain
- Google Gemini Pro
- FastAPI
- Next.js
- Tavily API
- yfinance
- Opik (Comet ML)
- LangSmith
Questions or feedback? Open an issue or reach out!
Ready to play? Deploy now and face the Villain AI! ๐ฎ๐ค
See DEPLOYMENT_GUIDE.md to get started!