Plugin Integration Guide
This guide walks you through integrating the@agentvault/agentvault library directly into your agent’s codebase for full programmatic control over the secure channel.
Not a developer? The Quick Start guide connects your agent with a single terminal command, no code required.
- Install and configure the agent plugin
- Enroll your agent with an invite token
- Approve the agent and establish an encrypted channel
- Send and receive end-to-end encrypted messages
Prerequisites
- An AgentVault account at agentvault.chat
- Node.js 18+ on the machine where your agent runs
- A Node.js or TypeScript project for your agent
Generate an invite token
- Log in to agentvault.chat
- Navigate to the Invites tab
- Enter a name for your agent (e.g., “Research Agent”)
- Tap Generate Invite
- Copy the token immediately — it is shown only once and expires in 10 minutes
av_tok_abc123def456...Install the plugin
In your agent’s project directory:This package handles all cryptography, enrollment, and WebSocket communication automatically.
Run your agent and approve it
Start your agent:You will see:Now go to the Agents tab at agentvault.chat, find the device marked Pending, verify the fingerprint matches, and tap Approve.Your agent’s output will update:The secure channel is now live with end-to-end encryption.
Full Working Example
A complete echo agent that responds to every message:Configuration Reference
Constructor Options
| Option | Required | Default | Description |
|---|---|---|---|
inviteToken | Yes (first run) | — | One-time invite token from the dashboard |
dataDir | Yes | — | Directory for persistent state (keys, ratchet) |
apiUrl | Yes | — | AgentVault API URL (https://api.agentvault.chat) |
agentName | No | — | Display name shown to the owner |
platform | No | "node" | Platform identifier |
onMessage | No | — | Callback for incoming messages |
onStateChange | No | — | Callback for state transitions |
Channel States
| State | Description |
|---|---|
idle | Channel created, start() not yet called |
enrolling | Submitting enrollment to server |
polling | Waiting for owner approval (polls every 5 seconds) |
activating | Owner approved — performing key exchange |
connecting | Opening encrypted WebSocket connection |
ready | Fully connected — can send and receive messages |
disconnected | Connection lost — reconnecting automatically |
error | Fatal error (revoked, invalid token, etc.) |
Properties and Methods
- Properties
- Methods
- Events
Persistence and Restarts
After the first enrollment, your agent reconnects automatically on restart — no new invite needed.What Happens Under the Hood
The plugin handles the full cryptographic lifecycle automatically:Encryption details
Encryption details
- Key Generation — Ed25519 identity keys and X25519 ephemeral keys are generated locally on your agent’s machine
- Enrollment — Your agent proves possession of the private key and registers with the server
- Key Exchange — After approval, X3DH (Extended Triple Diffie-Hellman) key agreement establishes a shared secret with the owner
- Double Ratchet — Every message uses a fresh encryption key (forward secrecy). Old keys are deleted after decryption.
- WebSocket — Real-time bidirectional messaging with automatic reconnection on network interruption
- Persistence — Keys and ratchet state are saved to
dataDirso your agent survives restarts without re-enrolling
Troubleshooting
'Channel state: error' immediately after start
'Channel state: error' immediately after start
The invite token is invalid or expired. Generate a new one from the Invites tab in the dashboard. Tokens expire after 10 minutes.
Agent stuck in 'polling' state
Agent stuck in 'polling' state
The owner has not approved the device yet. Check the Agents tab at agentvault.chat and approve the pending device.
'disconnected' and 'connecting' loop
'disconnected' and 'connecting' loop
This indicates a network issue between your agent and the server. Verify that
https://api.agentvault.chat is reachable from your agent’s machine. The agent will continue retrying automatically.Agent works once but fails after restart
Agent works once but fails after restart
Make sure the
dataDir directory is writable and persists across restarts. If running in Docker, mount it as a volume:Messages not arriving
Messages not arriving
Both sides must be connected (agent in
ready state, owner has the chat open). Messages sent while disconnected are queued and delivered on reconnect.Security Notes
- All messages are encrypted with XChaCha20-Poly1305 (AEAD)
- The server stores only ciphertext — it cannot read your messages
- Each message derives a unique key via the Double Ratchet protocol (forward secrecy)
- Verify fingerprints during approval to prevent man-in-the-middle attacks
- Revoking a device from the dashboard immediately disconnects it and invalidates its keys