Multi-user AI Chat with RedwoodSDK RSC and Cloudflare Agents
This is an experimental project, looking at how to live-stream AI responses back to multiple connected clients. All implementations use Cloudflare durable objects and React Server Components (RSC) with RedwoodSDK.
Deployed at https://agents-chat.jldec.me/
-
RSC Chat - Uses RedwoodSDK realtime websockets
-
OpenAI Chat - New! Uses OpenAI Agents SDK
-
Agent Chat - Uses Cloudflare Agents websockets
-
Agent SDK Chat - Uses Cloudflare Agents AIChatAgent
-
TinyBase Chat - Uses TinyBase websockets
-
Agent Agent Chat - Cloudflare Agents with subagents and MCP tools
Companion repo for blog post: Multi-user AI chat with RedwoodSDK RSC and Cloudflare agents.
Takeaways
TL;DR
- Cloudflare is a great platform for building multi-agent multi-user streaming UX.
- Current UI tooling is immature e.g. with limiting assumptions which block many-to-many connections.
RedwoodSDK RSC:
- React Server Components provide succinct way to render JSX on the server.
- RedwoodSDK makes using react with Cloudflare workers easy.
- The realtime feature of RedwoodSDK pushes updates to connected clients over websockets.
- Had to disable ssr for hooks (e.g. useChat) not designed to run server-side.
Cloudflare Agents
- Cloudflare durable objects (DOs) are ideal for agents and subagents.
- The agents library wraps DOs with additional classes and react hookk.
- It depends on Vercel's AI SDK for model portabilty, message types, streaming, and tool calling.
- useChat and useAgentChat result in tight coupling between Agents and UI.
- The design for AI chat assumes single-agent, single-user.
- RSC support in Vercel's AI SDK is limited.
OpenAI Agents SDK
- OpenAI Agents SDK is less mature and focuses on model APIs, not UI integration.
- It offers APIs for realtime, handoffs, and subagents - not used in this project yet.
- It currently requires patches to run in workerd. (from here 🙏 @threepointone)
- The stateful Agent abstraction assumes long-running server processes with a single conversation per agent.
TinyBase:
- DB sync engines can improve UX with local-first client-side persistence.
- The approach requires careful validation since database operations run on the client.
- The architecture assumes that connected clients sync the same data.
Links
Test broken link