Pyae Sone commited on
Commit
a797e4d
Β·
1 Parent(s): 20bdb98

fix(backend): fix all runtime errors in main_v11.py

Browse files

Critical bug fixes:
- TaskEngine.__init__ only takes ws_manager (not ai_router) - fixed
- init_db() takes no arguments - fixed
- task_engine.run() -> task_engine.start() - fixed
- ws_manager.emit_task() method doesn't exist -> use emit_chat() - fixed
- connector_manager.initialize() not needed (sync init) - removed
- WebSocket connect() uses room-based system, use 'chat:{session_id}' - fixed
- Added task_engine.stop() on shutdown
- Updated HF Space README.md with v11 info and correct header

Files changed (2) hide show
  1. backend/README.md +28 -15
  2. backend/main_v11.py +48 -44
backend/README.md CHANGED
@@ -1,5 +1,5 @@
1
  ---
2
- title: God Agent OS v10 Backend
3
  emoji: πŸ€–
4
  colorFrom: purple
5
  colorTo: indigo
@@ -9,22 +9,35 @@ license: mit
9
  app_port: 7860
10
  ---
11
 
12
- # GOD AGENT OS v10 β€” Backend API
13
- **Distributed 22-Space Architecture | Autonomous Agent OS**
14
  *Powered by Pyae Sone*
15
 
16
  ## Runtime Overview
17
- - 22 distributed worker spaces
18
- - God Core Space orchestration
19
- - KeyPool routing for Gemini, SambaNova, and GitHub model endpoints
20
- - WebSocket + REST control plane
21
- - Backward-compatible legacy agent fleet
22
 
23
- ## Primary APIs
24
- - `GET /` β€” system runtime summary
25
- - `GET /api/v1/spaces` β€” list all worker spaces
26
- - `POST /api/v1/spaces/{name}/execute` β€” execute in a worker space
27
- - `POST /api/v1/kernel/orchestrate` β€” main orchestration endpoint
28
- - `GET /api/v1/ai/pool-status` β€” key pool visibility
29
- - `WS /ws/chat/{session_id}` β€” live orchestration channel
30
  - `GET /api/docs` β€” Swagger UI
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: Autonomous Coding System
3
  emoji: πŸ€–
4
  colorFrom: purple
5
  colorTo: indigo
 
9
  app_port: 7860
10
  ---
11
 
12
+ # GOD AGENT OS v11 β€” Backend API
13
+ **16-Agent Autonomous Engineering OS | God Mode**
14
  *Powered by Pyae Sone*
15
 
16
  ## Runtime Overview
17
+ - 16 autonomous agents (Chat, Planner, Coder, Debug, Test, File, Git, Browser, Vision, Sandbox, Deploy, Connector, Memory, Workflow, UI, Reasoning)
18
+ - 22 logical worker spaces (all running in this single backend)
19
+ - Multi-provider AI Router: Gemini β†’ SambaNova β†’ GitHub Models β†’ Groq β†’ OpenAI
20
+ - WebSocket + REST + SSE streaming
 
21
 
22
+ ## Key Endpoints
23
+ - `GET /` β€” Root info
24
+ - `GET /health` β€” Health check
 
 
 
 
25
  - `GET /api/docs` β€” Swagger UI
26
+ - `GET /api/v1/system/status` β€” Full system status
27
+ - `GET /api/v1/agents` β€” List all 16 agents
28
+ - `GET /api/v1/spaces` β€” All 22 spaces status
29
+ - `POST /api/v1/chat` β€” Chat with streaming
30
+ - `POST /api/v1/orchestrate` β€” God Mode orchestration
31
+ - `WS /ws/{session_id}` β€” Real-time WebSocket
32
+ - `WS /ws/computer-use/{session_id}` β€” Computer-use event stream
33
+
34
+ ## Environment Variables
35
+ Set these in HF Space secrets:
36
+ - `GEMINI_KEY` β€” Google Gemini API key(s), comma-separated
37
+ - `SAMBANOVA_KEY` β€” SambaNova API key(s), comma-separated
38
+ - `GITHUB_KEY` β€” GitHub Models API key(s), comma-separated
39
+ - `GROQ_API_KEY` β€” Groq API key (optional fallback)
40
+ - `OPENAI_API_KEY` β€” OpenAI API key (optional fallback)
41
+ - `GITHUB_TOKEN` β€” GitHub token for Git operations
42
+ - `HF_TOKEN` β€” HuggingFace token
43
+ - `VERCEL_TOKEN` β€” Vercel deploy token
backend/main_v11.py CHANGED
@@ -2,6 +2,14 @@
2
  πŸš€ GOD AGENT OS v11 β€” 100% Working Autonomous Engineering OS
