Add settings.json for permissions and create QUICK_REFERENCE.md for SmolVM usage
Browse files- .qwen/settings.json.orig +7 -0
- QUICK_REFERENCE.md +129 -0
- agent.py +38 -35
.qwen/settings.json.orig
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"permissions": {
|
| 3 |
+
"allow": [
|
| 4 |
+
"WebSearch"
|
| 5 |
+
]
|
| 6 |
+
}
|
| 7 |
+
}
|
QUICK_REFERENCE.md
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 🚀 SmolVM Quick Reference Card
|
| 2 |
+
|
| 3 |
+
## ✅ Installation Status
|
| 4 |
+
- **Original Error:** `ModuleNotFoundError: No module named 'pwd'` ❌
|
| 5 |
+
- **Current Status:** Resolved - Running in WSL2 Ubuntu ✅
|
| 6 |
+
- **Access Method:** Windows script (`smolvm.cmd`) ✅
|
| 7 |
+
|
| 8 |
+
---
|
| 9 |
+
|
| 10 |
+
## 💻 Using SmolVM from Windows
|
| 11 |
+
|
| 12 |
+
### From CMD:
|
| 13 |
+
```cmd
|
| 14 |
+
smolvm.cmd doctor
|
| 15 |
+
smolvm.cmd --help
|
| 16 |
+
smolvm.cmd list
|
| 17 |
+
smolvm.cmd create <config>
|
| 18 |
+
```
|
| 19 |
+
|
| 20 |
+
### From PowerShell:
|
| 21 |
+
```powershell
|
| 22 |
+
.\smolvm.ps1 doctor
|
| 23 |
+
.\smolvm.ps1 --help
|
| 24 |
+
.\smolvm.ps1 list
|
| 25 |
+
.\smolvm.ps1 create <config>
|
| 26 |
+
```
|
| 27 |
+
|
| 28 |
+
---
|
| 29 |
+
|
| 30 |
+
## 📋 Common Commands
|
| 31 |
+
|
| 32 |
+
| Command | Description |
|
| 33 |
+
|---------|-------------|
|
| 34 |
+
| `smolvm.cmd --help` | Show all available commands |
|
| 35 |
+
| `smolvm.cmd doctor` | Check installation status |
|
| 36 |
+
| `smolvm.cmd setup` | Configure network permissions |
|
| 37 |
+
| `smolvm.cmd list` | List all sandboxes |
|
| 38 |
+
| `smolvm.cmd create <config>` | Create a new sandbox |
|
| 39 |
+
| `smolvm.cmd ssh <name>` | SSH into a sandbox |
|
| 40 |
+
| `smolvm.cmd stop <name>` | Stop a running sandbox |
|
| 41 |
+
| `smolvm.cmd browser` | Manage browser sessions |
|
| 42 |
+
| `smolvm.cmd ui` | Start dashboard UI |
|
| 43 |
+
|
| 44 |
+
---
|
| 45 |
+
|
| 46 |
+
## 📂 Files Created
|
| 47 |
+
|
| 48 |
+
### Scripts (Ready to Use):
|
| 49 |
+
- ✅ `smolvm.cmd` - Windows CMD launcher
|
| 50 |
+
- ✅ `smolvm.ps1` - PowerShell launcher
|
| 51 |
+
|
| 52 |
+
### Docker Setup (Alternative):
|
| 53 |
+
- 📁 `smolvm-docker/` - Docker-based setup (not needed now)
|
| 54 |
+
- `Dockerfile`
|
| 55 |
+
- `docker-compose.yml`
|
| 56 |
+
- `README.md`
|
| 57 |
+
|
| 58 |
+
### Documentation:
|
| 59 |
+
- 📄 `SCRIPTS_README.md` - Detailed setup guide
|
| 60 |
+
- 📄 `QUICK_REFERENCE.md` - This file
|
| 61 |
+
|
| 62 |
+
---
|
| 63 |
+
|
| 64 |
+
## ⚠️ Known Limitations
|
| 65 |
+
|
| 66 |
+
### KVM Not Available
|
| 67 |
+
- **Issue:** `/dev/kvm does not exist` in WSL2
|
| 68 |
+
- **Impact:** Firecracker micro-VMs may not work
|
| 69 |
+
- **Reason:** WSL2 doesn't expose KVM by default
|
| 70 |
+
- **Status:** Basic installation works, but VM execution may fail
|
| 71 |
+
|
| 72 |
+
### What Works:
|
| 73 |
+
✅ SmolVM installation
|
| 74 |
+
✅ Command-line interface
|
| 75 |
+
✅ Configuration management
|
| 76 |
+
✅ Help and doctor commands
|
| 77 |
+
|
| 78 |
+
### What May Not Work:
|
| 79 |
+
❌ Running actual Firecracker micro-VMs (requires KVM)
|
| 80 |
+
❌ Network setup commands (requires sudo)
|
| 81 |
+
|
| 82 |
+
---
|
| 83 |
+
|
| 84 |
+
## 🔧 Making `smolvm.cmd` Available Everywhere
|
| 85 |
+
|
| 86 |
+
### Option 1: Copy to Windows directory
|
| 87 |
+
```cmd
|
| 88 |
+
copy "E:\Git\Final_Assignment_Template\smolvm.cmd" C:\Windows\
|
| 89 |
+
```
|
| 90 |
+
|
| 91 |
+
### Option 2: Add to PATH
|
| 92 |
+
Add `E:\Git\Final_Assignment_Template` to your system PATH environment variable.
|
| 93 |
+
|
| 94 |
+
### Option 3: Create an alias (PowerShell)
|
| 95 |
+
Add to your `$PROFILE`:
|
| 96 |
+
```powershell
|
| 97 |
+
function smolvm { & "E:\Git\Final_Assignment_Template\smolvm.cmd" @args }
|
| 98 |
+
```
|
| 99 |
+
|
| 100 |
+
---
|
| 101 |
+
|
| 102 |
+
## 🎯 Next Steps
|
| 103 |
+
|
| 104 |
+
1. **Test basic commands:**
|
| 105 |
+
```cmd
|
| 106 |
+
smolvm.cmd --version
|
| 107 |
+
smolvm.cmd list
|
| 108 |
+
```
|
| 109 |
+
|
| 110 |
+
2. **Try creating a sandbox** (may fail without KVM):
|
| 111 |
+
```cmd
|
| 112 |
+
smolvm.cmd create --help
|
| 113 |
+
```
|
| 114 |
+
|
| 115 |
+
3. **(Optional) Enable KVM in WSL2:**
|
| 116 |
+
- Requires Windows 11 Build 26100+
|
| 117 |
+
- Enable in `.wslconfig`:
|
| 118 |
+
```ini
|
| 119 |
+
[wsl2]
|
| 120 |
+
nestedVirtualization=true
|
| 121 |
+
```
|
| 122 |
+
|
| 123 |
+
---
|
| 124 |
+
|
| 125 |
+
## 📞 Need Help?
|
| 126 |
+
|
| 127 |
+
- Check `SCRIPTS_README.md` for detailed troubleshooting
|
| 128 |
+
- Visit: https://github.com/CelestoAI/SmolVM
|
| 129 |
+
- Run: `smolvm.cmd --help`
|
agent.py
CHANGED
|
@@ -12,6 +12,7 @@ from dotenv import load_dotenv
|
|
| 12 |
from langchain_core.messages import HumanMessage, AIMessage, SystemMessage, ToolMessage
|
| 13 |
from langchain_core.tools import tool
|
| 14 |
from langchain_groq import ChatGroq
|
|
|
|
| 15 |
from langgraph.graph import StateGraph, START, END
|
| 16 |
from langchain_community.document_loaders import WikipediaLoader, UnstructuredFileLoader
|
| 17 |
from langchain_community.document_loaders.image import UnstructuredImageLoader
|
|
@@ -171,29 +172,33 @@ class AgentState(TypedDict):
|
|
| 171 |
|
| 172 |
# --- LLM Invocation with Fallback ---
|
| 173 |
def _invoke_llm_with_tools(messages, fallback_count=0):
|
| 174 |
-
"""Invoke LLM with tool binding and rate limit handling.
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
if prefer_free:
|
| 179 |
-
# Prefer free/open-source model; set MODEL_NAME env to a usable local model name if available
|
| 180 |
-
model_name = "open-source-local"
|
| 181 |
-
else:
|
| 182 |
-
model_name = "llama-3.3-70b-versatile" if fallback_count == 0 else "llama-3.1-8b-instant"
|
| 183 |
try:
|
| 184 |
-
|
|
|
|
| 185 |
model_with_tools = model.bind_tools(tools)
|
| 186 |
return model_with_tools.invoke(messages)
|
| 187 |
except Exception as e:
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
return
|
| 195 |
-
|
| 196 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
|
| 198 |
# --- Helper Functions ---
|
| 199 |
def is_reversed_text(question: str) -> bool:
|
|
@@ -222,28 +227,26 @@ def call_model(state: AgentState):
|
|
| 222 |
|
| 223 |
# Add System Message if not present
|
| 224 |
if not any(isinstance(m, SystemMessage) for m in messages):
|
| 225 |
-
system_prompt = """You are a highly capable General AI Assistant (GAIA). Your goal is to solve complex, multi-step tasks
|
| 226 |
|
| 227 |
Your thought process MUST be methodical:
|
| 228 |
1. THINK:
|
| 229 |
-
- Analyze the question deeply. Identify the core goal and
|
| 230 |
-
-
|
| 231 |
- Plan your steps. Break the problem into smaller sub-problems.
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
- Is the precision correct? (e.g., if it asks for 'two decimal places', ensure it has exactly two).
|
| 240 |
-
- Is the format exactly as requested?
|
| 241 |
-
6. FINALIZE: Once you are absolutely confident, provide the result in the exact format: FINAL ANSWER: <answer>.
|
| 242 |
|
| 243 |
Guidelines:
|
| 244 |
-
-
|
| 245 |
-
-
|
| 246 |
-
-
|
|
|
|
| 247 |
"""
|
| 248 |
messages = [SystemMessage(content=system_prompt)] + messages
|
| 249 |
|
|
|
|
| 12 |
from langchain_core.messages import HumanMessage, AIMessage, SystemMessage, ToolMessage
|
| 13 |
from langchain_core.tools import tool
|
| 14 |
from langchain_groq import ChatGroq
|
| 15 |
+
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 16 |
from langgraph.graph import StateGraph, START, END
|
| 17 |
from langchain_community.document_loaders import WikipediaLoader, UnstructuredFileLoader
|
| 18 |
from langchain_community.document_loaders.image import UnstructuredImageLoader
|
|
|
|
| 172 |
|
| 173 |
# --- LLM Invocation with Fallback ---
|
| 174 |
def _invoke_llm_with_tools(messages, fallback_count=0):
|
| 175 |
+
"""Invoke LLM with tool binding and rate limit handling.
|
| 176 |
+
Primary: Gemini 1.5 Flash (Multimodal, Free Tier).
|
| 177 |
+
Fallback: Groq (Llama 3.3).
|
| 178 |
+
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
try:
|
| 180 |
+
# Primary: Gemini 1.5 Flash
|
| 181 |
+
model = ChatGoogleGenerativeAI(model="gemini-1.5-flash", temperature=0)
|
| 182 |
model_with_tools = model.bind_tools(tools)
|
| 183 |
return model_with_tools.invoke(messages)
|
| 184 |
except Exception as e:
|
| 185 |
+
print(f"Gemini Error: {e}. Falling back to Groq...")
|
| 186 |
+
try:
|
| 187 |
+
# Fallback: Groq
|
| 188 |
+
groq_model = "llama-3.3-70b-versatile" if fallback_count == 0 else "llama-3.1-8b-instant"
|
| 189 |
+
model = ChatGroq(model=groq_model, temperature=0)
|
| 190 |
+
model_with_tools = model.bind_tools(tools)
|
| 191 |
+
return model_with_tools.invoke(messages)
|
| 192 |
+
except Exception as groq_e:
|
| 193 |
+
err_msg = str(groq_e).lower()
|
| 194 |
+
if ("rate limit" in err_msg or "429" in err_msg) and fallback_count < 2:
|
| 195 |
+
import time
|
| 196 |
+
wait_time = 10 * (fallback_count + 1)
|
| 197 |
+
print(f"Groq Rate limit hit. Waiting {wait_time}s...")
|
| 198 |
+
time.sleep(wait_time)
|
| 199 |
+
return _invoke_llm_with_tools(messages, fallback_count + 1)
|
| 200 |
+
print(f"Critical LLM Error: {groq_e}")
|
| 201 |
+
return AIMessage(content=f"ERROR: All LLM invocations failed: {groq_e}")
|
| 202 |
|
| 203 |
# --- Helper Functions ---
|
| 204 |
def is_reversed_text(question: str) -> bool:
|
|
|
|
| 227 |
|
| 228 |
# Add System Message if not present
|
| 229 |
if not any(isinstance(m, SystemMessage) for m in messages):
|
| 230 |
+
system_prompt = """You are a highly capable General AI Assistant (GAIA). Your goal is to solve complex, multi-step tasks.
|
| 231 |
|
| 232 |
Your thought process MUST be methodical:
|
| 233 |
1. THINK:
|
| 234 |
+
- Analyze the question deeply. Identify the core goal and ALL constraints (units, date formats, precision, etc.).
|
| 235 |
+
- If the task involves an image or video, describe the visual elements before attempting to solve.
|
| 236 |
- Plan your steps. Break the problem into smaller sub-problems.
|
| 237 |
+
2. ACT (Python-First):
|
| 238 |
+
- Use `python_repl` for ANY task involving: math, counting, data analysis, list filtering (e.g., botany), or verifying logic (e.g., commutativity). DO NOT do these manually.
|
| 239 |
+
- Use `web_search` for initial discovery and `browse_url` to verify details from the source.
|
| 240 |
+
3. OBSERVE: Carefully review tool outputs. If a result is ambiguous, search for a second source to triangulate.
|
| 241 |
+
4. REFINE: Question your assumptions. If the answer seems too simple for a complex GAIA task, you likely missed a constraint.
|
| 242 |
+
5. VERIFY: Before finalizing, double-check units and precision.
|
| 243 |
+
6. FINALIZE: Provide the result in the exact format: FINAL ANSWER: <answer>.
|
|
|
|
|
|
|
|
|
|
| 244 |
|
| 245 |
Guidelines:
|
| 246 |
+
- [Attached Files]: Always use `read_file` for local files.
|
| 247 |
+
- Research: Don't trust a single snippet; browse the full page if the answer is buried.
|
| 248 |
+
- Constraints: If the question says 'alphabetize' or 'comma-separated', use Python to ensure it is perfect.
|
| 249 |
+
- Final Output: Return ONLY the final answer in the requested format.
|
| 250 |
"""
|
| 251 |
messages = [SystemMessage(content=system_prompt)] + messages
|
| 252 |
|