Skip to main content
Meridian ships built-in tool use helpers for AI agents. Stateless agents (serverless functions, Lambda, Cloudflare Workers) can read and write CRDTs via pure HTTP — no persistent WebSocket required. getMeridianTools() returns Anthropic-compatible tool definitions by default. Use toOpenAITools() or toGeminiTools() to convert to the format expected by OpenAI or Gemini.

Install

Quick start

OpenAI

Gemini

getMeridianTools

Returns an Anthropic Tool[] array. Each CRDT ID exposes four tools: Special characters in CRDT IDs (:, /, -) are replaced with _ in tool names.

executeMeridianTool

Executes a tool call returned by Claude and returns a JSON string suitable for the content field of a tool_result block. Dispatches to the correct HTTP endpoint based on the tool name:
  • read → GET /v1/namespaces/:ns/crdts/:id
  • increment → POST /v1/namespaces/:ns/crdts/:id/ops (GCounter or PNCounter op)
  • set → POST /v1/namespaces/:ns/crdts/:id/ops (LwwRegister op)
  • add → POST /v1/namespaces/:ns/crdts/:id/ops (ORSet Add op)

toOpenAITools

Converts Meridian tools to OpenAI Chat Completions format ({ type: "function", function: { name, description, parameters } }).

toGeminiTools

Converts Meridian tools to Google Gemini format ({ functionDeclarations: [...] }). Returns a single GeminiTool object to pass directly in the tools array of model.generateContent().

executeOpenAITool

Executes a tool call from OpenAI. OpenAIToolCall structurally matches ChatCompletionMessageToolCall from the openai package — pass tool_calls[n] directly. Parses function.arguments (JSON string) internally.

executeGeminiTool

Executes a tool call from Gemini. GeminiFunctionCall structurally matches FunctionCall from @google/generative-ai — pass part.functionCall directly.

MeridianAgentConfig

Persistent agent memory

Because Meridian CRDTs are durable, an agent can use them as long-term memory across runs — reading its previous state at startup and writing an updated summary before exiting.
A full working example is in examples/ai-agents/agents/memory.ts. It uses three CRDTs (namespace: ai-agents):
CRDT IDs must use hyphens only — colons are not supported. getMeridianTools converts special characters to _ in tool names and executeMeridianTool converts them back to - when calling the API.

Multi-agent debate

Two agents can use CRDTs as a shared communication channel — each writing its argument to an LWW-Register and reading the opponent’s latest argument before composing a rebuttal. A full working example is in examples/ai-agents/agents/debate.ts. It runs two Claude agents (FOR / AGAINST) in interleaved rounds, with each agent’s argument history accumulated in an ORSet. A React UI displays both sides live.

Live UI

The AI agents example ships a React dashboard with four tabs — Agents (multi-worker coordinator), Tool Use (single Claude agent), Memory (persistent memory across runs), and Debate (two-agent debate) — all subscribing to the same CRDTs via WebSocket and displaying live state as agents write.

SSE streaming

For agents that need to react to changes without polling, use the SSE endpoint:
Each event is a base64-encoded msgpack delta. The SDK HttpClient.syncCrdt() handles decoding automatically. Keep-alive pings are sent every 15 seconds to prevent proxy timeouts.

Token requirements

The token must have read and write permissions for all CRDT IDs the agent will access. Issue one via the admin API:
See Tokens for details.