main.ts entrypoint.
It is a port of the Next.js example into Deno + Hono, showing how to run the same agent stack on Deno Deploy instead of Vercel.
Source: js-deno in the deployment cookbook.
Deploy to Deno Deploy
Create a Deno Deploy project
Fork or clone
langchain-ai/deployment-cookbook. In the Deno Deploy dashboard, create a new project linked to this repo.Configure build settings
- Set Root Directory to
js-deno. - Set the build command to
deno task build:client(builds the Vite SPA intodist/). - Set the entrypoint to
main.ts. - Add
OPENAI_API_KEYin project environment variables.
deno deploy CLI (Deno 2.x). The deploy block in deno.json sets org/app. Change those to your own (or pass --org/--app flags, which override them).
deno task deploy runs deno task build:client && deno deploy --prod, then rm -rf dist. Building locally is required because deno deploy --source local uploads your working tree (minus .gitignore) and does not run build commands. Those only run for GitHub-connected apps.
Optionally enable LangSmith tracing by adding the variables from .env.example.
Required API endpoints
The app exposes the Agent Streaming Protocol under/api/threads/.... Route handlers live in server/routes.ts and mirror the Next.js handlers in js-next/app/api/threads/.
Minimum (streaming chat)
| Method | Path | Purpose |
|---|---|---|
POST | /api/threads/:threadId/commands | Accept protocol commands (run.start, …) and start agent runs |
POST | /api/threads/:threadId/stream | SSE stream of protocol events for a run |
GET / POST | /api/threads/:threadId/state | Read and bootstrap checkpointed thread state |
Optional (sidebar)
| Method | Path | Purpose |
|---|---|---|
GET | /api/threads | List threads known to the checkpointer |
DELETE | /api/threads/:threadId | Delete a thread’s session and checkpoints |
POST | /api/threads/:threadId/history | Paginated checkpoint history (Agent Protocol) |
Request flow
How the Deno backend works
This example runs as a single Deno process:main.ts:Deno.serve+ Hono app. Mounts/apiroutes and serves the Vite-built SPA fromdist/.server/routes.ts: Hono route definitions for the Agent Streaming Protocol.server/session.ts:LocalThreadSession: buffers protocol events in a LangGraphStreamChannel, filters withmatchesSubscription, and fans matching frames out over SSEReadableStream.server/threads.ts: checkpointer-backedgetState/updateState/getHistoryhelpers in the LangGraph SDK wire format.server/registry.ts: process-local singleton owning the agent and one session per thread id.server/agent/: samecreateDeepAgentorchestrator as the Next.js example (researcher + math-whiz subagents, mock tools).
MemorySaver checkpointer. For production persistence across isolates, swap in a durable checkpointer (Postgres, Redis, …). The route handlers and server/threads.ts helpers stay the same.
Production persistence
Out of the box, the agent uses an in-memoryMemorySaver checkpointer (server/agent/index.ts) and a process-local session map (server/registry.ts). That works for local dev and single-isolate deployments, but on Deno Deploy (multiple isolates, cold starts) conversation state is not durable across instances.
Replace MemorySaver in server/agent/index.ts with a durable checkpointer such as @langchain/langgraph-checkpoint-postgres or @langchain/langgraph-checkpoint-redis. You will also want a shared session/replay store so SSE reconnection works across isolates.
Local development
You need Deno 2.x and pnpm for the client./api to the Deno server on port 8000.
For a production-like local run (single server, no HMR):
Project layout
main.ts: Deno Deploy entrypoint (Deno.serve+ Hono).server/agent/: deep agent (createDeepAgent) with subagents and mock tools.server/: protocol server logic:session.ts,threads.ts,serialize.ts,registry.ts,routes.ts.client/: Vite + React SPA (same UI as the Next.js example).dist/: Vite build output served by Deno (generated bydeno task build:client).
See also
Connect these docs to Claude, VSCode, and more via MCP for real-time answers.

