File size: 6,953 Bytes
49ae209
da4ce3a
cfe0485
49ae209
 
 
 
 
cfe0485
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6cee2e2
cfe0485
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6cee2e2
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
---
title: LangGraph Multi-Agent Orchestrator
emoji: 🧭
colorFrom: red
colorTo: red
sdk: docker
app_port: 8501
tags:
  - streamlit
  - langgraph
  - langchain
  - groq
  - sqlite
  - neo4j
short_description: A multi-agent chat app powered by LangGraph.
---

# 🧭 LangGraph Multi-Agent Orchestrator (Streamlit)

A **multi-agent chat orchestrator** built with **LangGraph + LangChain**, wrapped in a **Streamlit** UI.

It routes each user message to the best specialist:

- **SQL Agent** → relational questions over **SQLite**
- **Graph Agent** → relationship questions over **Neo4j** (Cypher)
- **Tools Agent****Web / Wikipedia / arXiv / Calculator** assisted answers
- **General** → normal LLM chat/explanations

---

## ✨ What you can do

### 1) Router Chat (auto orchestration)
A single chat experience where a router decides which agent to run each turn:
- SQL / Graph / Tools / General
- Handles follow-up questions by rewriting them into standalone queries

### 2) SQL Agent (SQLite analytics)
Ask questions like:
- “Top 10 students by average score in 2025-Fall”
- “Which course has the lowest average score?”
- “Who has attendance below 70%?”

### 3) Graph Agent (Neo4j Cypher Q&A)
Ask relationship-heavy questions like:
- “Movies that share actors with The Matrix”
- “Shortest path between Tom Hanks and Tom Cruise”
- “Actors who worked with both X and Y”

> Graph Agent is optional — it only works if Neo4j credentials are configured.

### 4) Tools Agent (Web + Wikipedia + arXiv + Calculator)
Useful for open-world questions outside your databases:
- quick research + citations from tools (inside the agent)
- safe arithmetic calculator tool for quick computations

---

## 🧱 Architecture (high-level)

```

User → Router (LangGraph) → one route:
├─ SQL Agent   (SQLite, read-only)
├─ Graph Agent (Neo4j → Cypher → answer grounded in results)
├─ Tools Agent (DuckDuckGo + Wikipedia + arXiv + Calculator)
└─ General     (LLM-only)

```

## 🚀 Run locally (Python)

### 1) Install
```bash
git clone https://github.com/sparklerz/LangGraph-Multi-Agent-Orchestrator
cd LangGraph-Multi-Agent-Orchestrator

pip install -r requirements.txt
````

### 2) Configure environment variables

Create a `.env` file:

```bash
# Required
GROQ_API_KEY="YOUR_GROQ_KEY"

# Recommended (the repo includes school.db)
SQLITE_PATH="school.db"

# Optional model override (Groq)
LLM_MODEL="meta-llama/llama-4-maverick-17b-128e-instruct"

# Optional: enable Neo4j Graph Agent
NEO4J_URI="neo4j+s://97329836.databases.neo4j.io"
NEO4J_USERNAME="neo4j"
NEO4J_PASSWORD="password"

# Optional: tool config
WIKI_DOC_CHARS="2000"

# Optional: debugging (shows more internal steps)
DEBUG="1"
```

### 3) Run

```bash
streamlit run app.py
```

---

## 🗄️ SQLite database (SQL Agent)

This repo ships with a demo SQLite DB: **`school.db`**.

If you see “DB not found” errors:

* ensure `school.db` exists in the repo root
* set `SQLITE_PATH=school.db`

### Optional: regenerate / reseed the DB

```bash
python sqlite.py
```

> `sqlite.py` supports env overrides like `SQLITE_DB`, `NUM_STUDENTS`, etc.

---

## 🕸️ Neo4j setup (Graph Agent)

Graph Agent is optional. To enable it, set:

* `NEO4J_URI`
* `NEO4J_USERNAME`
* `NEO4J_PASSWORD`

**Tip:** Neo4j’s “Movies” dataset is perfect for testing locally.

If Neo4j is not configured, Graph Agent calls will fail gracefully (and the rest of the app still works).

---
## Hugging Face Spaces (Docker) deployment

This repo is configured for **Docker Spaces** using the .github/workflows/main.yml.

### 1) Create the Space
1. Create a new Space on Hugging Face
2. Choose **SDK → Docker**
3. Push / sync this repository to the Space

### 2) Add required Secret
In your Space: **Settings → Variables and secrets**
- Add **Secret**: `GROQ_API_KEY` (required)

### 3) Add Variables (recommended)

Add **Variables**:

* `SQLITE_PATH=school.db`
* Optional: `LLM_MODEL=meta-llama/llama-4-maverick-17b-128e-instruct`
* Optional: `WIKI_DOC_CHARS=2000`
* Optional: `DEBUG=1`

### 4) Neo4j on Spaces (optional)

If you want Graph Agent on Spaces, your Neo4j must be reachable from the public internet.
Add these as **Secrets**:

* `NEO4J_URI`
* `NEO4J_USERNAME`
* `NEO4J_PASSWORD`

> If you don’t set Neo4j creds, just avoid Graph-only questions (Router will still work for SQL/Tools/General).

---

## ⚙️ Configuration reference

| Variable         | Default                                         | Purpose                                              |
| ---------------- | ----------------------------------------------- | ---------------------------------------------------- |
| `GROQ_API_KEY`   | (none)                                          | **Required**. Enables Groq LLM calls                 |
| `LLM_MODEL`      | `meta-llama/llama-4-maverick-17b-128e-instruct` | Default Groq model                                   |
| `SQLITE_PATH`    | `student.db`                                    | Path to SQLite DB (set to `school.db` for this repo) |
| `NEO4J_URI`      | (empty)                                         | Neo4j connection URI                                 |
| `NEO4J_USERNAME` | (empty)                                         | Neo4j username                                       |
| `NEO4J_PASSWORD` | (empty)                                         | Neo4j password                                       |
| `WIKI_DOC_CHARS` | `2000`                                          | Wikipedia doc truncation size for tools              |
| `DEBUG`          | `0`                                             | Show more intermediate/debug info                    |

---

## 🧪 Example prompts to try

### Router Chat

* “Show the top 10 students by average score in 2025-Fall”
* “Now only Computer Science students”
* “Explain what LangGraph is, in simple terms”
* “Summarize the latest research on graph RAG” (tools)

### SQL Agent

* “List the tables”
* “Attendance below 70% in 2025-Fall”
* “Which department has the highest average course score?”

### Graph Agent

* “Find movies that share at least 2 actors with The Matrix”
* “Shortest connection between Tom Hanks and Tom Cruise”

### Tools Agent

* “What’s the difference between BM25 and dense retrieval?”
* “Find 3 papers on multi-agent orchestration and summarize”
* “(12*(3+4))/2”

---

## 🧯 Troubleshooting

* **Missing `GROQ_API_KEY`**
  Set it in `.env` (local) or Space **Secrets** (HF).

* **SQLite DB not found**
  Ensure the file exists in the repo root and `SQLITE_PATH` matches (recommended: `school.db`).

* **Neo4j errors**
  Confirm Neo4j is running and reachable, credentials are correct, and the dataset exists.

* **Tools Agent can’t access web**
  Some hosted environments restrict outbound requests. If web tools fail, try Router/SQL/General flows.

---

## 📄 License

Apache-2.0