@@ -4,10 +4,40 @@ Generate and execute Python code for telemetry analysis using Cohere AI and a cu
44
55## Architecture
66
7- ```
8- [User in Slack] → [Slackbot (Lappy)] → [Code Generator] → [Custom Sandbox]
9- ↑ (Cohere AI) (Python + InfluxDB)
10- └──────────────────────────── [Results (images, logs, data)] ←──────────┘
7+ ``` mermaid
8+ flowchart TD
9+ User([User in Slack])
10+
11+ User -->|"!agent <prompt>"| Slackbot
12+
13+ subgraph "Code Generator (port 3030)"
14+ direction TB
15+ Receive[Receive prompt]
16+ LoadGuide["Load system prompt (prompt-guide.txt)"]
17+ CohereAI["Cohere AI (command-r-plus)"]
18+ RetryNode["Append error to prompt and retry"]
19+ Check{"Execution successful?"}
20+
21+ Receive --> LoadGuide
22+ LoadGuide -->|"system prompt + user prompt"| CohereAI
23+ CohereAI -->|"Generated Python code"| Check
24+ RetryNode -->|"Updated prompt"| CohereAI
25+ end
26+
27+ subgraph "Sandbox (port 8080)"
28+ direction TB
29+ Execute["Execute Python in subprocess"]
30+ InfluxDB[("InfluxDB3")]
31+
32+ Execute <-->|"slicks: fetch_telemetry(), discover_sensors()"| InfluxDB
33+ end
34+
35+ Slackbot -->|"POST /api/generate-code { prompt }"| Receive
36+ Check -->|"Submit code"| Execute
37+ Execute -->|"ok, stdout, stderr, output_files (b64)"| Check
38+ Check -->|"Failed & retries remaining"| RetryNode
39+ Check -->|"Success or max retries reached"| Slackbot
40+ Slackbot -->|"Text output + uploaded images"| User
1141```
1242
1343### Components
@@ -38,7 +68,7 @@ Add to your `.env` file:
3868# Required: Cohere API key
3969COHERE_API_KEY=your-cohere-api-key-here
4070
41- # Optional: Cohere model (default: command-r-plus)
71+ # Optional: Cohere model (default in docker-compose : command-r-plus; code default: command-a-reasoning-08-2025 )
4272COHERE_MODEL=command-r-plus
4373
4474# Optional: Max retry attempts (default: 2)
@@ -119,27 +149,27 @@ Use the `!agent` command in Slack:
119149** Simple Plot:**
120150```
121151User: !agent create a random scatter plot
122- Bot: 🤖 Processing your request...
123- Bot: ✅ Code executed successfully!
124- Bot: 📊 Here's your visualization: [output.png]
152+ Bot: Processing your request...
153+ Bot: Code executed successfully!
154+ Bot: Here's your visualization: [output.png]
125155```
126156
127157** With Retry:**
128158```
129159User: !agent plot df['time'] data
130- Bot: 🤖 Processing your request...
131- Bot: ⚠️ Initial code had errors. Retried 1 time(s) with error feedback.
132- Bot: ✅ Code executed successfully! (after 1 retry)
133- Bot: Output: Data plotted successfully
160+ Bot: Processing your request...
161+ Bot: Initial code had errors. Retried 1 time(s) with error feedback.
162+ Bot: Code executed successfully! (after 1 retry)
163+ Bot: Output: Data plotted successfully
134164```
135165
136166** Failure After Retries:**
137167```
138168User: !agent impossible task
139- Bot: 🤖 Processing your request...
140- Bot: ⚠️ Initial code had errors. Retried 2 time(s) with error feedback.
141- Bot: ❌ Code execution failed after 2 retries:
142- ERROR_TRACE: [error details]
169+ Bot: Processing your request...
170+ Bot: Initial code had errors. Retried 2 time(s) with error feedback.
171+ Bot: Code execution failed after 2 retries:
172+ ERROR_TRACE: [error details]
143173```
144174
145175## System Prompt
@@ -204,9 +234,9 @@ Response:
204234}
205235```
206236
207- ### Sandbox Runner Service (Port 9090 )
237+ ### Sandbox Runner Service (Port 8080 )
208238
209- ** POST /**
239+ ** POST / or /execute **
210240``` json
211241{
212242 "code" : " print('hello world')"
@@ -216,11 +246,16 @@ Response:
216246Response:
217247``` json
218248{
219- "success " : true ,
249+ "ok " : true ,
220250 "std_out" : " hello world\n " ,
221251 "std_err" : " " ,
222252 "return_code" : 0 ,
223- "output_files" : []
253+ "output_files" : [
254+ {
255+ "filename" : " output.png" ,
256+ "b64_data" : " base64-encoded-bytes"
257+ }
258+ ]
224259}
225260```
226261
@@ -241,7 +276,7 @@ docker compose logs -f sandbox
241276
242277- Code executes in isolated subprocess with timeout limits
243278- ** Has internet access** for InfluxDB queries via ` slicks ` and API calls
244- - Limited runtime (30 seconds max, configurable)
279+ - Limited runtime (120 seconds max, configurable via ` SANDBOX_TIMEOUT ` )
245280- Limited memory and file size
246281- InfluxDB credentials passed via environment variables (consumed by ` slicks ` automatically)
247282- Generated code is logged for audit purposes
0 commit comments