3
  God Mode: Plan + Code + Debug + Deploy + Browse + Git + Memory
4
  Real streaming, real agents, real computer-use events
 
 
 
 
 
 
 
 
5
  """
6
 
7
  import asyncio
@@ -74,7 +82,6 @@ orchestrator: GodAgentOrchestratorV7 = None
74
  connector_manager: ConnectorManager = None
75
 
76
  # ─── Computer-Use Event Stream (Manus-style) ──────────────────────────────────
77
- # Each session has a list of computer-use steps shown in UI
78
  computer_use_sessions: Dict[str, List[Dict]] = {}
79
 
80
 
@@ -89,7 +96,6 @@ def add_computer_use_step(session_id: str, step_type: str, data: Dict):
89
  "timestamp": time.time(),
90
  "status": "running",
91
  })
92
- # Keep last 100 steps
93
  computer_use_sessions[session_id] = computer_use_sessions[session_id][-100:]
94
 
95
 
@@ -99,9 +105,8 @@ async def lifespan(app: FastAPI):
99
 
100
  log.info("πŸš€ God Agent OS v11 starting up...")
101
 
102
- # Initialize DB
103
- db_path = os.environ.get("DB_PATH", "/tmp/god_agent_v11.db")
104
- await init_db(db_path)
105
 
106
  # Initialize AI Router
107
  ai_router = AIRouterV10()
@@ -109,8 +114,8 @@ async def lifespan(app: FastAPI):
109
  # WebSocket Manager
110
  ws_manager = WebSocketManager()
111
 
112
- # Task Engine
113
- task_engine = TaskEngine(ws_manager, ai_router)
114
 
115
  # Agent Fleet
116
  orchestrator = GodAgentOrchestratorV7(ws_manager, ai_router)
@@ -135,9 +140,8 @@ async def lifespan(app: FastAPI):
135
  for name, agent in agents_map.items():
136
  orchestrator.register_agent(name, agent)
137
 
138
- # Connector Manager
139
  connector_manager = ConnectorManager()
140
- await connector_manager.initialize()
141
 
142
  # Attach to app state
143
  app.state.ws_manager = ws_manager
@@ -146,13 +150,14 @@ async def lifespan(app: FastAPI):
146
  app.state.orchestrator = orchestrator
147
  app.state.connector_manager = connector_manager
148
 
149
- # Start task engine
150
- asyncio.create_task(task_engine.run())
151
 
152
  log.info("βœ… God Agent OS v11 ready!", agents=len(agents_map))
153
  yield
154
 
155
  log.info("Shutting down God Agent OS v11...")
 
156
 
157
 
158
  # ─── App ──────────────────────────────────────────────────────────────────────
@@ -191,7 +196,8 @@ app.include_router(github.router, prefix="/api/v1/github", tags=["github"])
191
 
192
  @app.websocket("/ws/{session_id}")
193
  async def websocket_endpoint(websocket: WebSocket, session_id: str):
194
- await ws_manager.connect(websocket, session_id)
 
195
  try:
196
  while True:
197
  data = await websocket.receive_json()
@@ -201,14 +207,13 @@ async def websocket_endpoint(websocket: WebSocket, session_id: str):
201
  await websocket.send_json({"type": "pong", "ts": time.time()})
202
 
203
  elif event_type == "message":
204
- # Real-time chat/task via WebSocket
205
  message = data.get("message", "")
206
  task_id = uuid.uuid4().hex[:12]
207
- await ws_manager.emit_task(session_id, "task_start", {
 
208
  "task_id": task_id,
209
  "message": message[:100],
210
  })
211
- # Run in background
212
  asyncio.create_task(
213
  _run_ws_task(message, task_id, session_id)
214
  )
@@ -216,10 +221,10 @@ async def websocket_endpoint(websocket: WebSocket, session_id: str):
216
  elif event_type == "stop":
217
  task_id = data.get("task_id", "")
218
  if task_id:
219
- task_engine.cancel(task_id)
220
 
221
  except WebSocketDisconnect:
222
- ws_manager.disconnect(websocket, session_id)
223
 
224
 
225
  async def _run_ws_task(message: str, task_id: str, session_id: str):
@@ -230,12 +235,12 @@ async def _run_ws_task(message: str, task_id: str, session_id: str):
230
  task_id=task_id,
231
  session_id=session_id,
232
  )
233
- await ws_manager.emit_task(session_id, "task_complete", {
234
  "task_id": task_id,
235
  "result": result[:2000] if result else "",
236
  })
237
  except Exception as e:
238
- await ws_manager.emit_task(session_id, "task_error", {
239
  "task_id": task_id,
240
  "error": str(e),
241
  })
@@ -283,7 +288,6 @@ async def orchestrate_goal(request: Request):
283
 
284
  task_id = uuid.uuid4().hex[:12]
285
 
286
- # Add computer-use step
287
  add_computer_use_step(session_id, "thinking", {
288
  "message": f"Processing: {message[:100]}",
289
  "task_id": task_id,
@@ -377,31 +381,31 @@ async def list_agents():
377
  return {"agents": agents_list, "total": len(agents_list)}
378
 
379
 
380
- # ─── Spaces Status (Real 22-space status) ────────────────────────────────────
381
 
382
  SPACE_DEFS = [
383
- {"id": "god-core", "name": "God Core Space", "role": "orchestration", "agent": "orchestrator", "icon": "🧠"},
384
- {"id": "coding", "name": "Coding Worker", "role": "code_generation", "agent": "coding", "icon": "⚑"},
385
- {"id": "sandbox", "name": "Sandbox Worker", "role": "execution", "agent": "sandbox", "icon": "πŸ”§"},
386
- {"id": "terminal", "name": "Terminal Worker", "role": "execution", "agent": "sandbox", "icon": "πŸ–₯️"},
387
- {"id": "filesystem", "name": "FileSystem Worker", "role": "files", "agent": "file", "icon": "πŸ“"},
388
- {"id": "browser", "name": "Browser Worker", "role": "research", "agent": "browser", "icon": "🌐"},
389
- {"id": "vision", "name": "Vision Worker", "role": "ui_gen", "agent": "vision", "icon": "πŸ‘οΈ"},
390
- {"id": "ui", "name": "UI Worker", "role": "ui", "agent": "ui", "icon": "🎨"},
391
- {"id": "debug", "name": "Debug Worker", "role": "debugging", "agent": "debug", "icon": "πŸ›"},
392
- {"id": "test", "name": "Test Worker", "role": "testing", "agent": "test", "icon": "πŸ§ͺ"},
393
- {"id": "verification", "name": "Verification Worker", "role": "qa", "agent": "test", "icon": "βœ…"},
394
- {"id": "git", "name": "Git Worker", "role": "git", "agent": "git", "icon": "πŸ”€"},
395
- {"id": "deploy", "name": "Deploy Worker", "role": "deployment", "agent": "deploy", "icon": "πŸš€"},
396
- {"id": "connector", "name": "Connector Worker", "role": "integration", "agent": "connector", "icon": "πŸ”Œ"},
397
- {"id": "memory", "name": "Memory Worker", "role": "memory", "agent": "memory", "icon": "πŸ’Ύ"},
398
- {"id": "knowledge", "name": "Knowledge Worker", "role": "knowledge", "agent": "memory", "icon": "πŸ“š"},
399
- {"id": "workflow", "name": "Workflow Worker", "role": "automation", "agent": "workflow", "icon": "βš™οΈ"},
400
- {"id": "eventbus", "name": "Event Bus", "role": "events", "agent": None, "icon": "πŸ“‘"},
401
- {"id": "model-router", "name": "Model Router", "role": "ai_routing", "agent": None, "icon": "πŸ€–"},
402
- {"id": "observability", "name": "Observability", "role": "monitoring", "agent": None, "icon": "πŸ“Š"},
403
- {"id": "session-runtime", "name": "Session Runtime", "role": "sessions", "agent": None, "icon": "⏱️"},
404
- {"id": "auth-gateway", "name": "Auth Gateway", "role": "auth", "agent": None, "icon": "πŸ”"},
405
  ]
406
 
407
 
@@ -415,7 +419,7 @@ async def get_spaces():
415
  spaces_status.append({
416
  **space,
417
  "status": "active" if (agent is not None or agent_name is None) else "inactive",
418
- "online": True, # Running in this backend
419
  "backend": "god-agent-os-v11",
420
  "tasks_completed": 0,
421
  })
 
2
  πŸš€ GOD AGENT OS v11 β€” 100% Working Autonomous Engineering OS
3
  God Mode: Plan + Code + Debug + Deploy + Browse + Git + Memory
4
  Real streaming, real agents, real computer-use events
5
+
6
+ FIXED BUGS:
7
+ - TaskEngine constructor: only takes ws_manager (not ai_router)
8
+ - init_db: no argument needed
9
+ - task_engine.run() β†’ task_engine.start()
10
+ - ws_manager.emit_task() β†’ ws_manager.emit()
11
+ - connector_manager.initialize() β†’ not needed (sync init)
12
+ - WebSocket: connect(websocket, session_id) vs connect(websocket, room)
13
  """
