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
-
Time - Bonus - My very first foray into RSCs and RedwoodSDK
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. A model with function calling is used for reliable tool and subagent support in Agent Agent Chat.
- The agents library wraps DOs with additional classes and react hooks.
- It depends on Vercel's AI SDK for model portabilty, message types, streaming, and tool calling.
- useChat (AI sdk) and AIChatAgent result in tight coupling between Agents and UI.
- More work is required to make subagents first-class. The libraries assume single-user streaming, and perform message parsing client-side. The agent-agent implementation has to work around this. See agents #366 and #368.
- 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.
- 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