riazmo commited on
Commit
34a4f9e
Β·
verified Β·
1 Parent(s): 7ddd45f

Upload πŸ›οΈ Multi-Model Hierarchical Research System.md

Browse files
πŸ›οΈ Multi-Model Hierarchical Research System.md ADDED
@@ -0,0 +1,460 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # πŸ›οΈ Multi-Model Hierarchical Research System
2
+
3
+ A sophisticated **hierarchical multi-agent research system** with real-time progress tracking and live dashboard. Powered by multiple AI models (Qwen, Llama, Mistral) for comprehensive market research, competitive analysis, and strategic insights.
4
+
5
+ ## ✨ Features
6
+
7
+ ### 🎯 Hierarchical Multi-Agent Architecture
8
+ ```
9
+ Supervisor (Strategy)
10
+ ↓
11
+ β”œβ”€β†’ Researcher Agent πŸ† (Industry Leaders)
12
+ β”œβ”€β†’ Analyzer Agent ⭐ (Best Practices)
13
+ └─→ Critic Agent πŸ” (Quality Review)
14
+ ↓
15
+ Synthesizer Agent πŸ’‘ (Recommendations)
16
+ ```
17
+
18
+ ### πŸ“Š Real-Time Progress Tracking
19
+ - **Live Dashboard** - Watch research progress in real-time
20
+ - **Phase-by-phase updates** - See each agent's status
21
+ - **Execution metrics** - Track timing and performance
22
+ - **Error handling** - Graceful degradation with retry logic
23
+
24
+ ### πŸ€– Multi-Model Support
25
+ - **Qwen 2.5 7B** - Fast & efficient analysis
26
+ - **Qwen 2.5 72B** - Most capable Qwen model
27
+ - **Meta Llama 3.1 70B** - Strong reasoning capabilities
28
+ - **Mistral Large** - Excellent analysis and synthesis
29
+
30
+ ### πŸ” Comprehensive Research
31
+ - **Industry Leaders** - Top 5 companies setting standards
32
+ - **Best Practices** - Proven methods and innovations
33
+ - **Quality Review** - Independent assessment and validation
34
+ - **Strategic Recommendations** - Actionable roadmap
35
+
36
+ ### πŸ“ˆ Rich Output
37
+ - Executive summaries with infographics
38
+ - Execution timelines and performance metrics
39
+ - Model assignment verification
40
+ - Search history and metadata
41
+
42
+ ## πŸš€ Quick Start
43
+
44
+ ### 1. **Get HuggingFace API Token**
45
+
46
+ Visit [HuggingFace Settings](https://huggingface.co/settings/tokens):
47
+ 1. Click "New token"
48
+ 2. Select "Read" permission
49
+ 3. Copy the token (starts with `hf_...`)
50
+
51
+ ### 2. **Set Environment Variable**
52
+
53
+ ```bash
54
+ # On Linux/Mac
55
+ export HF_TOKEN=hf_your_token_here
56
+
57
+ # On Windows (PowerShell)
58
+ $env:HF_TOKEN="hf_your_token_here"
59
+
60
+ # Or create .env file
61
+ echo "HF_TOKEN=hf_your_token_here" > .env
62
+ ```
63
+
64
+ ### 3. **Install Dependencies**
65
+
66
+ ```bash
67
+ pip install -r requirements.txt
68
+ ```
69
+
70
+ ### 4. **Run the Application**
71
+
72
+ ```bash
73
+ python app.py
74
+ ```
75
+
76
+ The application will start on `http://localhost:7860`
77
+
78
+ ## πŸ“‹ Usage Guide
79
+
80
+ ### Basic Research
81
+
82
+ 1. **Enter Research Topic**
83
+ - Example: "AI project management tools"
84
+ - Example: "Sustainable fashion brands"
85
+ - Example: "Electric vehicle charging infrastructure"
86
+
87
+ 2. **Click "Start Research"**
88
+ - Watch the Live Dashboard tab for real-time progress
89
+ - Each agent will execute in sequence
90
+
91
+ 3. **Review Results**
92
+ - **Summary**: Executive overview and metadata
93
+ - **Industry Leaders**: Top 5 companies/products
94
+ - **Best Practices**: Proven strategies and innovations
95
+ - **Quality Review**: Independent assessment
96
+ - **Recommendations**: Strategic action plan
97
+
98
+ ### Advanced: Configure Models
99
+
100
+ 1. Open "Configure AI Models" accordion
101
+ 2. Select different models for each phase:
102
+ - Query Understanding
103
+ - Industry Leaders Research
104
+ - Best Practices Analysis
105
+ - Quality Review
106
+ - Recommendations Generation
107
+
108
+ 3. Click "Start Research" with custom configuration
109
+
110
+ ## πŸ“Š Understanding the Output
111
+
112
+ ### Live Dashboard
113
+ Shows real-time progress as research happens:
114
+ ```
115
+ πŸš€ Research started!
116
+ πŸ“Œ Topic: AI project management tools
117
+ πŸ€– Models configured: 4 unique models
118
+
119
+ πŸ† PHASE 1: RESEARCHER AGENT - Industry Leaders
120
+ Model: Qwen/Qwen2.5-72B-Instruct
121
+ Status: ⏳ Running...
122
+ Status: βœ… Complete (24.5s)
123
+
124
+ ⭐ PHASE 2: ANALYZER AGENT - Best Practices
125
+ Model: Qwen/Qwen2.5-72B-Instruct
126
+ Status: ⏳ Running...
127
+ Status: βœ… Complete (25.2s)
128
+
129
+ [... more phases ...]
130
+
131
+ πŸ“Š RESEARCH COMPLETE!
132
+ πŸ“ˆ EXECUTION SUMMARY:
133
+ πŸ† Researcher: 24.5s [β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘]
134
+ ⭐ Analyzer: 25.2s [β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘]
135
+ πŸ” Critic: 14.8s [β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘]
136
+ πŸ’‘ Synthesizer: 19.5s [β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘]
137
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
138
+ πŸ“ˆ TOTAL TIME: 84.0s [β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘]
139
+ ```
140
+
141
+ ### Summary Tab
142
+ - Research overview with hierarchy diagram
143
+ - Agent execution status and timing
144
+ - Performance metrics
145
+ - Model assignment verification
146
+ - Research metadata
147
+
148
+ ### Industry Leaders Tab
149
+ - Top 5 companies/products
150
+ - Market positioning
151
+ - Key strengths
152
+ - Notable features
153
+ - Market metrics
154
+
155
+ ### Best Practices Tab
156
+ - Industry standards and frameworks
157
+ - Success stories and case studies
158
+ - Innovation patterns
159
+ - Implementation guidelines
160
+ - Key takeaways
161
+
162
+ ### Quality Review Tab
163
+ - Research completeness assessment
164
+ - Source quality evaluation
165
+ - Recency and relevance check
166
+ - Clarity and usefulness rating
167
+ - Improvement recommendations
168
+ - Overall quality scores
169
+
170
+ ### Recommendations Tab
171
+ - Executive summary
172
+ - Immediate actions (0-30 days)
173
+ - Short-term strategy (1-3 months)
174
+ - Long-term vision (3-12 months)
175
+ - Success metrics
176
+ - Risk mitigation strategies
177
+ - Resource requirements
178
+ - Next steps
179
+
180
+ ## πŸ—οΈ Architecture
181
+
182
+ ### Research Engine
183
+ - **MultiModelResearchEngine**: Orchestrates agent execution
184
+ - **Model Caching**: Efficient model instance management
185
+ - **Retry Logic**: Automatic fallback for API errors
186
+ - **Web Search Integration**: Real-time information gathering
187
+
188
+ ### Agent System
189
+ 1. **Researcher Agent** πŸ†
190
+ - Identifies top industry leaders
191
+ - Analyzes market positioning
192
+ - Gathers competitive intelligence
193
+
194
+ 2. **Analyzer Agent** ⭐
195
+ - Researches best practices
196
+ - Identifies success patterns
197
+ - Documents innovations
198
+
199
+ 3. **Critic Agent** πŸ”
200
+ - Quality assurance review
201
+ - Source validation
202
+ - Gap identification
203
+
204
+ 4. **Synthesizer Agent** πŸ’‘
205
+ - Synthesizes all inputs
206
+ - Generates recommendations
207
+ - Creates action roadmap
208
+
209
+ ### State Management
210
+ - **ResearchState**: Tracks search history, model usage, dashboard updates
211
+ - **Live Updates**: Real-time progress tracking
212
+ - **Caching**: Results and model instances
213
+
214
+ ## πŸ”§ Configuration
215
+
216
+ ### Environment Variables
217
+
218
+ ```bash
219
+ # Required
220
+ HF_TOKEN=hf_your_token_here
221
+
222
+ # Optional (for future extensions)
223
+ ANTHROPIC_API_KEY=your_anthropic_key
224
+ OPENAI_API_KEY=your_openai_key
225
+ ```
226
+
227
+ ### Model Selection
228
+
229
+ Edit `DEFAULT_PHASE_MODELS` in `app.py`:
230
+
231
+ ```python
232
+ DEFAULT_PHASE_MODELS = {
233
+ "query_understanding": "qwen-2.5-7b",
234
+ "industry_leaders": "qwen-2.5-72b",
235
+ "best_practices": "qwen-2.5-72b",
236
+ "quality_review": "qwen-2.5-72b",
237
+ "recommendations": "qwen-2.5-72b"
238
+ }
239
+ ```
240
+
241
+ ### Available Models
242
+
243
+ | Model | Provider | Speed | Quality | Cost |
244
+ |-------|----------|-------|---------|------|
245
+ | Qwen 2.5 7B | HuggingFace | ⚑⚑⚑ | ⭐⭐⭐ | πŸ’° |
246
+ | Qwen 2.5 72B | HuggingFace | ⚑⚑ | ⭐⭐⭐⭐ | πŸ’°πŸ’° |
247
+ | Llama 3.1 70B | HuggingFace | ⚑⚑ | ⭐⭐⭐⭐ | πŸ’°πŸ’° |
248
+ | Mistral Large | HuggingFace | ⚑⚑ | ⭐⭐⭐⭐ | πŸ’°πŸ’° |
249
+
250
+ ## πŸ“ˆ Expected Performance
251
+
252
+ ### Typical Execution Times
253
+
254
+ | Phase | Duration | Notes |
255
+ |-------|----------|-------|
256
+ | Researcher Agent | 20-30s | Includes web search |
257
+ | Analyzer Agent | 20-30s | Includes web search |
258
+ | Critic Agent | 10-20s | No web search |
259
+ | Synthesizer Agent | 15-25s | No web search |
260
+ | **Total** | **80-120s** | ~2 minutes |
261
+
262
+ ### Factors Affecting Speed
263
+ - Model size (larger = slower)
264
+ - Topic complexity
265
+ - Internet speed (affects web search)
266
+ - API response time
267
+ - System load
268
+
269
+ ## πŸ› Troubleshooting
270
+
271
+ ### "HF_TOKEN not found"
272
+ **Solution**: Set the environment variable:
273
+ ```bash
274
+ export HF_TOKEN=hf_your_token_here
275
+ ```
276
+
277
+ ### "API compatibility issue"
278
+ **Solution**: The system automatically falls back to compatible configurations. If issues persist:
279
+ 1. Try using Qwen models instead
280
+ 2. Simplify your research topic
281
+ 3. Check your internet connection
282
+
283
+ ### "Research stuck on Running"
284
+ **Solution**:
285
+ 1. Check internet connection
286
+ 2. Verify HF_TOKEN is valid
287
+ 3. Try a simpler topic
288
+ 4. Check HuggingFace API status
289
+
290
+ ### "Empty results"
291
+ **Solution**:
292
+ 1. Check the Live Dashboard for errors
293
+ 2. Verify all models are available
294
+ 3. Try with default model configuration
295
+ 4. Simplify the research topic
296
+
297
+ ## πŸ“¦ Deployment
298
+
299
+ ### Local Deployment
300
+ ```bash
301
+ python app.py
302
+ ```
303
+
304
+ ### HuggingFace Spaces
305
+ 1. Create new Space on HuggingFace
306
+ 2. Upload files:
307
+ - `app.py`
308
+ - `requirements.txt`
309
+ - `.env` (with HF_TOKEN)
310
+ 3. HuggingFace automatically detects Gradio app
311
+ 4. Space launches automatically
312
+
313
+ ### Docker Deployment
314
+ ```dockerfile
315
+ FROM python:3.11-slim
316
+
317
+ WORKDIR /app
318
+
319
+ COPY requirements.txt .
320
+ RUN pip install -r requirements.txt
321
+
322
+ COPY app.py .
323
+
324
+ ENV HF_TOKEN=your_token_here
325
+
326
+ CMD ["python", "app.py"]
327
+ ```
328
+
329
+ ## πŸ“š File Structure
330
+
331
+ ```
332
+ .
333
+ β”œβ”€β”€ app.py # Main application
334
+ β”œβ”€β”€ requirements.txt # Python dependencies
335
+ β”œβ”€β”€ agents_config.yaml # Agent configuration (optional)
336
+ β”œβ”€β”€ .env # Environment variables (local only)
337
+ └── README.md # This file
338
+ ```
339
+
340
+ ## πŸ” Security
341
+
342
+ ### API Key Management
343
+ - Never commit `.env` file to version control
344
+ - Use HuggingFace Spaces secrets for deployment
345
+ - Rotate tokens regularly
346
+ - Use read-only tokens when possible
347
+
348
+ ### Data Privacy
349
+ - Research results are not stored
350
+ - Web searches are performed by the models
351
+ - No data is sent to external services except HuggingFace API
352
+ - Each session is independent
353
+
354
+ ## πŸ“– API Reference
355
+
356
+ ### Main Function: `run_research()`
357
+
358
+ ```python
359
+ run_research(
360
+ topic: str,
361
+ model_query: str,
362
+ model_leaders: str,
363
+ model_practices: str,
364
+ model_quality: str,
365
+ model_recommendations: str,
366
+ progress: gr.Progress
367
+ ) -> Tuple[str, str, str, str, str, str]
368
+ ```
369
+
370
+ **Parameters:**
371
+ - `topic`: Research topic
372
+ - `model_*`: Model selection for each phase
373
+ - `progress`: Gradio progress callback
374
+
375
+ **Returns:**
376
+ - Summary, Leaders, Practices, Review, Recommendations, Dashboard
377
+
378
+ ### Research Engine
379
+
380
+ ```python
381
+ engine = MultiModelResearchEngine(phase_models)
382
+ engine.research_industry_leaders(topic)
383
+ engine.research_best_practices(topic)
384
+ engine.quality_review(research_text)
385
+ engine.generate_recommendations(topic, research_text)
386
+ ```
387
+
388
+ ## 🀝 Contributing
389
+
390
+ Contributions are welcome! Areas for enhancement:
391
+ - Additional model support
392
+ - Custom agent configurations
393
+ - Export formats (PDF, DOCX, etc.)
394
+ - Caching and persistence
395
+ - Advanced filtering options
396
+
397
+ ## πŸ“„ License
398
+
399
+ MIT License - See LICENSE file for details
400
+
401
+ ## πŸ™‹ Support
402
+
403
+ ### Getting Help
404
+ 1. Check the Troubleshooting section
405
+ 2. Review the Live Dashboard for error messages
406
+ 3. Verify environment setup
407
+ 4. Check HuggingFace API status
408
+
409
+ ### Common Issues
410
+
411
+ **Q: How long does research take?**
412
+ A: Typically 80-120 seconds (about 2 minutes) depending on topic complexity and model selection.
413
+
414
+ **Q: Can I use different models for each phase?**
415
+ A: Yes! Use the "Configure AI Models" accordion to select different models.
416
+
417
+ **Q: What if a model fails?**
418
+ A: The system has automatic retry logic and will gracefully degrade to compatible configurations.
419
+
420
+ **Q: How many searches are performed?**
421
+ A: Typically 8-12 searches across the Researcher and Analyzer agents.
422
+
423
+ **Q: Can I export the results?**
424
+ A: Results are displayed in markdown format and can be copied. Future versions will support PDF/DOCX export.
425
+
426
+ ## πŸŽ“ Learning Resources
427
+
428
+ - [HuggingFace Hub Documentation](https://huggingface.co/docs/hub)
429
+ - [Gradio Documentation](https://www.gradio.app/docs)
430
+ - [SmolaGents Documentation](https://huggingface.co/docs/smolagents)
431
+ - [Multi-Agent Systems](https://en.wikipedia.org/wiki/Multi-agent_system)
432
+
433
+ ## πŸš€ Roadmap
434
+
435
+ ### Upcoming Features
436
+ - [ ] PDF/DOCX export
437
+ - [ ] Custom agent configuration via YAML
438
+ - [ ] Result caching and history
439
+ - [ ] Advanced filtering options
440
+ - [ ] Custom prompt templates
441
+ - [ ] Multi-language support
442
+ - [ ] API endpoint for programmatic access
443
+ - [ ] Result persistence and database storage
444
+
445
+ ## πŸ“Š Metrics & Analytics
446
+
447
+ The system tracks:
448
+ - Execution time per agent
449
+ - Model usage statistics
450
+ - Search queries performed
451
+ - Success/failure rates
452
+ - Research coverage metrics
453
+
454
+ All metrics are displayed in the Summary and Dashboard tabs.
455
+
456
+ ---
457
+
458
+ **Made with ❀️ for intelligent research and decision-making**
459
+
460
+ For questions or suggestions, please open an issue or contact the development team.