Paperbag commited on
Commit
9e3bdbf
·
1 Parent(s): 40dab7b

Add settings.json for permissions and create QUICK_REFERENCE.md for SmolVM usage

Browse files
Files changed (3) hide show
  1. .qwen/settings.json.orig +7 -0
  2. QUICK_REFERENCE.md +129 -0
  3. 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
- model_name = os.getenv("MODEL_NAME")
176
- prefer_free = os.getenv("PREFER_FREE_MODELS", "0") == "1"
177
- if not model_name:
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
- model = ChatGroq(model=model_name, temperature=0)
 
185
  model_with_tools = model.bind_tools(tools)
186
  return model_with_tools.invoke(messages)
187
  except Exception as e:
188
- err_msg = str(e).lower()
189
- if ("rate limit" in err_msg or "429" in err_msg) and fallback_count < 2:
190
- import time
191
- wait_time = 10 * (fallback_count + 1)
192
- print(f"Rate limit hit. Waiting {wait_time}s...")
193
- time.sleep(wait_time)
194
- return _invoke_llm_with_tools(messages, fallback_count + 1)
195
- print(f"LLM Error: {e}")
196
- return AIMessage(content=f"ERROR: LLM invocation failed: {e}")
 
 
 
 
 
 
 
 
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 using your tools.
226
 
227
  Your thought process MUST be methodical:
228
  1. THINK:
229
- - Analyze the question deeply. Identify the core goal and any constraints (e.g., specific units, date formats, or required precision).
230
- - Review all available information (including attached files).
231
  - Plan your steps. Break the problem into smaller sub-problems.
232
- - Consider potential pitfalls or alternative interpretations of the question.
233
- 2. ACT: Call tools as needed. Use `python_repl` for any math, counting, data analysis, or file processing to avoid manual errors. Use `web_search` for quick facts and `browse_url` for in-depth reading.
234
- 3. OBSERVE: Carefully review tool outputs. If an error occurs, diagnose it and adapt your plan.
235
- 4. REFINE: If the answer is not yet clear, iterate. Question your assumptions.
236
- 5. VERIFY: Before providing the final answer, double-check:
237
- - Does the answer directly address all parts of the question?
238
- - Are the units correct? (e.g., if it asks for 'meters', don't give 'kilometers').
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
- - If you find an [Attached File Local Path: ...], *always* use `read_file` to access its content.
245
- - Be precise. Double-check year ranges, units, and specific formatting requirements.
246
- - Return ONLY the final answer in the requested format when done. Do not include any extra commentary once you provide the final answer.
 
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