Overview
- Web API is the single entry point for all clients — it handles auth, user data, session/message persistence, credits, tool configuration, and more
- AI Backend receives forwarded agent requests from Web API and executes the Agent loop (LLM reasoning + tool calls)
- Extension / Desktop nodes maintain a direct WebSocket connection to AI Backend’s Gateway for real-time tool execution (browser automation, desktop control)
- Each user has an independent cloud workspace (Supabase Storage / S3) and session state (PostgreSQL Checkpointer)
Two-Tier Backend
Web API (Next.js) — Gateway & Data Layer
The Web API is a Next.js application that serves as the central API gateway for all clients. It owns the database and handles all non-AI concerns:
Key API routes (93 total):
AI Backend (FastAPI) — Agent Execution Engine
The AI Backend is a FastAPI service dedicated to AI Agent orchestration. It receives forwarded requests from the Web API and handles all AI-related operations. The Agent Runtime is the core of the AI Backend — the other modules provide supporting infrastructure around it:
AI Backend API routes:
Components & Data Flow
Request Flow — Agent Invocation
WebSocket Gateway
The Gateway manages all WebSocket connections throughConnectionManager, supporting three node types:
- Extension / Desktop nodes: Each node is uniquely identified by
node_id; a user can have multiple nodes - Web clients: Managed by
user_id; the same user can have multiple Web connections - Tool calls: The Agent initiates JSON-RPC requests via
call_tool(); the Gateway routes requests to the corresponding node and awaits responses (Future-based)
Agent Service
The Agent Service is the core orchestration layer, built on the DeepAgents framework (a higher-level wrapper over LangGraph): Service Layer:Tool System
Zeus tools are organized into four layers:
Connector Tools call chain: Agent → ToolRouter → Gateway → WebSocket → Node → Execute → Return via same path.
Node Management
Node management is handled by three cooperating components:
Each user can have up to 10 nodes; nodes that miss heartbeats are automatically marked offline and deregistered.
Storage & State
Communication Protocols
HTTP SSE (Agent Response Stream)
Agent invocations returntext/event-stream. SSE event types:
WebSocket JSON-RPC 2.0 (Node Tool Calls)
Node tool calls follow the MCP (Model Context Protocol) specification: Request:WebSocket Message Types (Non JSON-RPC)
Startup & Lifecycle
Web API Startup
The Next.js application starts automatically and serves:- All API routes under
/api/* - Web frontend pages under
/[locale]/* - Authentication via Better Auth middleware
AI Backend Startup
Key Environment Variables
Web API (Next.js):
AI Backend (FastAPI):
Health Checks
- AI Backend:
GET /health→{"status": "ok"} - AI Backend:
GET /→{"name": "Zeus Backend API", "version": "1.0.0", "status": "running"}
System Invariants
- JWT Authentication: All Web API routes require a valid JWT Token; AI Backend receives a forwarded token from Web API
- Session Isolation: Each
session_idhas independent Checkpointer state; different sessions do not interfere - Node Heartbeat: Nodes that miss heartbeats for over 60 seconds are automatically marked offline; the Gateway immediately deregisters nodes on disconnect
- Tool Call Timeout: WebSocket tool calls default to 60-second timeout; workflow execution has a 300-second timeout
- SSE Non-Replay: Agent invocation SSE streams are one-time; after disconnect, context must be restored via Checkpointer
- Credit Gate: Web API checks and deducts credits before forwarding any agent request to AI Backend
- Single-Instance Gateway: The current
ConnectionManageris a per-process singleton; WebSocket connections are not shared across processes
Directory Structure
Web API (Next.js):Agent Runtime
Runtime detailed design — Workspace, Session, Modes
Gateway Protocol
Channels & Gateway — Feishu, WebSocket node communication
Tool System
Four-layer tool system — Built-in, MCP, OAuth, Connector
File System
Storage architecture — CloudDriveBackend, Checkpoint