14
 
15
  import asyncio
 
82
  connector_manager: ConnectorManager = None
83
 
84
  # ─── Computer-Use Event Stream (Manus-style) ──────────────────────────────────
 
85
  computer_use_sessions: Dict[str, List[Dict]] = {}
86
 
87
 
 
96
  "timestamp": time.time(),
97
  "status": "running",
98
  })
 
99
  computer_use_sessions[session_id] = computer_use_sessions[session_id][-100:]
100
 
101
 
 
105
 
106
  log.info("πŸš€ God Agent OS v11 starting up...")
107
 
108
+ # Initialize DB (no arguments needed)
109
+ await init_db()
 
110
 
111
  # Initialize AI Router
112
  ai_router = AIRouterV10()
 
114
  # WebSocket Manager
115
  ws_manager = WebSocketManager()
116
 
117
+ # Task Engine (only takes ws_manager β€” NOT ai_router)
118
+ task_engine = TaskEngine(ws_manager)
119
 
120
  # Agent Fleet
121
  orchestrator = GodAgentOrchestratorV7(ws_manager, ai_router)
 
140
  for name, agent in agents_map.items():
141
  orchestrator.register_agent(name, agent)
142
 
143
+ # Connector Manager (sync init β€” no await needed)
144
  connector_manager = ConnectorManager()
 
