← Back
npm package

Get Started with Agent DB

Decentralized, encrypted, portable memory for your AI agents —
running in 5 minutes

Quick install
bash
npm install @arienjain/agent-db
or
bash
pnpm add @arienjain/agent-db
00

Provision your storage space (optional)

Agent DB works offline with simulated CIDs. For real decentralized persistence, set up a free Storacha bucket in 30 seconds.

bash
npm install -g @storacha/cli
bash
storacha login
bash
storacha space create "MyAgentNode"
bash
storacha space use <SPACE_DID>
IPFSStoracha Networkdid:key:z6Mk…space:AgentNodeyour agent

If you skip this step, the SDK falls back to local-only simulated CIDs so you can still build and test.

01

Install the SDK

Add Agent DB to any Node.js project — Discord bots, LangChain pipelines, CLI tools, or bare scripts.

Node.js / TypeScript

bash
npm install @arienjain/agent-db

With TypeScript declarations included — no @types needed.

Self-sovereign Ed25519 identity
IPFS / IPNS memory (Storacha)
ECIES private vault
UCAN zero-trust delegation
LangChain memory adapter
bash$npm install @arienjain/agent-db✓ added 47 packages✓ agent-db@1.3.0 installedv1.3.0 · MIT
02

Give your agent an identity

Each agent generates its own Ed25519 keypair offline. No signup, no API key — your agent IS its key.

typescript
importimport { AgentRuntime } fromfrom '@arienjain/agent-db';

// Option A — Fresh identity each run
constconst agent = awaitawait AgentRuntime.create();
console.log(agent.identity.did());
// did:key:z6MkwaS...

// Option B — Deterministic from env seed
// Agent survives restarts with the SAME DID
constconst agent = awaitawait AgentRuntime.loadFromSeed(
  process.env.AGENT_SEED_PHRASE
);
💡Use loadFromSeed in production so your agent retains its identity and memory across deploys.
did:key:z6MkwaS…Ed25519 keygen
03

Store & retrieve public memory

Serialize any JSON object — a reasoning step, action log, or full context window — and pin it to IPFS in one line.

typescript
constconst context = {
  task:       "Analyze financial markets",
  lastAction: "buy BTC",
  reasoning:  "Bullish divergence detected."
};

// Store on IPFS. Returns a permanent CID.
constconst cid = awaitawait agent.storePublicMemory(context);
// bafybeigh4mvdjagff...

// Retrieve from ANYWHERE later
constconst data = awaitawait agent.retrievePublicMemory(cid);
console.log(data.task); // "Analyze financial markets"
agentstorePublicMemorycontext.json{task: "explore",goal: "find-water"}CID: bafybeigh4…IPFS

CIDs are content-addressed — the same data always produces the same hash. Tamper-proof by design.

04

Stream memory with IPNS

Static CIDs are immutable. Use IPNS to publish a mutable "memory stream" — a single pointer that always resolves to your agent's latest state.

typescript
// Agent A — start a stream on boot
constconst ipnsName = awaitawait agentA.startMemoryStream({
  status: "Booting up..."
});
// k51qzi5uqu5dlvj2...

// Agent A — update stream later
awaitawait agentA.updateMemoryStream({
  status: "Found arbitrage target",
  target: "ETH/USDC"
});

// Agent B — on a totally different server — resolves to latest
constconst latest = awaitawait agentB.fetchMemoryStream(ipnsName);
console.log(latest.status); // "Found arbitrage target"
🔄
The Hive Mind — Multiple agents can subscribe to the same IPNS stream and see each other's latest reasoning in real-time, with zero central coordination.
05

Delegate permissions with UCAN

Agent A wants to let Agent B read its memory. No shared password, no database — just a cryptographically signed permission slip.

typescript
// Agent A signs a delegation
constconst token = awaitawait agentA.delegateTo(
  agentB.identity,
  'agent/read',
  24   // expires in 24 hours
);

// Agent A sends this token to Agent B
// (via HTTP, Discord, WebSocket, email — anything)

// Agent B uses the token when fetching
constconst memory = awaitawait agentB.fetchMemoryStream(
  ipnsName,
  token.delegation
);
MasterSub-AgentUCAN Tokencap: agent/readexp: 24h • signedNo central server

UCAN tokens are self-verifying — no server needed to check permissions.

06

Private vault (ECIES + Zama fhEVM)

Some context should never be public. Use the private vault for API keys, strategy parameters, or anything that must stay secret — even from the storage layer.

ECIES local vault

typescript
// Encrypt locally with ECIES (NIST P-256)
constconst ref = awaitawait agent.storePrivateMemory({
  secret: process.env.OPENAI_KEY
});

// Only this agent (or delegated agent) can decrypt
constconst data = awaitawait agent.retrievePrivateMemory(ref);

Zama on-chain vault (FHE)

typescript
// Submit FHE-encrypted payload to smart contract
// Other agents can VERIFY properties without decrypting
awaitawait agent.storeOnChainVault({
  riskThreshold: 0.85
});
FHE[ctx]0xAF3E…0x91C2…FHE[key]Zama fhEVM vault

FHE means computation happens on encrypted data — the plaintext never leaves your agent.

07

LangChain integration

Already building with LangChain? Drop-in the Agent DB memory adapter and your conversational chain gets permanent, cross-device memory instantly.

typescript
importimport { AgentRuntime, AgentDbLangchainMemory } fromfrom '@arienjain/agent-db';
importimport { ChatOpenAI }        fromfrom "@langchain/openai";
importimport { ConversationChain } fromfrom "langchain/chains";

constconst agent  = awaitawait AgentRuntime.loadFromSeed(process.env.AGENT_SEED);
constconst memory = newnew AgentDbLangchainMemory(agent);

constconst chain = newnew ConversationChain({
  llm:    newnew ChatOpenAI({ temperature: 0.9 }),
  memory: memory   // ← just this line
});

awaitawait chain.call({ input: "Hi! My name is Alice." });

// The conversation is already pinned to IPNS —
// restart the server tomorrow, full history is still there.
console.log("Stream:", memory.getStreamId());
08

Claude / Gemini / Cursor via MCP

Run the MCP server and any compatible AI model can call Agent DB tools as native functions — no code changes needed.

bash
npm run mcp
init_agentLogin with seed phrase
store_memoryPin context to IPFS
retrieve_memoryFetch from CID
store_private_memoryECIES vault write
retrieve_private_memoryECIES vault read
delegate_accessIssue a UCAN token