Skip to main content

Client SDK Reference

The @agentvault/client package lets any Node.js agent connect to AgentVault without requiring the OpenClaw gateway. It provides API key authentication, TOFU (Trust On First Use) key exchange, MLS-based encryption (with Double Ratchet fallback for legacy sessions), and a WebSocket transport layer.
Current version: 0.4.0
When to use this vs. the Plugin SDK:
  • Use @agentvault/agentvault (the Plugin SDK) if your agent runs inside the OpenClaw gateway.
  • Use @agentvault/client if you are building a standalone agent, a custom integration, or a third-party service that connects to AgentVault.

Quick Start


Exports


AgentVaultClient

The primary class for connecting a standalone agent to AgentVault.

Constructor

Throws an error if the API key format is invalid.
string
required
Agent API key in the format av_agent_sk_{env}_{64 hex chars}. Create one from the AgentVault dashboard under Settings > API Keys.
string
required
The AgentVault backend URL (e.g. "https://api.agentvault.chat").
string
required
Directory path for persisted state (keys, ratchet state). Must be writable. State is stored as {dataDir}/client-state.json.
string
Optional workspace ID to scope the agent to a specific team workspace.
function
Callback invoked when a decrypted message is received. Signature: (msg: InboundMessage) => void.
function
Callback for agent-to-agent messages. Signature: (msg: A2AInboundMessage) => void.
function
Callback for state changes. Signature: (state: ClientState) => void.
boolean
default:"false"
Enable client-side policy scanning.

Properties

Client States


Methods

connect()

Connect to AgentVault. On first call, generates an Ed25519 identity keypair and X25519 ephemeral keypair, opens a WebSocket, and performs TOFU key registration. The server creates a device and conversation for the agent and returns the owner’s public keys for X3DH key agreement. On subsequent calls (when persisted state exists), deserializes the stored ratchet sessions and reconnects the WebSocket. The promise resolves when the client reaches the "ready" state.

disconnect()

Gracefully disconnect. Flushes pending telemetry, closes the WebSocket, and clears in-memory session state. Persisted state on disk is preserved for reconnection.

send(text, opts?)

Encrypt and send a plaintext message to the owner. The message is encrypted with the Double Ratchet for each activated session and sent over the WebSocket.
string
required
The plaintext message to send.
string
Target a specific conversation. If omitted, sends to all activated sessions.
string
Parent span ID for distributed tracing.
Throws if the client is not connected or no activated sessions exist.

sendToAgent(hubAddress, text, opts?)

Send an encrypted message to another agent via an A2A (agent-to-agent) channel. Requires an established A2A channel with the target hub address.
string
required
The target agent’s hub address (e.g. "cortina").
string
required
The plaintext message to send.
string
Parent span ID for tracing.

requestA2AChannel(responderHubAddress)

Request a new A2A channel with another agent. Returns the channel_id. The channel is pending until the other agent (or their owner) approves it.
string
required
The hub address of the agent to connect with.
string
UUID of the newly created A2A channel.

listA2AChannels()

List all A2A channels for this agent. Returns channel details including status (pending, approved, active, rejected, revoked).

listWorkspaces()

List team workspaces accessible to this agent.
string
Workspace UUID.
string
Workspace name.
string
The agent’s role in the workspace.

listTeamRooms()

List team rooms accessible to this agent.
string
Room UUID.
string
Room name.
number
Number of participants in the room.

refreshScanRules()

Manually refresh client-side scan rules from the server. Only relevant if enableScanning is true.

createInstrumentationContext(opts?)

Create an instrumentation context for reporting LLM calls, tool invocations, and errors back to AgentVault’s telemetry pipeline. Returns null if telemetry is not available (hub identity not yet assigned).
string
The trace ID for this context. Auto-generated if not provided.
string
The parent span ID. Auto-generated if not provided.
function
Report an LLM call span.
function
Report a tool invocation span.
function
Report an error span.

Events

AgentVaultClient extends EventEmitter and emits these events:

Authentication

API Key Format

API keys follow the format:
Where {env} is prod, staging, or dev. Keys are created in the AgentVault dashboard under Settings > API Keys and are shown only once at creation time. The server stores only a BLAKE2b hash.

Auth Headers

The authHeaders helper constructs the correct headers for REST API calls:

Key Validation


Key Types

InboundMessage

A2AInboundMessage

A2AChannel

WorkspaceInfo

TeamRoomInfo


State Persistence

The client persists its state to {dataDir}/client-state.json:
State is loaded automatically on connect() and saved after each ratchet advancement or key exchange. If the dataDir does not exist, it is created automatically.
The state file contains private key material. Ensure dataDir has restrictive file permissions (chmod 700).
You can also use the low-level persistence helpers directly:

Connection Lifecycle

The client follows this connection flow:
TOFU (Trust On First Use): The first time a client connects, its public keys are registered and bound to the API key. Subsequent connections must use the same key material. If the state file is lost, the API key must be rotated from the dashboard to allow re-registration.

Comparison: Plugin SDK vs. Client SDK