145
 
146
  # Attach to app state
147
  app.state.ws_manager = ws_manager
 
150
  app.state.orchestrator = orchestrator
151
  app.state.connector_manager = connector_manager
152
 
153
+ # Start task engine using start() method (not run())
154
+ asyncio.create_task(task_engine.start())
155
 
156
  log.info("βœ… God Agent OS v11 ready!", agents=len(agents_map))
157
  yield
158
 
159
  log.info("Shutting down God Agent OS v11...")
160
+ await task_engine.stop()
161
 
162
 
163
  # ─── App ──────────────────────────────────────────────────────────────────────
 
196
 
197
  @app.websocket("/ws/{session_id}")
198
  async def websocket_endpoint(websocket: WebSocket, session_id: str):
199
+ # ws_manager.connect uses room-based system, use session_id as room
200
+ await ws_manager.connect(websocket, f"chat:{session_id}")
201
  try:
202
  while True:
203
  data = await websocket.receive_json()
 
207
  await websocket.send_json({"type": "pong", "ts": time.time()})
208
 
209
  elif event_type == "message":
 
210
  message = data.get("message", "")
211
  task_id = uuid.uuid4().hex[:12]
212
+ # emit uses room-based broadcast
213
+ await ws_manager.emit_chat(session_id, "task_start", {
214
  "task_id": task_id,
215
  "message": message[:100],
216
  })
 
217
  asyncio.create_task(
218
  _run_ws_task(message, task_id, session_id)
219
  )
 
221
  elif event_type == "stop":
222
  task_id = data.get("task_id", "")
223
  if task_id:
224
+ await task_engine.cancel(task_id)
225
 
226
  except WebSocketDisconnect:
