This guide shows you how to take a simple AI agent and give it "Infinite Memory" using our system.
Instead of using an API key, your agent uses a DID (Decentralized ID). This makes them a unique, verifiable entity on the web.
import { AgentRuntime } from '@arienjain/agent-db';
// Load a persistent identity so the agent keeps its memory after a restart
const agent = await AgentRuntime.loadFromSeed("your-secret-agent-seed-phrase");
console.log(`Agent DID initialized: ${agent.did}`);If you already use a framework, just drop in our memory class. It handles all the IPFS pinning and UCAN security behind the scenes.
LangChain Example:
import { AgentDbLangchainMemory } from '@arienjain/agent-db';
const memory = new AgentDbLangchainMemory(agent);
// Now pass this 'memory' to your LangChain Agent/ChainIf you have a custom script, manually save "checkpoints" of the agent's logic.
// After every LLM response, save the context
const chatSummary = "User asked about Bitcoin. I explained the Halving.";
const cid = await agent.storePublicMemory({
thoughts: chatSummary,
timestamp: Date.now()
});
console.log(`Memory safe on IPFS: https://storacha.link/ipfs/${cid}`);For highly sensitive data, use the ECIES-encrypted vault. Only the owner agent can decrypt this.
// Encrypt and store private data (Sovereign Context)
const secretCid = await agent.storePrivateMemory({
private_key_recovery: "...",
secret_strategy: "Buy low, sell high"
});
// To retrieve and decrypt:
const secretData = await agent.retrievePrivateMemory(secretCid);To make your agent work with other agents, issue a UCAN delegation. This lets Agent B read Agent A's memory without sharing private keys.
// Agent A grants 'read' permission to Agent B for 24 hours
const token = await agentA.delegateTo(agentB.did, 'agent/read', 24);
// Send this 'token' to Agent B so they can access your memory stream!- Persistence: Your bot won't forget who the user is if the server reboots.
- Privacy: Sensitive data is encrypted via Zama FHE or exported with UCAN guardrails.
- Interoperability: Different agents (one in Python, one in JS) can share a single "Hive Mind" memory stream on IPFS.