Spaces:
Sleeping
Sleeping
File size: 5,721 Bytes
2eef9ea 8e6535c 2eef9ea 8e6535c 2eef9ea 8e6535c 2eef9ea 8e6535c 2eef9ea 8e6535c 2eef9ea 8e6535c 2eef9ea 8e6535c 2eef9ea 8e6535c 2eef9ea 8e6535c 2eef9ea | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | ---
title: Multi-Agent System
emoji: π€
colorFrom: purple
colorTo: blue
sdk: docker
pinned: false
app_port: 7860
---
# Autonomous Multi-Agent Workflow System
[](https://www.python.org/)
[](https://github.com/langchain-ai/langgraph)
[](https://fastapi.tiangolo.com)
[](https://opensource.org/licenses/MIT)
> A production-grade LangGraph multi-agent system β Planner, Executor, Critic, and Memory agents β that collaborate to decompose and execute complex tasks with state management, failure recovery, and persistent memory.
## Live Demo
Deployed on [Hugging Face Spaces](https://huggingface.co/spaces) via Docker.
## Architecture
```
User Task
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β LangGraph Workflow β
β β
β Memory Retrieve β Planner β Executor (loop) β
β β β β
β replan all done β
β β βΌ β
β Critic β Executor β
β β β
β approved β
β βΌ β
β Memory Store β END β
βββββββββββββββββββββββββββββββββββββββββββββββββββ
```
| Agent | Role |
|---|---|
| **Memory Retrieve** | Pull relevant past context from SQLite |
| **Planner** | Decompose task into 2β4 ordered steps |
| **Executor** | Run each step using tools (web search, code, etc.) |
| **Critic** | Score output 0β100, trigger replan if score < 60 |
| **Memory Store** | Persist learnings for future tasks |
## Tools
| Tool | Description |
|---|---|
| `web_search` | Google via Serper API, fallback to DuckDuckGo |
| `fetch_url` | Scrape and clean URL content |
| `calculate` | Safe math expression evaluator |
| `run_python` | Sandboxed Python execution (pandas, numpy, matplotlib supported) |
| `write_file` / `read_file` | In-memory file store |
| `get_datetime` | Current UTC datetime |
| `synthesize` | Final answer generation |
## Stack
- **Orchestration**: LangGraph 0.2 (stateful graph with conditional routing)
- **LLM**: Groq (Llama 3.3 70B) β free tier, 14,400 req/day Β· also supports Gemini
- **Search**: Serper (Google Search API) with DuckDuckGo fallback
- **API**: FastAPI + Server-Sent Events for real-time streaming
- **Memory**: SQLite (long-term) + Redis optional (short-term cache)
- **Frontend**: Vanilla JS dashboard with live agent graph visualization
## Local Setup
```bash
git clone https://github.com/jatingyass/multi-agent-system
cd multi-agent-system
python -m venv .venv
.venv\Scripts\activate # Windows
# source .venv/bin/activate # macOS/Linux
pip install -r requirements.txt
# Create .env with your API keys (see .env.example)
cp .env.example .env
python run.py
# Open http://localhost:8000
```
### Required API Keys
| Key | Where to get | Free tier |
|---|---|---|
| `GROQ_API_KEY` | [console.groq.com](https://console.groq.com) | 14,400 req/day |
| `SERPER_API_KEY` | [serper.dev](https://serper.dev) | 2,500 searches/month |
| `GOOGLE_API_KEY` | [aistudio.google.com/apikey](https://aistudio.google.com/apikey) | Optional (Gemini fallback) |
## Hugging Face Deployment
1. Create a new Space β **Docker** SDK
2. Add secrets in **Settings β Variables and secrets**:
- `GROQ_API_KEY`
- `SERPER_API_KEY`
- `GOOGLE_API_KEY` (optional)
3. Push this repo β the `Dockerfile` handles the rest (port 7860, production mode)
> Redis is optional. The app runs fully without it (short-term memory disabled).
## Switching LLM Provider
Change `llm_provider` in `backend/core/config.py`:
```python
llm_provider: str = "groq" # Llama 3.3 70B via Groq
llm_provider: str = "gemini" # Gemini 2.5 Flash
```
No other code changes needed.
## API
```bash
# Submit a task (streaming)
curl -X POST http://localhost:8000/api/tasks/stream \
-H "Content-Type: application/json" \
-d '{"task": "Research quantum computing breakthroughs in 2024"}'
# Submit a task (batch)
curl -X POST http://localhost:8000/api/tasks \
-H "Content-Type: application/json" \
-d '{"task": "Calculate compound interest on $10,000 at 7% for 20 years"}'
# Health check
curl http://localhost:8000/api/health
```
Interactive docs: `http://localhost:8000/docs`
## Key Design Decisions
**Why LangGraph?** Explicit graph control β every routing decision is visible and testable, unlike chain-based frameworks.
**Why a separate Critic?** Self-evaluation is biased. A dedicated evaluator LLM catches significantly more errors and provides structured scoring.
**Why two-tier memory?** Redis for sub-millisecond working memory during task execution; SQLite for persistent episodic and semantic memory across sessions.
**Why Groq?** 14,400 free requests/day vs Gemini's 20/day on the free tier β orders of magnitude more headroom for development and demos.
**Failure recovery:** Critic-triggered replanning for low-quality outputs; hard iteration cap (3) prevents infinite loops; Serper β DuckDuckGo fallback ensures web search always has a path.
## License
MIT
|