Spaces:
Running
Running
File size: 3,580 Bytes
7b20f5d |
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 |
# Modal Integration
## Priority: P1 - HIGH VALUE ($2,500 Modal Innovation Award)
---
## What Modal Is For
Modal provides serverless GPU/CPU compute. For DeepCritical:
### Current Use Case (Mario's Code)
- `src/tools/code_execution.py` - Run LLM-generated analysis code in sandboxes
- Scientific computing (pandas, scipy, numpy) in isolated containers
### Potential Additional Use Cases
| Use Case | Benefit | Complexity |
|----------|---------|------------|
| Code Execution Sandbox | Run statistical analysis safely | ✅ Already built |
| LLM Inference | Run local models (no API costs) | Medium |
| Batch Processing | Process many papers in parallel | Medium |
| Embedding Generation | GPU-accelerated embeddings | Low |
---
## Current State
Mario implemented `src/tools/code_execution.py`:
```python
# Already exists - ModalCodeExecutor
executor = get_code_executor()
result = executor.execute("""
import pandas as pd
import numpy as np
# LLM-generated statistical analysis
""")
```
### What's Missing
1. **Not wired into the main pipeline** - The executor exists but isn't used
2. **No Modal tokens configured** - Needs MODAL_TOKEN_ID/MODAL_TOKEN_SECRET
3. **No demo showing it works** - Judges need to see it
---
## Integration Plan
### Step 1: Wire Into Agent Pipeline
Add a `StatisticalAnalysisAgent` that uses Modal:
```python
# src/agents/analysis_agent.py
from src.tools.code_execution import get_code_executor
class AnalysisAgent:
"""Run statistical analysis on evidence using Modal sandbox."""
async def analyze(self, evidence: list[Evidence], query: str) -> str:
# 1. LLM generates analysis code
code = await self._generate_analysis_code(evidence, query)
# 2. Execute in Modal sandbox
executor = get_code_executor()
result = executor.execute(code)
# 3. Return results
return result["stdout"]
```
### Step 2: Add to Orchestrator
```python
# In orchestrator, after gathering evidence:
if settings.enable_modal_analysis:
analysis_agent = AnalysisAgent()
stats_results = await analysis_agent.analyze(evidence, query)
```
### Step 3: Create Demo
```python
# examples/modal_demo/run_analysis.py
"""Demo: Modal-powered statistical analysis of drug evidence."""
# Show:
# 1. Gather evidence from PubMed
# 2. Generate analysis code with LLM
# 3. Execute in Modal sandbox
# 4. Return statistical insights
```
---
## Modal Setup
### 1. Install Modal CLI
```bash
pip install modal
modal setup # Authenticates with Modal
```
### 2. Set Environment Variables
```bash
# In .env
MODAL_TOKEN_ID=your-token-id
MODAL_TOKEN_SECRET=your-token-secret
```
### 3. Deploy (Optional)
```bash
modal deploy src/tools/code_execution.py
```
---
## What to Show Judges
For the Modal Innovation Award ($2,500):
1. **Sandbox Isolation** - Code runs in container, not local
2. **Scientific Computing** - Real pandas/scipy analysis
3. **Safety** - Can't access local filesystem
4. **Speed** - Modal's fast cold starts
### Demo Script
```bash
# Run the Modal verification script
uv run python examples/modal_demo/verify_sandbox.py
```
This proves code runs in Modal, not locally.
---
## Files to Update
- [ ] Wire `code_execution.py` into pipeline
- [ ] Create `src/agents/analysis_agent.py`
- [ ] Update `examples/modal_demo/` with working demo
- [ ] Add Modal setup to README
- [ ] Test with real Modal account
---
## Cost Estimate
Modal pricing for our use case:
- CPU sandbox: ~$0.0001 per execution
- For demo/judging: < $1 total
- Free tier: 30 hours/month
Not a cost concern.
|