Agentic editing

AI agents can modify the same Sync document as the humans in your application using server-side APIs. Connected users receive changes in realtime, meaning agents can visibly work alongside humans, and take advantage of the same conflict resolution that enables human collaboration.

Edit Sync documents

Agents can read and modify your realtime Sync documents concurrently with your users. Generate changes with AI, then apply them with Liveblocks.mutateStorage—edits appear instantly for connected users.

Other APIs can be used to enable server-side editing, such as the JSON Patch endpoint. AI models are already familiar with JSON Patch, allowing them to easily generate modifications from natural language instructions.

Learn more in our JSON Patch guide.

Saving versions

It’s recommended to use version history to save versions of the Sync document before a modification is applied. This way, the user can revert their document to the previous state, in case they’d like to revert modifications made by the agent. You can manually create a version snapshot using Liveblocks.createVersionHistorySnapshot.

In React, you can display a list of versions with useHistoryVersions, show snapshot previews with useHistoryVersionStorageData, and create revert buttons with useRestoreToStorageVersion.

Note that HistoryVersionSummary and HistoryVersionSummaryList are optional ready-made components that display version history information with styled components.

Show agent presence

Show what agents are working on inside your app by giving them live presence updates, such as selections, typing indicators, and online avatars. Liveblocks.setPresence allows you to set your agent’s presence. In this example, selectedShapeId represents a shape that the agent is focused on, and editing.

After setting presence, you can read it in your app with useOthers like any human, so existing avatar stacks, cursors, and focus indicators show AI activity with no extra UI.

Agent presence appears for a specific amount of seconds, the ttl value, before it disappears. To make it disappear, set ttl to the minimum value of 2 seconds.

Learn more under the presence use case.

Display agent status

Presence shows that an agent is in the room right now, but it disappears when the process ends. You can use feeds to stream the agent’s working state (e.g. thinking, writing, complete), and save it permanently in a history. Create a status message with Liveblocks.createFeedMessage when work starts, then update it with Liveblocks.updateFeedMessage as the agent moves through each stage.

In React, read the latest status with useFeedMessages and render it in your UI.

Feeds can also be used to build complete AI chat interfaces, from which agents can issue modifications. Learn more under the chat use case.

Leave AI comments

Agents can review content and leave contextual feedback with Comments. Generate feedback with AI, convert it with markdownToCommentBody, and post it with Liveblocks.createThread under the agent’s own user ID.

In React, read the comments with useThreads and render them in your UI with Thread.

You can also automatically trigger an agent when a user mentions it in a thread using the commentCreated webhook. Learn more under the comments use case.

Putting it all together

Combining each of the features above, you can create a complete AI agentic editing experience that will modify a document, save a snapshot, display what it’s editing, stream live status, and save a history of the run.

server.ts

In React, you can show all this live in the UI. A list of shapes is rendered, each shape with its own properties, with an outline displayed if the AI is editing the shape. A button to generate a new shape is shown, and when clicked, the agentic editing process is triggered, and the UI displays streamed updates instead of the button.

app.tsx