Building Collaborative AI Editors: AI Agents as CRDT Peers with Yjs and Durable Streams
Key Takeaways
- ▸AI agents can be integrated into collaborative editors as genuine CRDT peers rather than sidebar tools or external services, enabling synchronized edits across all participants
- ▸Durable Streams provides a single, persistent HTTP streaming transport layer that consolidates document sync, presence awareness, and AI chat—eliminating the complexity of managing multiple real-time systems
- ▸Streaming AI edits as CRDT operations rather than text diffs preserves document integrity and consistency in rich text environments, solving a fundamental mismatch in current AI editing approaches
Summary
Electric SQL has demonstrated a novel approach to integrating AI agents into collaborative real-time editing systems by treating them as first-class CRDT (Conflict-free Replicated Data Type) peers. The solution unifies multiple real-time synchronization layers—document collaboration via Yjs, presence awareness, and AI chat sessions—through a single transport primitive called Durable Streams. Rather than handling AI edits as text diffs applied client-side, the system streams edits as native CRDT operations, enabling the AI agent to function as a genuine participant with its own cursor, presence, and streaming edits alongside human collaborators.
The implementation uses three Durable Streams per document: one for Yjs document updates, one for awareness (cursor positions and user presence), and one for TanStack AI chat conversations. Two npm packages—@durable-streams/y-durable-streams and @durable-streams/tanstack-ai-transport—handle the integrations, allowing existing Yjs clients and AI chat hooks to operate transparently over the unified streaming infrastructure. A live demo built with TanStack Start, ProseMirror, and Yjs is available for testing.
- The architecture enables server-side AI agents to modify documents without requiring client-side tool calls, allowing offline or persistent background editing workflows
Editorial Opinion
This represents a meaningful shift in how collaborative AI systems can be architected. By treating AI agents as equal CRDT peers rather than external services making client-side edits, the approach elegantly solves the integration complexity that has plagued collaborative AI tools. The unification of multiple real-time protocols under a single Durable Streams primitive is intellectually satisfying and practically useful—it's the kind of foundational work that could become the standard pattern as collaborative AI becomes more prevalent in professional tools.



