How openswarm-ai/openswarm works
1. Overall shape
- Open Swarm is a local desktop orchestrator, not a traditional web app.
- The runtime is split into three main boundaries: Electron shell for packaging and native integration, React/TypeScript frontend for all user interaction, and a FastAPI/Python backend for orchestration, persistence, and agent execution.
2. Electron as the desktop host
- electron/main.js is the top-level desktop entry point.
- It owns app startup, auto-updates, packaging, and the bundled Python environment.
- The frontend and backend are launched together under Electron during development and in packaged builds, so the desktop app is the actual deployment unit.
3. Frontend responsibilities
- The frontend/ app is the primary UI layer: dashboard canvas, agent chat, skills/tools/modes/settings, and output editors.
- It is state-heavy and uses Redux slices under frontend/src/shared/state to model agents, dashboards, models, tools, modes, skills, sessions, streaming state, and updates.
- A dedicated WebSocket manager and shared hooks connect UI state to live backend events.
4. Backend responsibilities
- backend/main.py starts a FastAPI service on the local machine.
- The backend exposes REST endpoints for CRUD/configuration and WebSocket endpoints for streaming agent activity and approvals.
- It also owns persistent local storage, session lifecycle, tool discovery, registry proxies, and file-system coordination.
5. Agent orchestration is the core subsystem
- backend/apps/agents/ is the orchestration layer for launching, managing, and monitoring agents.
- It handles agent lifecycle, streaming output, approval gating, retries, metrics, history, and specialized browser/invoke workflows.
- The design is centered on parallel sessions: each agent can run independently while the UI aggregates their status into one workspace.
6. Conversation and tool-call streaming
- The live chat experience is driven by backend-to-frontend streaming over WebSockets.
- Streaming includes token deltas, tool calls, approvals, cost updates, and session events.
- The frontend renders this as chat bubbles, tool bubbles, approval bars, and branch navigation, while the backend remains the source of truth for execution state.
7. Git worktree isolation is a key architectural boundary
- The backend’s session and workspace code manages isolated git worktrees per agent.
- This lets multiple agents work in parallel without overwriting each other’s branch state.
- The UI exposes that isolation through the dashboard, diff viewer, and session navigation, but the actual filesystem/branch mechanics live in the backend.
8. Dashboard and spatial workspace
- backend/apps/dashboards, dashboard_layout, and the frontend dashboard pages together implement the “spatial canvas” model.
- Dashboard state is persisted separately from agent sessions so users can arrange cards, open browser/view/agent cards, and resume layouts.
- The dashboard is the main coordination surface, while chat is the detailed interaction surface.
9. Tools, MCP, and external integrations
- backend/apps/tools_lib, mcp_registry, discord_mcp_shim, and google_workspace_mcp_shim cover tool discovery and integration.
- The system supports MCP servers over stdio, HTTP, and SSE, with OAuth support where needed.
- Tool policy, discovery, and registry browsing are first-class, because agent capabilities depend on which tools are connected and allowed.
10. Modes, skills, and prompt composition
- backend/apps/modes, skills, and the prompt manager under backend/apps/agents/manager/prompt define how agents are instructed.
- Modes constrain system prompts and tool access; skills are synced and surfaced for reuse; prompt templates/attachments shape individual runs.
- This is a control-plane layer for agent behavior, separate from the execution/runtime layer.
11. Views and outputs form a second runtime surface
- backend/apps/outputs generates and runs interactive artifacts, including HTML/JS/CSS views and backend-backed runtime processes.
- The frontend has dedicated editors, previews, run dialogs, and code panels for this subsystem.
- This is distinct from agent chat: it is for produced artifacts and live preview, not just conversation.
12. Local persistence and configuration
- Most app state is local and file-based rather than database-backed.
- backend/config and backend/apps/settings manage install IDs, JSON stores, credentials, redaction, and app settings.
- The frontend settings pages map directly onto these backend stores, so config changes are persisted locally and reloaded across restarts.
13. Optional cloud/external dependencies
- The product is “100% local” in the sense that the orchestration stack runs on the user machine, but it still depends on external services when enabled.
- Key outside integrations include Anthropic/Claude APIs for model access, GitHub Releases for updates, Google OAuth for Workspace tools, and package/proxy registries for MCP and skills discovery.
14. Support systems and release pipeline
- openswarm-edge/ is a separate edge/sandbox service used for hosted or published output scenarios, not the main desktop runtime.
- linter/, scripts/, e2e/, and the large backend test suite show that architecture is guarded by repo-level checks, smoke tests, and release verification.
- This repo is built like a desktop platform: core runtime, integration shims, artifact publishing, and strong CI/release gating.
Main entry points: Main.tsx App shell · main.py FastAPI main · store.ts Redux state · agent_manager.py Agent runtime
Components 21
Desktop host
Electron packaging, native integration, and app launch
- Electron main · Top-level desktop entry point for startup, updates, and bundled runtime launch
electron/main.js - Preload · IPC and webview bridge into the desktop shell
electron/preload.js
Frontend
React/TypeScript UI and client state
- App shell · Root UI composition and cross-page layout
frontend/src/app/Main.tsx - Dashboard · Canvas-based workspace for cards, agent panes, and layout interactions
frontend/src/app/pages/Dashboard/Dashboard.tsx - Agent chat · Streaming chat surface with approvals, tool bubbles, and branch navigation
frontend/src/app/pages/AgentChat/AgentChat.tsx - Views · Editors and previews for generated interactive artifacts
frontend/src/app/pages/Views/Views.tsx - Tools · Tool connections, registry browsing, and MCP configuration screens
frontend/src/app/pages/Tools/Tools.tsx - Settings · Local app, model, privacy, and subscription settings screens
frontend/src/app/pages/Settings/Settings.tsx - Redux state · Shared slices for agents, dashboards, models, tools, modes, sessions, streaming, and updates
frontend/src/shared/state/store.ts - WebSocket mgr · Client-side live event and streaming connection manager
frontend/src/shared/ws/WebSocketManager.ts
Backend
FastAPI orchestration, persistence, and local APIs
- FastAPI main · Local backend service entry point
backend/main.py - Agent runtime · Launches, monitors, and streams parallel agent sessions
backend/apps/agents/agent_manager.py - Session store · Session lifecycle, history, and isolated git worktrees
backend/apps/agents/manager/session/session_store.py - Dashboard store · Persistent dashboard layouts and spatial workspace state
backend/apps/dashboards/dashboards.py - Outputs runtime · Builds, runs, and publishes interactive output artifacts
backend/apps/outputs/runtime.py - Tool library · Tool taxonomy, MCP config, OAuth tokens, and discovery
backend/apps/tools_lib/tools_lib.py - Settings store · Persistent JSON-backed settings, credentials, redaction, and install identity
backend/apps/settings/settings.py - Swarm core · Shared entity and registry layer for apps, sessions, skills, and workflows
backend/apps/swarm/swarm.py
Integrations
Tool discovery, MCP, OAuth, and external service bridges
- MCP registry · Registry browsing and server discovery for external tools
backend/apps/mcp_registry/mcp_registry.py
Support
Release pipeline, tests, and edge/runtime support
- Edge service · Separate sandbox/edge service for hosted or published outputs
openswarm-edge/app/main.py - CI and release · Linting, E2E, packaging, verification, and release workflows
.github/workflows/release-windows.yml
Connections 30
- Electron main → App shell: launches · Electron starts the desktop UI
- Electron main → FastAPI main: starts · Electron hosts the local backend during development and packaged runs
- Electron main → Preload: bridges · Desktop IPC/webview bridge for the renderer
- App shell → Dashboard: navigates · Main shell exposes the spatial workspace
- App shell → Agent chat: navigates · Main shell exposes agent conversation
- App shell → Views: navigates · Main shell exposes artifact editing and previews
- App shell → Tools: navigates · Main shell exposes integrations management
- App shell → Settings: navigates · Main shell exposes local configuration
- App shell → Redux state: uses · UI pages share centralized client state
- Dashboard → Redux state: reads/writes · Dashboard cards and layout interact with shared state
- Agent chat → Redux state: reads/writes · Chat, streaming, and approvals are state-driven
- Views → Redux state: reads/writes · Artifact editor and preview state is shared
- Tools → Redux state: reads/writes · Tool connections and registry views are state-driven
- Settings → Redux state: reads/writes · Settings forms bind to persisted client state
- Redux state → WebSocket mgr: syncs via · Shared state is updated from live backend events
- WebSocket mgr → FastAPI main: streams · WebSocket channel for tokens, tool calls, approvals, and session events
- FastAPI main → Agent runtime: hosts · Backend exposes orchestration and execution services
- Agent runtime → Session store: uses · Agent runs are isolated by session and git worktree
- Agent runtime → Outputs runtime: drives · Agents can create and run interactive outputs
- FastAPI main → Dashboard store: persists · Dashboard layouts are stored separately from sessions
- FastAPI main → Settings store: persists · Local app and credential configuration lives in file-backed stores
- FastAPI main → Tool library: serves · Backend exposes tool discovery and policy APIs
- Tool library → MCP registry: discovers · Registry-backed MCP server discovery and browsing
- Tool library → Settings store: reads · Tool connections depend on local credentials and config
- Agent runtime → Swarm core: depends on · Execution uses shared swarm/domain entities and registry logic
- Dashboard store → Session store: links · Workspace layout references agent/session state
- Outputs runtime → Edge service: publishes to · Some outputs target the separate edge sandbox runtime
- CI and release → Electron main: verifies · Release pipeline validates desktop packaging and host behavior
- CI and release → FastAPI main: verifies · CI covers backend correctness and API behavior
- CI and release → App shell: verifies · CI covers frontend builds and E2E flows