A multi-agent legal strategy system built for the MongoDB Agentic Orchestration and Collaboration Hackathon 2026. This application demonstrates Statement 2: Multi-Agent Collaboration using MongoDB Atlas as the coordination backbone.
Statement Two: Multi-Agent Collaboration
Develop a multi-agent system in which specialized agents explore, assign tasks, and communicate with one another, using MongoDB to organize and oversee contexts. How do agents convey their skills, identify suitable peers for a sub-task, share context effectively within token limits, and perform intricate tasks resulting from successful collaborations?
Agent names inspired by the TV show "Suits"
- Overview
- Key Features
- Tech Stack
- Project Structure
- Setup Instructions
- Environment Variables
- MongoDB Configuration
- How It Works
- API Endpoints
- Solution Architecture
- Troubleshooting
Legal Strategy Council employs four specialized AI agents that collaborate to analyze legal cases and develop winning strategies:
| Agent | Role | Nickname |
|---|---|---|
| Harvey | Lead Trial Strategist | "The Closer" |
| Louis | Precedent & Research Expert | "The Savant" |
| Tanner | Adversarial Counsel | "The Destroyer" |
| Jessica | Managing Partner / Moderator | "The Mediator" |
- Multi-round deliberation: Harvey and Tanner debate the strategy before Jessica synthesizes
- Step-level tracing: Every reasoning step is persisted to MongoDB for auditability
- Inter-agent messaging: Agents communicate through MongoDB for coordination
- Real-time updates: Watch agents analyze in real-time via Server-Sent Events (SSE)
- PDF extraction: Upload case documents and automatically extract case information
- Conflict detection: Automatically identifies disagreements between agents
- Modern UI: Beautiful, responsive interface with dark mode support
- Backend: Python 3.11+ with FastAPI
- Frontend: React 18+ with Vite and Tailwind CSS v4
- Database: MongoDB Atlas (or local MongoDB)
- LLM: Groq API (configurable - supports multiple models)
- Real-time Updates: Server-Sent Events (SSE)
- PDF Processing: PyPDF2 for document extraction
- UI Components: shadcn/ui (Radix UI primitives)
legal-multi-agents/
├── backend/
│ ├── main.py # FastAPI application and endpoints
│ ├── config.py # Configuration settings and environment variables
│ ├── database.py # MongoDB connection and collection management
│ ├── requirements.txt # Python dependencies
│ ├── models/
│ │ └── schemas.py # Pydantic models for data validation
│ ├── agents/
│ │ ├── base_agent.py # Base agent class with LLM integration
│ │ ├── harvey.py # Harvey - Lead Trial Strategist
│ │ ├── louis.py # Louis - Precedent Expert
│ │ ├── tanner.py # Tanner - Adversarial Counsel
│ │ └── jessica.py # Jessica - Managing Partner
│ └── services/
│ ├── orchestrator.py # Multi-round workflow orchestration
│ ├── conflict_detector.py # Conflict detection service
│ ├── mongo_utils.py # MongoDB coordination utilities
│ └── langgraph_wrapper.py # Step-level tracing for auditability
├── frontend/
│ ├── package.json # Node.js dependencies
│ ├── vite.config.js # Vite configuration with proxy
│ ├── tailwind.config.js # Tailwind CSS configuration
│ └── src/
│ ├── App.jsx # Main application component
│ ├── main.jsx # React entry point
│ ├── index.css # Global styles and theme
│ ├── lib/
│ │ └── utils.js # Utility functions (class merging)
│ └── components/
│ ├── CaseInput.jsx # Case input form with PDF upload
│ ├── AgentPanel.jsx # Individual agent display card
│ ├── DebateView.jsx # Agent grid view
│ ├── ConflictView.jsx # Conflict display component
│ ├── FinalStrategy.jsx # Final strategy display
│ ├── LandingPage.jsx # Landing page with hero, features, FAQ
│ └── ui/ # Reusable UI components (shadcn/ui)
├── .env.example # Environment variables template
├── .gitignore # Git ignore rules
└── README.md # This file
- Python 3.11 or higher - Download Python
- Node.js 18 or higher - Download Node.js
- MongoDB Atlas account (free tier available) - Sign up
- Groq API key (free tier available) - Get API key
git clone <repository-url>
cd legal-multi-agentsCreate a .env file in the backend directory (or root directory) with the following variables:
GROQ_API_KEY=your_groq_api_key_here
MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/?retryWrites=true&w=majority
DATABASE_NAME=legal_war_roomImportant: Replace username and password in the MongoDB URI with your actual MongoDB Atlas credentials.
cd backend
# Create virtual environment (recommended)
python -m venv venv
# Activate virtual environment
# On Windows:
venv\Scripts\activate
# On macOS/Linux:
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt
# Start the backend server
uvicorn main:app --reload --port 8000The backend will start on http://localhost:8000 (or http://127.0.0.1:8000).
Open a new terminal window:
cd frontend
# Install dependencies
npm install
# Start the development server
npm run devThe frontend will start on http://localhost:5173.
- Frontend: http://localhost:5173
- Backend API: http://localhost:8000
- API Documentation: http://localhost:8000/docs (Swagger UI)
The following environment variables are required:
| Variable | Description | Example |
|---|---|---|
GROQ_API_KEY |
Your Groq API key | gsk_xxxxxxxxxxxxx |
MONGODB_URI |
MongoDB connection string | mongodb+srv://user:pass@cluster.mongodb.net/... |
DATABASE_NAME |
MongoDB database name (optional, defaults to legal_war_room) |
legal_war_room |
- Create a MongoDB Atlas account: https://www.mongodb.com/cloud/atlas/register
- Create a new cluster (free tier M0 is sufficient)
- Create a database user:
- Go to "Database Access" → "Add New Database User"
- Choose "Password" authentication
- Create username and password (save these!)
- Set privileges to "Atlas admin" or "Read and write to any database"
- Whitelist your IP address:
- Go to "Network Access" → "Add IP Address"
- Click "Allow Access from Anywhere" (for development) or add your specific IP
- Get your connection string:
- Go to "Database" → "Connect" → "Connect your application"
- Copy the connection string
- Replace
<password>with your database user password - Replace
<username>with your database username
If you prefer to run MongoDB locally:
- Install MongoDB: https://www.mongodb.com/try/download/community
- Start MongoDB service:
# Windows net start MongoDB # macOS/Linux sudo systemctl start mongod
- Use local connection string:
MONGODB_URI=mongodb://localhost:27017/
The application automatically creates the following collections:
| Collection | Purpose |
|---|---|
cases |
Stores case facts and metadata |
arguments |
Stores Harvey and Louis arguments |
counterarguments |
Stores Tanner's attacks |
conflicts |
Stores detected disagreements between agents |
strategies |
Stores Jessica's final synthesized strategies |
agent_runs |
Tracks agent execution for auditability |
reasoning_steps |
Stores step-by-step agent thinking |
agent_messages |
Stores inter-agent communication |
┌─────────────────────────────────────────────────────────────────┐
│ Case Input │
│ (User uploads PDF or fills form manually) │
└─────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ Step 1: Harvey develops initial strategy │
│ - Analyzes case facts │
│ - Develops primary legal strategy │
│ - Writes to arguments collection │
└─────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ Step 2: Louis researches precedents │
│ - Finds relevant case law │
│ - Identifies legal doctrines │
│ - Writes to arguments collection │
└─────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ Step 3: Multi-Round Deliberation (2 rounds default) │
│ ┌─────────────────┐ ┌─────────────────┐ │
│ │ Round 1: │ │ Round 1: │ │
│ │ Tanner attacks │───▶│ Harvey rebuts │ │
│ │ (counterargs) │ │ (revised args) │ │
│ └─────────────────┘ └─────────────────┘ │
│ │ │ │
│ ▼ ▼ │
│ ┌─────────────────┐ ┌─────────────────┐ │
│ │ Round 2: │ │ (Final attack) │ │
│ │ Tanner attacks │───▶│ │ │
│ │ again │ │ │ │
│ └─────────────────┘ └─────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ Step 4: Conflict Detection │
│ - Analyzes all arguments and counterarguments │
│ - Identifies disagreements between agents │
│ - Writes to conflicts collection │
└─────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ Step 5: Jessica synthesizes final strategy │
│ - Reads all arguments, counterarguments, and conflicts │
│ - Resolves conflicts with clear reasoning │
│ - Produces unified, actionable strategy │
│ - Writes to strategies collection │
└─────────────────────────────────────────────────────────────────┘
The application uses MongoDB as the coordination layer for multi-agent collaboration:
- Immediate persistence: Each agent writes to MongoDB immediately upon completion
- Cross-agent reading: Agents read from MongoDB to access previous outputs
- Step-level tracing: Every reasoning step is persisted to
reasoning_stepsfor full auditability - Inter-agent messaging: Agents communicate through
agent_messagescollection - Audit trail: Complete history for replay, debugging, and analysis
The application uses Server-Sent Events (SSE) to push updates to the frontend:
| Event | Description |
|---|---|
agent_started |
When an agent begins analysis |
agent_completed |
When an agent finishes with output |
deliberation_round_started |
When a Harvey/Tanner round begins |
deliberation_round_completed |
When a round finishes |
detecting_conflicts |
When conflict detection starts |
conflict_detected |
When conflicts are identified |
strategy_ready |
When final strategy is available |
error |
When an error occurs |
| Endpoint | Method | Description |
|---|---|---|
/ |
GET | API health check |
/health |
GET | Health check endpoint |
/api/cases |
POST | Create a new case and start analysis |
/api/cases/process-documents |
POST | Extract case information from PDF files |
/api/cases/{case_id}/stream |
GET | SSE stream for real-time updates |
/api/cases/{case_id} |
GET | Get full case with all data |
/api/cases/{case_id}/arguments |
GET | Get all arguments for a case |
/api/cases/{case_id}/conflicts |
GET | Get all conflicts for a case |
/api/cases/{case_id}/strategy |
GET | Get final strategy for a case |
Build a multi-agent legal strategy system where multiple AI agents collaborate to analyze legal cases and develop winning strategies, using MongoDB as the coordination backbone.
- Multi-Agent Architecture: Four specialized agents (Harvey, Louis, Tanner, Jessica) each with distinct roles
- MongoDB Coordination: All agent outputs are stored in MongoDB, enabling agents to read each other's work
- Multi-Round Deliberation: Harvey and Tanner engage in multiple rounds of debate before final synthesis
- Step-Level Tracing: Every reasoning step is persisted for full auditability
- Real-Time Updates: Server-Sent Events provide live updates to the frontend
- PDF Extraction: Automatic extraction of case information from uploaded PDFs
-
MongoDB as Coordination Layer: Instead of direct agent-to-agent communication, agents coordinate through MongoDB collections. This provides:
- Persistence and auditability
- Decoupling of agents
- Easy scaling and debugging
- Complete history of all interactions
-
Multi-Round Deliberation: Harvey and Tanner engage in multiple rounds (default: 2) to ensure thorough debate before final synthesis
-
Step-Level Tracing: Adapted from LegalServer-main, every agent reasoning step is persisted to enable full auditability and debugging
-
Async Processing: Agents run asynchronously using thread pooling to avoid blocking the API
-
Error Handling: Comprehensive error handling with retry logic for LLM calls and graceful degradation
- Circular Import Issues: Resolved by lazy-loading agents inside the Orchestrator's
__init__method - MongoDB Index Conflicts: Implemented robust index creation that handles conflicts by dropping and recreating indexes
- IPv6 vs IPv4 Resolution: Fixed frontend proxy to use
127.0.0.1instead oflocalhoston Windows - SSE Connection Reliability: Added polling fallback mechanism to ensure frontend always has latest data
- PDF Extraction: Implemented LLM-based extraction with regex fallback for robust field extraction
Problem: ImportError: cannot import name 'HarveyAgent'
- Solution: This is a circular import issue. Ensure agents are imported inside
Orchestrator.__init__, not at module level.
Problem: IndexKeySpecsConflict errors
- Solution: The application automatically handles this by dropping and recreating indexes. If issues persist, manually drop indexes in MongoDB.
Problem: Connection refused errors
- Solution:
- Ensure MongoDB Atlas IP whitelist includes your IP address
- Verify MongoDB URI has correct username and password
- Check that MongoDB service is running (if using local MongoDB)
Problem: LLM API errors
- Solution:
- Verify API key is correct in
.envfile - Check API rate limits (use smaller model if hitting limits)
- Ensure internet connection is stable
- Verify API key is correct in
Problem: ECONNREFUSED ::1:8000
- Solution: The
vite.config.jsis configured to use127.0.0.1instead oflocalhost. Restart the Vite dev server after changes.
Problem: Agents not updating
- Solution:
- Check browser console for SSE connection errors
- Verify backend is running on port 8000
- Check network tab for failed API calls
Problem: PDF extraction not working
- Solution:
- Ensure PDF file is not corrupted
- Check backend logs for extraction errors
- Verify PyPDF2 is installed:
pip install PyPDF2
Problem: Cannot connect to MongoDB Atlas
- Solution:
- Verify connection string format:
mongodb+srv://username:password@cluster.mongodb.net/... - Check IP whitelist includes your current IP
- Verify database user has correct permissions
- Test connection using MongoDB Compass
- Verify connection string format:
Problem: Collections not created
- Solution: The application creates collections automatically on startup. Check backend logs for initialization messages.
- Agent coordination patterns adapted from LegalServer-main
- Agent names inspired by the TV show Suits
- Built with Groq LLM and MongoDB Atlas
- UI components from shadcn/ui
MIT License - Built for MongoDB Agentic Orchestration and Collaboration Hackathon 2026