Documentation Index
Fetch the complete documentation index at: https://docs.meshagent.com/llms.txt
Use this file to discover all available pages before exploring further.
Overview
TheSyncClient is the Room API for live shared documents (MeshDocuments). Use it when multiple humans or agents need to read and edit the same structured document in real time.
CLI commands
Start with the CLI help, then use a few common commands:bash
Why use the Sync API?
- Keep shared state in a live document instead of relying only on chat history.
- Let multiple participants collaborate on the same structured content at once.
- Define document schemas that help users and agents write valid data.
How it works
You create or open a document by path. Opening a document starts a live synchronization session so local changes propagate to other participants in the room. The Python SDK also exposesdescribe when you want the current JSON state without opening a sync session, and sync is available when you already have encoded changes to send.
For the Python, JavaScript, TypeScript, and .NET standalone room examples on this page, start the script through meshagent room connect --room={ROOM_NAME} --identity={AGENT_NAME} -- <command> so MeshAgent injects the room connection environment automatically. For example: meshagent room connect --room=my-room --identity=participant-name -- python3 documents-writing.py. The Dart sample still shows the explicit protocol factory flow.
Permissions and grants
The Sync API is controlled by thesync grant on the participant token.
In practice, sync grants are path-based and can be marked read-only. That lets you give a participant access to specific document paths without opening the entire sync surface.
See API Scopes and Service YAML.
Defining Your Document Structure
To define the structure of a MeshDocument, you start by creating a schema using the MeshSchema class. A schema:- Documents the structure of your MeshDocument for anyone in your organization.
- Ensures agents and users don’t write invalid data to the document.
- Allows agents to automatically generate, manipulate, and validate structured documents.
- Automatically generates LLM-compatible schemas for structured outputs.
- Synchronizes documents across all platforms that MeshAgent supports.
Example Schema
Suppose you have a basic web page structure and want to define a schema for it.Creating a MeshDocument
To create a MeshDocument based on your schema and enable synchronization across different clients, use the MeshAgent runtime:API reference
Use the methods below to create documents, open live sync sessions, inspect the current document state, and send low-level sync operations when needed.create(path, json=None)
- Parameters:
path: Document path.json: Optional initial JSON payload.
- Description: Create a new
MeshDocumentat the given path. The server infers the schema from the document extension.
describe(path)
- Parameters:
path: Document path.
- Returns: The current document root as JSON.
- Description: Read the current state of a
MeshDocumentwithout opening a live sync session. - Availability: Python exposes
room.sync.describetoday. Other SDKs can useopen()or a lower-level request until they add a helper.
open(path, create=True)
- Parameters:
path: Document path.create: Whentrue, create the document if it does not already exist.
- Returns: A
MeshDocumenttied to that path. - Description: Open a live synchronization session for the document. Local changes are sent automatically while the document remains open.
close(path)
- Parameters:
path: Document path.
- Description: Close the local sync session for that document path. Once closed, local changes are no longer synchronized.
sync(path, data)
- Parameters:
path: Document path.data: Serialized sync bytes.
- Description: Send encoded sync data directly to the server. Use this when you already have the wire-format change payload.
Notes
-
Synchronized Changes
Once a document is opened, any local changes you make in the associatedMeshDocumentare automatically queued for sending, thanks tosendChangesToBackend. You rarely need to callsync()manually unless you want to send raw data yourself. -
Reference Counting
TheSyncClientinternally tracks how many times a document is opened via the same path. Callingopenmultiple times for the same path returns the same underlying document. Only when all references are closed (viaclose()) will the client actually disconnect. -
Error Handling
If a request fails, theRoomClientmay throw an error (likeRoomServerException). Wrap calls intry/catch(or use.catch(...)) to handle them gracefully. -
Concurrency and Performance
- For high throughput, ensure that your
RoomClientand server are configured for concurrent operations. - The
SyncClientuses aStreamControllerinternally to manage queued updates, sending them asynchronously to the server.
- For high throughput, ensure that your