File size: 6,214 Bytes
fd06b5a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
245
246
247
248
249
250
251
252
253
254
255
256
# πŸš€ Quick Start Guide - Agentic AI Backend

## Prerequisites


## Step 1: Verify Installation βœ…

Dependencies are already installed. Verify with:
```powershell
python -c "import chromadb, sentence_transformers; print('βœ… Vector Store packages installed')"
```


## Step 2: Configure Environment πŸ”§

### Option 1: GitHub Models (Recommended) ⭐

**Free, fast, and reliable!**

1. **Get a GitHub token:** https://github.com/settings/tokens
2. **Edit `.env`:**
```powershell
Copy-Item .env.template .env
notepad .env
```

3. **Add your tokens:**
```bash
GITHUB_TOKEN=ghp_your_github_token_here
OPENWEATHERMAP_API_KEY=your_weather_api_key_here
```

**See detailed setup:** [GITHUB_MODELS_SETUP.md](GITHUB_MODELS_SETUP.md)

### Option 2: Local with Ollama

If you prefer running locally:

1. **Install a capable Ollama model:**
```powershell
ollama pull llama3.2  # Better than qwen3:0.6b
```

2. **Configure `.env`:**
```bash
OLLAMA_BASE_URL=http://localhost:11434
OLLAMA_MODEL=llama3.2
OPENWEATHERMAP_API_KEY=your_weather_api_key_here
```

**Note:** GitHub Models recommended for better reliability and tool calling.


## Step 3: Initialize Database πŸ’Ύ

```powershell
python seed_data.py
```

This creates:

Expected output:
```
Database initialized
Sample meetings created successfully
```


## Step 4: Run Tests πŸ§ͺ

```powershell
python test_agents.py
```

This runs 6 comprehensive tests:
1. βœ… Weather Agent - Current weather
2. βœ… Meeting Agent - Weather-conditional scheduling
3. βœ… SQL Agent - Database queries
4. βœ… Document RAG - High confidence retrieval
5. βœ… Web Fallback - Low confidence web search
6. βœ… Specific Retrieval - Precise information extraction

**First run will download the embedding model (~80MB) - this is normal!**


## Step 5: Start the API Server 🌐

```powershell
python main.py
```

Server starts at: **http://127.0.0.1:8000**

API docs available at: **http://127.0.0.1:8000/docs**


## Step 6: Test API Endpoints πŸ“‘

### Test 1: Weather Query
```powershell
$body = @{
    query = "What's the weather in Paris today?"
} | ConvertTo-Json

Invoke-RestMethod -Method Post -Uri "http://127.0.0.1:8000/chat" `
    -ContentType "application/json" -Body $body
```

### Test 2: Upload Document
```powershell
$filePath = "C:\path\to\your\document.pdf"
curl -X POST "http://127.0.0.1:8000/upload" -F "file=@$filePath"
```

Response will include `file_path` - use it in the next request.

### Test 3: RAG Query
```powershell
$body = @{
    query = "What does the document say about remote work?"
    file_path = "D:\python_workspace\multi-agent\uploads\uuid.pdf"
} | ConvertTo-Json

Invoke-RestMethod -Method Post -Uri "http://127.0.0.1:8000/chat" `
    -ContentType "application/json" -Body $body
```

### Test 4: Meeting Scheduling
```powershell
$body = @{
    query = "Schedule a team meeting tomorrow at 3 PM in London if weather is good. Include Alice and Bob."
} | ConvertTo-Json

Invoke-RestMethod -Method Post -Uri "http://127.0.0.1:8000/chat" `
    -ContentType "application/json" -Body $body
```

### Test 5: SQL Query
```powershell
$body = @{
    query = "Show me all meetings scheduled for this week"
} | ConvertTo-Json

Invoke-RestMethod -Method Post -Uri "http://127.0.0.1:8000/chat" `
    -ContentType "application/json" -Body $body
```


## Expected Behavior 🎯

### Weather Agent

### Document RAG Agent

### Meeting Agent

### SQL Agent


## Troubleshooting πŸ”§

### Issue: "No valid LLM configured"
**Solution:** Ensure Ollama is running at http://localhost:11434
```powershell
# Check if Ollama is running
Invoke-WebRequest http://localhost:11434
```

### Issue: "Weather API key not configured"
**Solution:** Add your API key to `.env`:
```bash
OPENWEATHERMAP_API_KEY=your_key_here
```

### Issue: "Document ingestion failed"
**Solution:** Check file format (PDF/TXT/MD/DOCX) and size (<10MB)

### Issue: Slow first RAG query
**Expected:** First run downloads sentence-transformers model (~80MB)
Subsequent queries will be fast.

### Issue: Import errors in IDE
**Normal:** VSCode may show import warnings until packages are fully indexed. Code will run fine.


## Understanding the RAG Workflow πŸ“š

```
User uploads document.pdf
         ↓
1. Parse with Docling
         ↓
2. Chunk into 500-char pieces (50-char overlap)
         ↓
3. Generate embeddings with sentence-transformers
         ↓
4. Store in ChromaDB (./chroma_db/)
         ↓
User asks: "What is the policy?"
         ↓
5. Search vector store for similar chunks
         ↓
6. Check similarity score
         ↓
   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚ Score β‰₯ 0.7 β”‚ Score < 0.7  β”‚
   β”‚ (confident) β”‚ (uncertain)  β”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚              β”‚
         ↓              ↓
   Return doc      Search web
   answer          + combine
                   results
```


## File Structure πŸ“

```
multi-agent/
β”œβ”€β”€ main.py                 # FastAPI server
β”œβ”€β”€ agents.py              # LangGraph agents
β”œβ”€β”€ tools.py               # Agent tools
β”œβ”€β”€ vector_store.py        # ChromaDB manager (NEW)
β”œβ”€β”€ database.py            # SQLite config
β”œβ”€β”€ models.py              # SQLAlchemy models
β”œβ”€β”€ test_agents.py         # Test suite
β”œβ”€β”€ seed_data.py           # DB initialization
β”œβ”€β”€ .env                   # Your configuration
β”œβ”€β”€ .env.template          # Configuration template
β”œβ”€β”€ database.db            # SQLite database
β”œβ”€β”€ chroma_db/             # Vector store (auto-created)
β”œβ”€β”€ uploads/               # Uploaded documents
└── IMPLEMENTATION_COMPLETE.md  # Full documentation
```


## Next Steps 🎯

1. **Explore the API:** Visit http://127.0.0.1:8000/docs
2. **Try different queries:** Test edge cases and complex scenarios
3. **Upload your documents:** Try PDFs, policies, resumes
4. **Check vector store:** Inspect `./chroma_db/` directory
5. **Review logs:** Monitor agent decisions and tool calls


## Performance Tips ⚑



## Support πŸ“ž



**You're all set! πŸŽ‰ Start making requests to your AI backend!**