227
+ ws_manager.disconnect(websocket, f"chat:{session_id}")
228
 
229
 
230
  async def _run_ws_task(message: str, task_id: str, session_id: str):
 
235
  task_id=task_id,
236
  session_id=session_id,
237
  )
238
+ await ws_manager.emit_chat(session_id, "task_complete", {
239
  "task_id": task_id,
240
  "result": result[:2000] if result else "",
241
  })
242
  except Exception as e:
243
+ await ws_manager.emit_chat(session_id, "task_error", {
244
  "task_id": task_id,
245
  "error": str(e),
246
  })
 
288
 
289
  task_id = uuid.uuid4().hex[:12]
290
 
 
291
  add_computer_use_step(session_id, "thinking", {
292
  "message": f"Processing: {message[:100]}",
293
  "task_id": task_id,
 
381
  return {"agents": agents_list, "total": len(agents_list)}
382
 
383
 
384
+ # ─── Spaces Status ────────────────────────────────────────────────────────────
385
 
386
  SPACE_DEFS = [
387
+ {"id": "god-core", "name": "God Core Space", "role": "orchestration", "agent": "orchestrator", "icon": "🧠"},
388
+ {"id": "coding", "name": "Coding Worker", "role": "code_generation","agent": "coding", "icon": "⚑"},
389
+ {"id": "sandbox", "name": "Sandbox Worker", "role": "execution", "agent": "sandbox", "icon": "πŸ”§"},
390
+ {"id": "terminal", "name": "Terminal Worker", "role": "execution", "agent": "sandbox", "icon": "πŸ–₯️"},
391
+ {"id": "filesystem", "name": "FileSystem Worker", "role": "files", "agent": "file", "icon": "πŸ“"},
392
+ {"id": "browser", "name": "Browser Worker", "role": "research", "agent": "browser", "icon": "🌐"},
393
+ {"id": "vision", "name": "Vision Worker", "role": "ui_gen", "agent": "vision", "icon": "πŸ‘οΈ"},
394
+ {"id": "ui", "name": "UI Worker", "role": "ui", "agent": "ui", "icon": "🎨"},
395
+ {"id": "debug", "name": "Debug Worker", "role": "debugging", "agent": "debug", "icon": "πŸ›"},
396
+ {"id": "test", "name": "Test Worker", "role": "testing", "agent": "test", "icon": "πŸ§ͺ"},
397
+ {"id": "verification", "name": "Verification Worker", "role": "qa", "agent": "test", "icon": "βœ…"},
398
+ {"id": "git", "name": "Git Worker", "role": "git", "agent": "git", "icon": "πŸ”€"},
399
+ {"id": "deploy", "name": "Deploy Worker", "role": "deployment", "agent": "deploy", "icon": "πŸš€"},
400
+ {"id": "connector", "name": "Connector Worker", "role": "integration", "agent": "connector", "icon": "πŸ”Œ"},
401
+ {"id": "memory", "name": "Memory Worker", "role": "memory", "agent": "memory", "icon": "πŸ’Ύ"},
402
+ {"id": "knowledge", "name": "Knowledge Worker", "role": "knowledge", "agent": "memory", "icon": "πŸ“š"},
403
+ {"id": "workflow", "name": "Workflow Worker", "role": "automation", "agent": "workflow", "icon": "βš™οΈ"},
404
+ {"id": "eventbus", "name": "Event Bus", "role": "events", "agent": None, "icon": "πŸ“‘"},
405
+ {"id": "model-router", "name": "Model Router", "role": "ai_routing", "agent": None, "icon": "πŸ€–"},
406
+ {"id": "observability", "name": "Observability", "role": "monitoring", "agent": None, "icon": "πŸ“Š"},
407
+ {"id": "session-runtime", "name": "Session Runtime", "role": "sessions", "agent": None, "icon": "⏱️"},
408
+ {"id": "auth-gateway", "name": "Auth Gateway", "role": "auth", "agent": None, "icon": "πŸ”"},
409
  ]
410
 
411
 
 
419
  spaces_status.append({
420
  **space,
421
  "status": "active" if (agent is not None or agent_name is None) else "inactive",
422
+ "online": True,
423
  "backend": "god-agent-os-v11",
424
  "tasks_completed": 0,
425
  })