Pyae Sone commited on
Commit Β·
a797e4d
1
Parent(s): 20bdb98
fix(backend): fix all runtime errors in main_v11.py
Browse filesCritical 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
- backend/README.md +28 -15
- backend/main_v11.py +48 -44
backend/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
emoji: π€
|
| 4 |
colorFrom: purple
|
| 5 |
colorTo: indigo
|
|
@@ -9,22 +9,35 @@ license: mit
|
|
| 9 |
app_port: 7860
|
| 10 |
---
|
| 11 |
|
| 12 |
-
# GOD AGENT OS
|
| 13 |
-
**
|
| 14 |
*Powered by Pyae Sone*
|
| 15 |
|
| 16 |
## Runtime Overview
|
| 17 |
-
-
|
| 18 |
-
-
|
| 19 |
-
-
|
| 20 |
-
- WebSocket + REST
|
| 21 |
-
- Backward-compatible legacy agent fleet
|
| 22 |
|
| 23 |
-
##
|
| 24 |
-
- `GET /` β
|
| 25 |
-
- `GET /
|
| 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 |
-
|
| 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
|
| 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.
|
| 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 |
-
|
|
|
|
| 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 |
-
|
|
|
|
| 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.
|
| 234 |
"task_id": task_id,
|
| 235 |
"result": result[:2000] if result else "",
|
| 236 |
})
|
| 237 |
except Exception as e:
|
| 238 |
-
await ws_manager.
|
| 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
|
| 381 |
|
| 382 |
SPACE_DEFS = [
|
| 383 |
-
{"id": "god-core",
|
| 384 |
-
{"id": "coding",
|
| 385 |
-
{"id": "sandbox",
|
| 386 |
-
{"id": "terminal",
|
| 387 |
-
{"id": "filesystem",
|
| 388 |
-
{"id": "browser",
|
| 389 |
-
{"id": "vision",
|
| 390 |
-
{"id": "ui",
|
| 391 |
-
{"id": "debug",
|
| 392 |
-
{"id": "test",
|
| 393 |
-
{"id": "verification",
|
| 394 |
-
{"id": "git",
|
| 395 |
-
{"id": "deploy",
|
| 396 |
-
{"id": "connector",
|
| 397 |
-
{"id": "memory",
|
| 398 |
-
{"id": "knowledge",
|
| 399 |
-
{"id": "workflow",
|
| 400 |
-
{"id": "eventbus",
|
| 401 |
-
{"id": "model-router",
|
| 402 |
-
{"id": "observability",
|
| 403 |
-
{"id": "session-runtime", "name": "Session Runtime",
|
| 404 |
-
{"id": "auth-gateway",
|
| 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,
|
| 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 |
})
|