Watch the demo on YouTube: https://youtu.be/RqlTGsb4JtA
SpiderBot AI — a real-time AI agent chat platform using Cloudflare Workers AI, Durable Objects, and WebSockets.
This project was intentionally built on Cloudflare to leverage features that are difficult to replicate with traditional serverless platforms.
- Workers enable low-latency execution close to users without managing servers.
- Durable Objects provide strongly consistent, per-user state, making them ideal for AI agents with conversational memory.
- Workers AI allows LLM inference at the edge without managing API keys or external model providers.
- WebSocket support in Workers enables real-time, bidirectional communication in a serverless environment.
These primitives together enable a real-time, stateful AI agent architecture that aligns closely with Cloudflare’s edge-first design philosophy.
Each user is routed to a dedicated Durable Object instance, which acts as a stateful AI agent. This ensures strong consistency for conversational memory while allowing horizontal scaling across users.
- Workers AI calls are executed remotely and may incur usage costs.
- Conversation history is intentionally trimmed to control token usage.
- The project avoids unrestricted model access and does not grant the LLM direct internet access.
- React
- TypeScript
- Vite
- Tailwind CSS
- shadcn/ui
- Cloudflare Workers
- Cloudflare Durable Objects
- Cloudflare Workers AI
- WebSockets
- TypeScript
. ├─ spider-chat-interface-frontend/ # Frontend (React) │ ├─ src/ │ └─ package.json │ ├─ spider-chat-interface-backend/ │ └─ my-ws-memory-bot/ # Backend (Cloudflare Worker) │ ├─ src/ │ │ ├─ index.ts │ │ └─ agent.ts │ ├─ wrangler.jsonc │ └─ package.json
- Node.js (18+)
- npm
- Cloudflare account (for Workers AI)
cd spider-chat-interface-backend/my-ws-memory-bot
npm install
npm run devThe backend worker typically runs on:
cd spider-chat-interface-frontend
npm install
npm run devOpen the app in your browser (Vite default):
🧪 Example WebSocket Test
npx wscat -c ws://127.0.0.1:8787/agents/chatbot/demo-userSend a user message payload:
{ "type": "user_message", "content": "Hello!" }📌 Future Improvements
- Long-term chat storage (D1 or SQLite analytics)
- Tool calling (search, APIs, RAG)
- Streaming token responses
- Authentication and rate limiting
- Multi-conversation chat sessions
