How vercel-labs/open-agents works
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: web Web app · lib Web libs · sandbox Sandbox runtime · agent Agent runtime
Components 20
Apps
Runtime applications and user-facing surfaces
- Web app · User-facing orchestration layer with pages, API routes, workflows, and UI
apps/web - Chat API · Starts, streams, stops, and persists durable chat runs
apps/web/app/api/chat - Session API · CRUD and actions for sessions, chats, files, diffs, skills, sharing, and PR-related state
apps/web/app/api/sessions - GitHub API · Auth, installations, repo lookup, webhooks, branches, and repo creation flows
apps/web/app/api/github - Sandbox API · Lifecycle, reconnect, snapshot, status, and dev-server endpoints for sandbox management
apps/web/app/api/sandbox - Auth API · Vercel sign-in and GitHub connect/reconnect/unlink/signout callbacks and routes
apps/web/app/api/auth - Workflows · Chat finish handling, auto-commit, PR generation, sandbox lifecycle, and usage updates
apps/web/app/workflows - Chat UI · Primary session and codespace views with diffs, git panels, tool rendering, and shared read-only views
apps/web/app/sessions - Web libs · 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 · System prompt, model wiring, tool registry, subagents, skills, and context management
packages/agent - Agent tools · Read/write/search/shell/task-style tools that act on the sandbox and repo
packages/agent/tools - Agent skills · Discovery and loading of reusable skills and subagent behaviors
packages/agent/skills - Context mgmt · Conversation compaction and cache-control for long-running runs
packages/agent/context-management - Sandbox runtime · Abstract sandbox interface plus Vercel-backed filesystem, shell, git, and snapshot management
packages/sandbox - Shared package · Shared hooks and diff/tool-state utilities for consistent rendering and state handling
packages/shared
Infra
External services and persistence boundaries
- Postgres · Primary database for sessions, chats, accounts, installs, usage, and workflow runs
- GitHub · Repository source of truth, auth domain, webhooks, pull requests, and merges
- Vercel · Hosting, OAuth, workflows, and sandbox infrastructure backing the application
- Redis/KV · Optional cache for skills and metadata
- Voice API · Optional voice transcription integration
Connections 31
- 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