# vercel-labs/open-agents architecture

> Architecture diagram of the GitHub repository vercel-labs/open-agents, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vercel-labs/open-agents
- Repository: https://github.com/vercel-labs/open-agents

## Overview

1. **Overall shape**
   This is a monorepo with three core runtime layers: the **Next.js web app** in `apps/web`, the **agent runtime** in `packages/agent`, and the **sandbox abstraction** in `packages/sandbox`. `packages/shared` holds UI/runtime primitives used by both the web app and agent-facing code.

2. **Web app as control plane**
   `apps/web` is the orchestration and presentation layer. It owns user-facing pages, React components, and a large set of App Router API routes for auth, sessions, chats, GitHub, sandbox control, settings, and PR/merge operations. It is also where durable chat workflows are started and monitored rather than executing agent logic inline.

3. **Durable agent execution**
   The agent itself lives in `packages/agent`. It defines the system prompt, models, tool registry, subagents, skill loading/discovery, and context-management logic. The agent is designed to run outside the sandbox and interact with it through tools like read/write/search/shell/task, which keeps “reasoning and planning” separate from “code execution.”

4. **Sandbox boundary**
   `packages/sandbox` and `apps/web/lib/sandbox` define the execution environment boundary: filesystem, git, shell, dev servers, and preview ports. The README makes the key architectural point explicit: the agent does **not** run inside the VM. Sandboxes can hibernate, resume from snapshot, and be reconnected to independently of the agent workflow.

5. **Main request flow**
   A chat request in `apps/web/app/api/chat` starts a workflow-backed run. The workflow persists state across steps, streams partial results back to the UI, and can be resumed by reconnecting to the same run. This is the central data flow: **user action → API route → workflow run → agent tools → sandbox state changes → persisted updates/streamed UI**.

6. **Session and chat state**
   Sessions, chats, messages, files, diffs, read state, sharing, and skill selection are modeled through API routes under `apps/web/app/api/sessions/...` and backed by database helpers in `apps/web/lib/db`. The app uses Postgres via Drizzle migrations/schemas, and caches some session state for faster reload/reconnect behavior.

7. **Git and repository operations**
   GitHub integration is a first-class subsystem. The app supports repo installation, branch selection, cloning, pushes, webhooks, PR creation, PR closure, merge readiness, and repo metadata lookup. The web layer handles auth and API coordination, while the sandbox performs the actual repository work during agent runs.

8. **Authentication and identity**
   There are two auth domains: **Vercel OAuth** for app sign-in and **GitHub App-based auth** for repo access and installation management. Token material is encrypted with app secrets, and several API routes manage reconnect/unlink/signout/callback flows. Identity is therefore split between “who is using the app” and “which repos/services the app can operate on.”

9. **Post-run automation**
   After a chat finishes, workflow helpers in `apps/web/app/workflows` can auto-commit, generate commit messages, create PRs, and poll PR/deployment readiness depending on user preferences. These are not always-on behaviors; they are gated by session/user settings and become part of the post-finish workflow rather than the main agent turn.

10. **UI surfaces**
   The UI is organized around sessions, chats, a codespace view, shared read-only views, and settings pages. The session/chat screen is the primary operating surface, with specialized components for diffs, file trees, git panels, model selection, sandbox status, and tool-call rendering. Shared links render a redacted, read-only subset of the same conversation data.

11. **Cross-cutting shared packages**
   `packages/shared` contains reusable state/context helpers and diff/tool-state utilities. These are used to keep the agent output representation, chat UI, and shared/read-only views consistent, especially for rendering tool calls, reasoning blocks, and diff-related state.

12. **External services and infra**
   The architecture depends materially on **Postgres** for durable app state, **Vercel** for hosting/workflows/sandboxes and OAuth, **GitHub** for repo access and PRs, and optionally **Redis/KV** for caching skills and metadata. **ElevenLabs** is optional for voice transcription. These services form the main system boundaries visible in the repository.

