rahul7star commited on
Commit
d8aced6
Β·
verified Β·
1 Parent(s): a9026d9

Create Design-v2.md

Browse files
Files changed (1) hide show
  1. Design-v2.md +363 -0
Design-v2.md ADDED
@@ -0,0 +1,363 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Here’s a clean, structured **design.md** you can directly use to preserve architecture knowledge πŸ‘‡
2
+
3
+ ---
4
+
5
+ # 🧠 PygmyClaw Multi-Agent System Design
6
+
7
+ ## 🎯 Goal
8
+
9
+ Build a **multi-agent AI system** with:
10
+
11
+ * Code execution
12
+ * Web search
13
+ * Image generation
14
+ * Deep research
15
+
16
+ All orchestrated from a **single command center UI**
17
+
18
+ ---
19
+
20
+ # πŸ—οΈ Architecture Overview
21
+
22
+ ```
23
+ UI (app.py)
24
+ ↓
25
+ Session Manager
26
+ ↓
27
+ Agent Router
28
+ ↓
29
+ Agent Executor (PygmyClaw)
30
+ ↓
31
+ Model Router
32
+ ↓
33
+ Tool Manager
34
+ ```
35
+
36
+ ---
37
+
38
+ # πŸ“¦ Existing Components (DO NOT REWRITE)
39
+
40
+ * `app.py` β†’ UI layer
41
+ * `pygmyclaw.py` β†’ core execution engine (queue + speculative decoding)
42
+ * `pygmyclaw_multitool.py` β†’ tools implementation
43
+ * `config.json` β†’ base configuration
44
+
45
+ πŸ‘‰ Strategy: **Wrap and extend, not replace**
46
+
47
+ ---
48
+
49
+ # 🧱 Core Classes
50
+
51
+ ---
52
+
53
+ ## 1. πŸ§‘β€πŸ’Ό SessionManager
54
+
55
+ ### Purpose
56
+
57
+ Manages:
58
+
59
+ * Users
60
+ * Sessions
61
+ * Workspace persistence
62
+ * Settings
63
+
64
+ ### Responsibilities
65
+
66
+ * Create/load users
67
+ * Create/load sessions
68
+ * Save/load workspace.json
69
+ * Save/load settings.json
70
+
71
+ ### Structure
72
+
73
+ ```python
74
+ class SessionManager:
75
+ def create_user(self, username): pass
76
+ def load_user(self, username): pass
77
+ def create_session(self, username): pass
78
+ def load_workspace(self, username, session_id): pass
79
+ def save_workspace(self, username, session_id, data): pass
80
+ def get_settings(self, username): pass
81
+ def save_settings(self, username, settings): pass
82
+ ```
83
+
84
+ ---
85
+
86
+ ## 2. 🧭 AgentRouter (SYSTEM BRAIN)
87
+
88
+ ### Purpose
89
+
90
+ Routes user input to correct agent:
91
+
92
+ ```
93
+ input β†’ agent_type
94
+ ```
95
+
96
+ ### Agent Types
97
+
98
+ * `command`
99
+ * `code`
100
+ * `research`
101
+ * `image`
102
+
103
+ ### Structure
104
+
105
+ ```python
106
+ class AgentRouter:
107
+ def route(self, message: str) -> str:
108
+ pass
109
+ ```
110
+
111
+ ### Notes
112
+
113
+ * Start with keyword-based routing
114
+ * Upgrade later to LLM-based intent detection
115
+
116
+ ---
117
+
118
+ ## 3. πŸ€– AgentExecutor (PygmyClaw Wrapper)
119
+
120
+ ### Purpose
121
+
122
+ Executes tasks based on agent type
123
+
124
+ ### Key Idea
125
+
126
+ ```
127
+ Agent = behavior
128
+ Model = engine
129
+ ```
130
+
131
+ ### Structure
132
+
133
+ ```python
134
+ class AgentExecutor:
135
+ def __init__(self, model_router, tool_manager): pass
136
+
137
+ def run(self, agent_type, message, session):
138
+ pass
139
+ ```
140
+
141
+ ### Responsibilities
142
+
143
+ * Select system prompt
144
+ * Select tools
145
+ * Call pygmyclaw generate
146
+ * Return structured output
147
+
148
+ ---
149
+
150
+ ## 4. 🧰 ToolManager
151
+
152
+ ### Purpose
153
+
154
+ Controls tool access per agent
155
+
156
+ ### Structure
157
+
158
+ ```python
159
+ class ToolManager:
160
+ def get_tools(self, agent_type):
161
+ pass
162
+ ```
163
+
164
+ ### Example Mapping
165
+
166
+ ```json
167
+ {
168
+ "command": ["echo", "sys_info"],
169
+ "code": ["run_python", "write_file"],
170
+ "research": ["web_search", "read_url"],
171
+ "image": ["generate_image"]
172
+ }
173
+ ```
174
+
175
+ ### Rule
176
+
177
+ πŸ‘‰ Agents only access allowed tools (security + clarity)
178
+
179
+ ---
180
+
181
+ ## 5. 🧠 ModelRouter (Future Ready)
182
+
183
+ ### Purpose
184
+
185
+ Abstract model selection
186
+
187
+ ### Structure
188
+
189
+ ```python
190
+ class ModelRouter:
191
+ def get_model(self, agent_type):
192
+ return default_model
193
+ ```
194
+
195
+ ### Phase Strategy
196
+
197
+ * Phase 1 β†’ single model
198
+ * Phase 2 β†’ role-based prompts
199
+ * Phase 3 β†’ multi-model routing
200
+
201
+ ---
202
+
203
+ ## 6. πŸ“‚ Workspace Structure
204
+
205
+ ### Directory Layout
206
+
207
+ ```
208
+ /workspace/users/
209
+ └── <username>/
210
+ β”œβ”€β”€ settings.json
211
+ └── sessions/
212
+ └── <session_id>/
213
+ └── workspace.json
214
+ ```
215
+
216
+ ---
217
+
218
+ ## settings.json (Simplified)
219
+
220
+ ```json
221
+ {
222
+ "default_model": "ollama:llama3",
223
+ "agents": {
224
+ "command": "default",
225
+ "code": "default",
226
+ "research": "default",
227
+ "image": "default"
228
+ }
229
+ }
230
+ ```
231
+
232
+ ---
233
+
234
+ ## workspace.json (Core Data)
235
+
236
+ Stores:
237
+
238
+ * tabs
239
+ * messages
240
+ * agent tasks
241
+ * timeline
242
+ * debug history
243
+
244
+ ---
245
+
246
+ # πŸ” Full Execution Flow
247
+
248
+ ```
249
+ User Input (UI)
250
+ ↓
251
+ SessionManager β†’ load session
252
+ ↓
253
+ AgentRouter β†’ detect agent_type
254
+ ↓
255
+ AgentExecutor.run()
256
+ ↓
257
+ ModelRouter β†’ select model
258
+ ↓
259
+ ToolManager β†’ allowed tools
260
+ ↓
261
+ PygmyClaw β†’ generate output
262
+ ↓
263
+ SessionManager β†’ save workspace
264
+ ↓
265
+ UI update
266
+ ```
267
+
268
+ ---
269
+
270
+ # 🧠 Key Design Principles
271
+
272
+ ---
273
+
274
+ ## 1. Agent β‰  Model
275
+
276
+ | Concept | Meaning |
277
+ | ------- | ---------------- |
278
+ | Agent | behavior |
279
+ | Model | execution engine |
280
+
281
+ πŸ‘‰ Many agents can share one model
282
+
283
+ ---
284
+
285
+ ## 2. Start Simple, Scale Later
286
+
287
+ ### Phase 1
288
+
289
+ * Single model
290
+ * Multi-agent behavior
291
+
292
+ ### Phase 2
293
+
294
+ * Better routing
295
+ * Tool optimization
296
+
297
+ ### Phase 3
298
+
299
+ * Multi-model support
300
+
301
+ ---
302
+
303
+ ## 3. Tools Are Scoped
304
+
305
+ | Agent | Allowed |
306
+ | -------- | --------------- |
307
+ | command | basic tools |
308
+ | code | execution tools |
309
+ | research | web tools |
310
+ | image | image tools |
311
+
312
+ ---
313
+
314
+ ## 4. Session is Core
315
+
316
+ Everything tied to:
317
+
318
+ ```
319
+ username + session_id
320
+ ```
321
+
322
+ ---
323
+
324
+ ## 5. Do NOT Modify Core Engine
325
+
326
+ * Keep `pygmyclaw.py` intact
327
+ * Extend via wrapper layers
328
+
329
+ ---
330
+
331
+ # πŸš€ Future Enhancements
332
+
333
+ * LLM-based agent routing
334
+ * Multi-model support (Ollama + HF)
335
+ * Parallel agents
336
+ * Streaming outputs
337
+ * Advanced workspace UI (tabs, timelines)
338
+
339
+ ---
340
+
341
+ # 🧭 Summary
342
+
343
+ This system evolves into:
344
+
345
+ > **A single-model, multi-agent AI platform with persistent memory, tool orchestration, and scalable architecture**
346
+
347
+ ---
348
+
349
+ # βœ… Next Step
350
+
351
+ Design **Agent Behavior Definitions**:
352
+
353
+ For each agent:
354
+
355
+ * system prompt
356
+ * tools
357
+ * constraints
358
+ * output format
359
+
360
+
361
+
362
+ ---
363
+