Main entry points: [`apps/web`](https://github.com/vercel-labs/open-agents/tree/main/apps/web) (Web app), [`apps/web/lib`](https://github.com/vercel-labs/open-agents/tree/main/apps/web/lib) (Web libs), [`packages/sandbox`](https://github.com/vercel-labs/open-agents/tree/main/packages/sandbox) (Sandbox runtime), [`packages/agent`](https://github.com/vercel-labs/open-agents/tree/main/packages/agent) (Agent runtime)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_apps["Apps"]
  node_web_app["Web app<br/>Next.js control plane"]
  node_chat_api["Chat API<br/>workflow-backed runs"]
  node_session_api["Session API<br/>session state"]
  node_github_api["GitHub API<br/>repo integration"]
  node_sandbox_api["Sandbox API<br/>sandbox control"]
  node_auth_api["Auth API<br/>identity flows"]
  node_workflow_layer["Workflows<br/>post-run automation"]
  node_ui_surface["Chat UI<br/>session workspace"]
  node_web_lib["Web libs<br/>app services"]
end

subgraph group_packages["Packages"]
  node_agent_pkg["Agent runtime<br/>LLM agent"]
  node_agent_tools["Agent tools<br/>tooling"]
  node_agent_skills["Agent skills<br/>skill loading"]
  node_context_mgmt["Context mgmt<br/>memory control"]
  node_sandbox_pkg["Sandbox runtime<br/>execution boundary"]
  node_shared_pkg["Shared package<br/>ui/runtime primitives"]
end

subgraph group_infra["Infra"]
  node_postgres[("Postgres<br/>durable state")]
  node_github["GitHub<br/>external repo host"]
  node_vercel["Vercel<br/>hosting runtime"]
  node_redis[("Redis/KV<br/>cache")]
  node_elevenlabs["Voice API<br/>optional transcription"]
end

node_web_app -->|"serves"| node_chat_api
node_web_app -->|"serves"| node_session_api
node_web_app -->|"serves"| node_github_api
node_web_app -->|"serves"| node_sandbox_api
node_web_app -->|"serves"| node_auth_api
node_web_app -->|"runs"| node_workflow_layer
node_web_app -->|"renders"| node_ui_surface
node_web_app -->|"uses"| node_web_lib
node_chat_api -->|"invokes"| node_agent_pkg
node_chat_api -->|"controls"| node_sandbox_pkg
node_session_api -->|"persists"| node_postgres
node_session_api -->|"reads/writes"| node_sandbox_pkg
node_github_api -->|"integrates"| node_github
node_github_api -->|"persists"| node_postgres
node_sandbox_api -->|"manages"| node_sandbox_pkg
node_workflow_layer -->|"updates"| node_postgres
node_workflow_layer -->|"creates PRs"| node_github
node_agent_pkg -->|"uses"| node_agent_tools
node_agent_pkg -->|"loads"| node_agent_skills
node_agent_pkg -->|"manages"| node_context_mgmt
node_agent_tools -->|"acts on"| node_sandbox_pkg
node_agent_tools -->|"shares state"| node_shared_pkg
node_web_lib -->|"uses"| node_postgres
node_web_lib -->|"calls"| node_github
node_web_lib -->|"calls"| node_vercel
node_web_lib -->|"caches"| node_redis
node_web_lib -->|"orchestrates"| node_sandbox_pkg
node_web_lib -->|"reuses"| node_shared_pkg
node_sandbox_pkg -->|"backs onto"| node_vercel
node_shared_pkg -->|"feeds UI"| node_web_app
node_web_lib -.->|"optional"| node_elevenlabs

click node_web_app "https://github.com/vercel-labs/open-agents/tree/main/apps/web"
click node_chat_api "https://github.com/vercel-labs/open-agents/tree/main/apps/web/app/api/chat"
click node_session_api "https://github.com/vercel-labs/open-agents/tree/main/apps/web/app/api/sessions"
click node_github_api "https://github.com/vercel-labs/open-agents/tree/main/apps/web/app/api/github"
click node_sandbox_api "https://github.com/vercel-labs/open-agents/tree/main/apps/web/app/api/sandbox"
click node_auth_api "https://github.com/vercel-labs/open-agents/tree/main/apps/web/app/api/auth"
click node_workflow_layer "https://github.com/vercel-labs/open-agents/tree/main/apps/web/app/workflows"
click node_ui_surface "https://github.com/vercel-labs/open-agents/tree/main/apps/web/app/sessions"
click node_web_lib "https://github.com/vercel-labs/open-agents/tree/main/apps/web/lib"
click node_agent_pkg "https://github.com/vercel-labs/open-agents/tree/main/packages/agent"
click node_agent_tools "https://github.com/vercel-labs/open-agents/tree/main/packages/agent/tools"
click node_agent_skills "https://github.com/vercel-labs/open-agents/tree/main/packages/agent/skills"
click node_context_mgmt "https://github.com/vercel-labs/open-agents/tree/main/packages/agent/context-management"
click node_sandbox_pkg "https://github.com/vercel-labs/open-agents/tree/main/packages/sandbox"
click node_shared_pkg "https://github.com/vercel-labs/open-agents/tree/main/packages/shared"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_web_app,node_chat_api,node_session_api,node_github_api,node_sandbox_api,node_auth_api,node_workflow_layer,node_ui_surface,node_web_lib toneBlue
class node_agent_pkg,node_agent_tools,node_agent_skills,node_context_mgmt,node_sandbox_pkg,node_shared_pkg toneAmber
class node_postgres,node_github,node_vercel,node_redis,node_elevenlabs toneMint
```

## Components

### Apps

Runtime applications and user-facing surfaces

- [Web app](https://github.com/vercel-labs/open-agents/tree/main/apps/web): Next.js control plane · User-facing orchestration layer with pages, API routes, workflows, and UI · `apps/web`
- [Chat API](https://github.com/vercel-labs/open-agents/tree/main/apps/web/app/api/chat): workflow-backed runs · Starts, streams, stops, and persists durable chat runs · `apps/web/app/api/chat`
- [Session API](https://github.com/vercel-labs/open-agents/tree/main/apps/web/app/api/sessions): session state · CRUD and actions for sessions, chats, files, diffs, skills, sharing, and PR-related state · `apps/web/app/api/sessions`
- [GitHub API](https://github.com/vercel-labs/open-agents/tree/main/apps/web/app/api/github): repo integration · Auth, installations, repo lookup, webhooks, branches, and repo creation flows · `apps/web/app/api/github`
- [Sandbox API](https://github.com/vercel-labs/open-agents/tree/main/apps/web/app/api/sandbox): sandbox control · Lifecycle, reconnect, snapshot, status, and dev-server endpoints for sandbox management · `apps/web/app/api/sandbox`
- [Auth API](https://github.com/vercel-labs/open-agents/tree/main/apps/web/app/api/auth): identity flows · Vercel sign-in and GitHub connect/reconnect/unlink/signout callbacks and routes · `apps/web/app/api/auth`
- [Workflows](https://github.com/vercel-labs/open-agents/tree/main/apps/web/app/workflows): post-run automation · Chat finish handling, auto-commit, PR generation, sandbox lifecycle, and usage updates · `apps/web/app/workflows`
- [Chat UI](https://github.com/vercel-labs/open-agents/tree/main/apps/web/app/sessions): session workspace · Primary session and codespace views with diffs, git panels, tool rendering, and shared read-only views · `apps/web/app/sessions`
- [Web libs](https://github.com/vercel-labs/open-agents/tree/main/apps/web/lib): app services · Database, GitHub, Vercel, sandbox, model, skill, and streaming helpers used by the web app · `apps/web/lib`

### Packages

Shared runtime packages and core execution layers

- [Agent runtime](https://github.com/vercel-labs/open-agents/tree/main/packages/agent): LLM agent · System prompt, model wiring, tool registry, subagents, skills, and context management · `packages/agent`
- [Agent tools](https://github.com/vercel-labs/open-agents/tree/main/packages/agent/tools): tooling · Read/write/search/shell/task-style tools that act on the sandbox and repo · `packages/agent/tools`
- [Agent skills](https://github.com/vercel-labs/open-agents/tree/main/packages/agent/skills): skill loading · Discovery and loading of reusable skills and subagent behaviors · `packages/agent/skills`
- [Context mgmt](https://github.com/vercel-labs/open-agents/tree/main/packages/agent/context-management): memory control · Conversation compaction and cache-control for long-running runs · `packages/agent/context-management`
- [Sandbox runtime](https://github.com/vercel-labs/open-agents/tree/main/packages/sandbox): execution boundary · Abstract sandbox interface plus Vercel-backed filesystem, shell, git, and snapshot management · `packages/sandbox`
- [Shared package](https://github.com/vercel-labs/open-agents/tree/main/packages/shared): ui/runtime primitives · Shared hooks and diff/tool-state utilities for consistent rendering and state handling · `packages/shared`

### Infra

External services and persistence boundaries

- **Postgres**: durable state · Primary database for sessions, chats, accounts, installs, usage, and workflow runs
- **GitHub**: external repo host · Repository source of truth, auth domain, webhooks, pull requests, and merges
- **Vercel**: hosting runtime · Hosting, OAuth, workflows, and sandbox infrastructure backing the application
- **Redis/KV**: cache · Optional cache for skills and metadata
- **Voice API**: optional transcription · Optional voice transcription integration

## Connections

- Web app → Chat API: serves · Chat requests and streaming run through the API layer
- Web app → Session API: serves · Session pages depend on session, diff, files, skills, and sharing endpoints
- Web app → GitHub API: serves · UI drives GitHub connection, repo selection, and PR operations
- Web app → Sandbox API: serves · UI inspects and controls sandbox lifecycle and status
- Web app → Auth API: serves · Sign-in and reconnect flows are handled by web routes
- Web app → Workflows: runs · Workflow helpers coordinate chat completion and follow-up actions
- Web app → Chat UI: renders · Pages and components compose the session workspace and codespace views
- Web app → Web libs: uses · The app relies on internal libs for persistence, integrations, and runtime helpers
- Chat API → Agent runtime: invokes · Workflow-backed runs delegate reasoning, tool selection, and skill use to the agent
- Chat API → Sandbox runtime: controls · Chat runs operate on sandboxes through the boundary package
- Session API → Postgres: persists · Sessions, chats, messages, and related state are stored durably
- Session API → Sandbox runtime: reads/writes · Session operations query files, diffs, and sandbox state
- GitHub API → GitHub: integrates · Repo auth, installs, webhooks, branches, and metadata come from GitHub
- GitHub API → Postgres: persists · Installation and account linkage state is stored in the database
- Sandbox API → Sandbox runtime: manages · API routes wrap sandbox lifecycle and snapshot operations
- Workflows → Postgres: updates · Post-finish automation records workflow and session state
- Workflows → GitHub: creates PRs · Automation can commit, open PRs, and poll merge/deployment readiness
- Agent runtime → Agent tools: uses · The agent reasons through the tool registry
- Agent runtime → Agent skills: loads · Skills are discovered and loaded into the agent runtime
- Agent runtime → Context mgmt: manages · Context management trims and preserves long-running conversation state
- Agent tools → Sandbox runtime: acts on · Shell, read, write, grep, glob, and task tools manipulate the sandboxed repo
- Agent tools → Shared package: shares state · Tool-call and diff state stay consistent across agent and UI surfaces
- Web libs → Postgres: uses · Database helpers, schemas, and caches back app state
- Web libs → GitHub: calls · GitHub client and auth helpers coordinate with GitHub APIs
- Web libs → Vercel: calls · OAuth, project, and deployment helpers integrate with Vercel
- Web libs → Redis/KV: caches · Skills and metadata may be cached in Redis/KV
- Web libs → Sandbox runtime: orchestrates · Web-side sandbox lifecycle helpers coordinate reconnect and persistence
- Web libs → Shared package: reuses · Shared diff and tool-state primitives support UI rendering and state sync
- Sandbox runtime → Vercel: backs onto · The concrete sandbox implementation is Vercel-backed
- Shared package → Web app: feeds UI · Shared hooks and state utilities power conversation and diff rendering
- Web libs → Voice API: optional · Voice transcription is an optional external integration
