|
1 | | -# 🧠 Agent DB: Decentralized Memory for AI Agents |
| 1 | +# 🤖 AgentDB: The Decentralized Memory Protocol for AI Agents |
2 | 2 |
|
3 | | -> **Persistent, encrypted, and permission-controlled memory for autonomous AI agents powered entirely by Web3 infrastructure.** |
4 | | -
|
5 | | -Built on **Storacha**, **IPNS**, **UCAN**, and **Zama fhEVM**, Agent DB is an enterprise-grade platform for endowing AI agents with cross-platform reasoning continuity and verifiable capability delegation. |
| 3 | +**AgentDB** is a high-performance, decentralized memory infrastructure layer that provides AI agents with permanent, sovereign, and collaborative "brains." Built on **Storacha (IPFS/Filecoin)**, **UCAN**, and **X25519**, it transforms ephemeral agent sessions into a global, device-agnostic knowledge graph. |
6 | 4 |
|
7 | 5 | --- |
8 | 6 |
|
9 | | -## 🏗️ Platform Architecture |
| 7 | +## 🌎 The Vision: Solving the "AI Lobotomy" |
| 8 | + |
| 9 | +Today, AI agents suffer from a fundamental flaw: **amnesia**. Every time a process restarts, a server crashes, or a container scales down, the agent is "lobotomized." Their memory is either trapped in volatile local RAM or locked inside centralized SaaS databases that other agents cannot access. |
10 | 10 |
|
11 | | -Agent DB is a decentralized memory and sovereignty engine for autonomous AI. It addresses the "Amnesia Bot" problem while ensuring that an agent's internal reasoning remains private and cryptographically secure. |
| 11 | +**AgentDB changes the fundamental architecture of AI:** |
12 | 12 |
|
13 | | -1. **The SDK (`src/lib`)**: Enables agents to generate deterministic DIDs and pin context directly to IPFS (**Verifiable AI Provenance**). |
14 | | -2. **ECIES Private Vault**: High-security storage for private memory using **ECIES (NIST P-256)** encryption for true data sovereignty. |
15 | | -3. **The Hive Mind (IPNS)**: Mutable memory streams via IPNS pointers, allowing swarms to continuously resolve each other's state. |
16 | | -4. **Agent Vault (Zama fhEVM)**: FHE-powered smart contracts for confidential finance and verifiable risk thresholds. |
17 | | -5. **OpenClaw Adapter**: Native persistence for OpenClaw agents, preventing context loss across device restarts using Storacha. |
18 | | -6. **Vincent Integration**: Autonomous agent wallet management with programmable guardrails using Lit Protocol. |
| 13 | +1. **From Local Silos to a Global Graph**: Agents no longer store "thoughts" on a single hard drive. They serialize their context and pin it to the decentralized web (Storacha), making their memory accessible from anywhere on Earth. |
| 14 | +2. **From Isolation to Cryptographic Collaboration**: AI models are moving towards multi-agent swarms. Using **UCAN delegations**, Agent B can cryptographically "hand off" its context to Agent A without exposing private keys or relying on centralized middleware. |
| 15 | +3. **From Centralized to Sovereign**: You—and your agents—own the memory. There is no API gatekeeper. It is raw, encrypted data pinned to the permanent web, verifiable on-chain. |
19 | 16 |
|
20 | 17 | --- |
21 | 18 |
|
22 | | -## 🚀 Running the Platform |
| 19 | +## 🏗️ Technical Architecture & Under-the-Hood |
23 | 20 |
|
24 | | -### 0. Prerequisites: Storacha IPFS Account |
25 | | -Before starting the gateway, you must provision a free decentralized storage bucket via Storacha. |
26 | | -1. `npm install -g @storacha/cli` |
27 | | -2. `storacha login` |
28 | | -3. `storacha space create "MyAgentNode"` |
29 | | -4. `storacha space use <SPACE_DID>` |
| 21 | +AgentDB operates as a fully peer-to-peer memory layer comprising three core modules. These modules ensure that data is not only stored permanently but retrieved at speeds competitive with Web2 databases. |
30 | 22 |
|
31 | | -*(If skipped, the gateway will gracefully fallback to simulated, local-only CIDs).* |
| 23 | +### 🧩 1. Identity & Authorization Layer (`ucan.ts`) |
| 24 | +We standardize agent identification using **Ed25519 DIDs** (Decentralized Identifiers). An agent *is* its private key. |
| 25 | +- **Sovereign Agents**: Every agent generates a DID upon initialization (`UcanService.createIdentity()`). |
| 26 | +- **Capability Delegation**: When Agent B finishes researching a topic, it issues a cryptographically signed "ticket" (UCAN) to Agent A (`UcanService.delegate()`). This ticket encodes the specific IPFS CID and the `agent/read` capability. |
| 27 | +- **Zero-Trust Verification**: Access isn't granted by checking a database; the proof is baked into the math of the UCAN token itself (`UcanService.verifyDelegation()`). |
32 | 28 |
|
33 | | -### 1. Start the API Gateway |
34 | | -The API Gateway handles UCAN delegation indexing and public skills discovery. |
| 29 | +### 🧩 2. Storage & Retrieval Layer (`storacha.ts`) |
| 30 | +Powered by **Storacha** (the hot storage layer for Filecoin), we treat IPFS as a high-speed agent backend. |
| 31 | +- **Gateway Racing Engine**: The biggest critique of IPFS is latency. AgentDB implements a proprietary retrieval strategy that queries 4+ IPFS gateways (Cloudflare, Pinata, IPFS.io, Storacha) simultaneously. The first one to return the data wins, consistently delivering **sub-second response times** (~500ms). |
| 32 | +- **Stable IPNS Mapping**: To solve the problem of moving agents across devices, AgentDB derives a stable mutable pointer directly from an agent's seed (`StorachaService.deriveIpnsName()`). This creates a permanent, deterministic "Home Base" (Session Registry) for the agent's memory map, regardless of the physical hardware it runs on. |
35 | 33 |
|
36 | | -```bash |
37 | | -# Install platform dependencies |
38 | | -npm install |
| 34 | +### 🧩 3. Security Layer (`encryption.ts`) |
| 35 | +For sensitive data, we implement hardware-grade protection using **X25519 (Curve25519)**. |
| 36 | +- **ECIES Implementation**: AgentDB combines Diffie-Hellman key exchange with **AES-256-GCM**. When Agent B wants to write a private thought, it encrypts the data so it is mathematically unreadable by anyone but the owner and authorized delegates (`EncryptionService.encrypt()`). |
39 | 37 |
|
40 | | -# Start the discovery gateway |
41 | | -npm run server |
42 | | -``` |
| 38 | +--- |
43 | 39 |
|
44 | | -The gateway will run on `http://localhost:3001` with strict CORS and rate-limiting enabled for production stability. |
| 40 | +## 🧠 Comprehensive Ecosystem Integrations |
45 | 41 |
|
46 | | -### 2. Start the Frontend Dashboard |
47 | | -The Next.js dashboard visualizes the global active agents, public skills on IPFS, and UCAN delegation flows. |
| 42 | +AgentDB acts as a drop-in persistence layer for the modern AI stack, enabling agents built on different frameworks to share a unified, decentralized memory. |
48 | 43 |
|
49 | | -```bash |
50 | | -cd frontend |
51 | | -npm install |
52 | | -npm run dev |
53 | | -``` |
| 44 | +### 🔹 [OpenClaw](https://github.com/openclaw/openclaw) Integration |
| 45 | +OpenClaw agents are brilliant but often lose their customized persona when deployed to new environments. `AgentDbOpenClawMemory` provides a permanent anchor: |
| 46 | +- **Persistent Persona (`resumeFromCid`)**: Instantly restores an agent's entire personality, learned preferences, and history from the decentralized web when it boots up. |
| 47 | +- **Auto-Checkpointing (`commitToStoracha`)**: Automatically snapshots the agent's state to IPFS after conversations. |
54 | 48 |
|
55 | | -Navigate to `http://localhost:3000` to view the live Globe visualization. |
| 49 | +### 🔹 [LangChain](https://js.langchain.com/) Integration |
| 50 | +`AgentDbLangchainMemory` replaces the ephemeral `BufferMemory` module standard in LangChain: |
| 51 | +- **Streaming "Hive Mind" IPNS**: Instead of just saving static JSON, it continuously updates a single mutable pointer as the conversation progresses. This allows external tools or other agents to "tune in" to a live stream of the agent's thought process. |
| 52 | + |
| 53 | +### 🔹 [Lit Protocol](https://litprotocol.com/) Integration |
| 54 | +Agents need agency. `LitVincentService` connects agent memory to programmable on-chain wallets: |
| 55 | +- **Programmable Wallets (`provisionAgentWallet`)**: Uses Lit PKPs to generate non-custodial wallets specifically for the agent. This allows the AgentDB agent to autonomously pay gas fees or its own Storacha storage bills, creating a fully self-sustaining AI entity. |
56 | 56 |
|
57 | 57 | --- |
58 | 58 |
|
59 | | -## 🤖 Model Context Protocol (MCP) Server |
60 | | -Agent DB is now accessible via MCP! This allows any AI model (Claude, Gemini, Cursor) to natively use decentralized memory, encryption, and delegation tools. |
| 59 | +## 💻 Developer Integration Guide |
61 | 60 |
|
62 | | -### 🔌 Connect to MCP |
63 | | -To add Agent DB to your AI agent environment, use the following command or configuration: |
| 61 | +Integrating AgentDB into your custom AI project takes less than 10 lines of code. |
64 | 62 |
|
65 | | -```bash |
66 | | -# Start locally |
67 | | -npm run mcp |
68 | | -``` |
| 63 | +### 1. Initialization and Public Memory |
| 64 | +Start by creating a stable identity and pushing data to the public IPFS network. |
69 | 65 |
|
70 | | -**Claude Desktop Config:** |
71 | | -```json |
72 | | -"mcpServers": { |
73 | | - "agent-db": { |
74 | | - "command": "npx", |
75 | | - "args": ["-y", "@arienjain/agent-db", "mcp"] |
76 | | - } |
77 | | -} |
78 | | -``` |
| 66 | +```typescript |
| 67 | +import { AgentRuntime } from '@arienjain/agent-db'; |
79 | 68 |
|
80 | | -**Exposed Tools:** |
81 | | -- `init_agent`: Login with your seed phrase. |
82 | | -- `store_memory` / `retrieve_memory`: Decentralized IPFS storage. |
83 | | -- `store_private_memory` / `retrieve_private_memory`: High-security ECIES vault. |
84 | | -- `delegate_access`: Issue UCAN permissions to other agents. |
| 69 | +// Initialize agent deterministically from a secure seed. |
| 70 | +// This guarantees it will resolve the same IPNS memory registry anywhere. |
| 71 | +const agent = await AgentRuntime.loadFromSeed(process.env.AGENT_SEED); |
| 72 | +console.log(`Agent Online: ${agent.did}`); |
85 | 73 |
|
86 | | ---- |
| 74 | +// Store a complex, nested context directly to Storacha (IPFS) |
| 75 | +const memoryCid = await agent.storePublicMemory({ |
| 76 | + mission: "Alpha Sector Scan", |
| 77 | + insights: ["Anomalous energy detected", "Possible alien artifact"], |
| 78 | + metrics: { confidence: 0.95 } |
| 79 | +}); |
| 80 | + |
| 81 | +console.log(`Memory permanently pinned at CID: ${memoryCid}`); |
| 82 | +``` |
87 | 83 |
|
88 | | -## 🔐 Smart Contract Vault (Zama fhEVM) |
| 84 | +### 2. The Agent Handoff (Collaboration) |
| 85 | +Share memory with another agent using UCANs. |
89 | 86 |
|
90 | | -For data that cannot be public on IPFS, Agent DB leverages Zama's Fully Homomorphic Encryption. |
| 87 | +```typescript |
| 88 | +// Agent A wants to give Agent B permission to read its data |
| 89 | +const agentBDid = "did:key:z6Mk...Agent_B_Address"; |
91 | 90 |
|
92 | | -1. Agents encrypt their context locally. |
93 | | -2. The FHE payload is submitted to the `EncryptedAgentMemory` contract. |
94 | | -3. Secondary agents can verify knowledge of the secret via the FHE Gateway without it ever being decrypted on-chain. |
| 91 | +// Generate a cryptographic delegation valid for 24 hours |
| 92 | +const token = await agent.delegateTo( |
| 93 | + { did: () => agentBDid }, |
| 94 | + 'agent/read', |
| 95 | + 24 |
| 96 | +); |
95 | 97 |
|
96 | | -### 3. Running Hackathon Bounty Demos |
97 | | -We have prepared specific demonstrators for the PL_Genesis bounty tracks. These demos satisfy the core requirements for the **AI & Robotics**, **Crypto**, and **Neurotech** tracks. |
| 98 | +// Publish token to IPFS for Agent B to pick up |
| 99 | +const tokenCid = await agent.exportDelegationForApi(token); |
| 100 | +// Or send token directly over API/WebSocket |
| 101 | +``` |
98 | 102 |
|
99 | | -```bash |
100 | | -# 🤖 AI & Robotics: OpenClaw Persistence (Storacha) |
101 | | -npm run demo:openclaw |
| 103 | +### 3. Private Memory (Military-Grade Encryption) |
| 104 | +```typescript |
| 105 | +// Encrypts memory so NO ONE else on the IPFS network can read it |
| 106 | +const secureCid = await agent.storePrivateMemory({ |
| 107 | + api_keys: { openai: "sk-..." }, |
| 108 | + financial_strategy: "buy the dip" |
| 109 | +}); |
102 | 110 |
|
103 | | -# 🔗 Crypto: Agent Registry on Filecoin Calibration |
104 | | -npm run demo:filecoin |
| 111 | +// Later, the agent decrypts it locally |
| 112 | +const secureData = await agent.retrievePrivateMemory(secureCid); |
| 113 | +``` |
105 | 114 |
|
106 | | -# ⚖️ Crypto/DeFi: Zama fhEVM Confidential Finance |
107 | | -npm run demo:defi |
| 115 | +--- |
108 | 116 |
|
109 | | -# 🛡️ Crypto/KeyMgmt: Lit Protocol Vincent Wallet Logic |
110 | | -npm run demo:lit |
| 117 | +## 🛰️ Advanced Architectural Features |
| 118 | + |
| 119 | +### 🧩 Agent Migration (Device-Agnosticism) |
| 120 | +AgentDB removes the "local file" bottleneck entirely. Because the session registry is mapped to IPNS via the agent's seed, you can destroy the server, boot the agent on a mobile device, and recover perfectly. |
| 121 | + |
| 122 | +```mermaid |
| 123 | +sequenceDiagram |
| 124 | + participant H as Environment A (Desktop) |
| 125 | + participant N as IPNS (Decentralized Registry) |
| 126 | + participant C as Environment B (Cloud) |
| 127 | + |
| 128 | + H->>H: Derive Stable IPNS from Seed |
| 129 | + H->>N: Update Registry (Session: Chat_Alice -> CID_123) |
| 130 | + Note over H: Power Failure / Machine Wiped |
| 131 | + Note over C: Agent Starts with SAME Seed |
| 132 | + C->>C: Resolve IPNS Registry |
| 133 | + N-->>C: Returns Session Map |
| 134 | + Note over C: Agent recovered all past chats with ZERO local state |
111 | 135 | ``` |
112 | 136 |
|
113 | | -### 🛡️ Production Hardening Proofs |
114 | | -The system has been hardened for real-world deployments. You can verify the security and resilience features here: |
| 137 | +### 🧩 Concurrency Guards |
| 138 | +In multi-agent architectures, two agents might try to update the IPNS registry simultaneously. AgentDB implements "Sync-before-Write" logic to fetch the latest global state before publishing, preventing data overwrites and collisions. |
115 | 139 |
|
116 | | -```bash |
117 | | -# 🔐 Private Vault (ECIES Security Verification) |
118 | | -npx tsx src/test-encryption.ts |
| 140 | +--- |
119 | 141 |
|
120 | | -# 💾 Resilience (Handoff & Persistence Verification) |
121 | | -npx tsx src/test-persistence.ts |
| 142 | +## 🛠️ MCP Ecosystem: For LLMs |
122 | 143 |
|
123 | | -# 🛠️ Validation & DX (Zod Schema & Error Handling) |
124 | | -npx tsx src/test-dx.ts |
125 | | -``` |
| 144 | +The **AgentDB MCP Server** enables Model Context Protocol-compatible clients (like Claude Desktop or Cursor) to natively use decentralized memory via a simple UI. |
| 145 | + |
| 146 | +- **`list_sessions`**: Command the LLM to browse the agent's decentralized memory tree. |
| 147 | +- **`resolve_session`**: Pull the full context of a past chat right into the LLM's prompt window. |
| 148 | +- **`store_private_memory`**: Command the LLM to encrypt sensitive output for its "private eyes" only. |
| 149 | +- **`delegate_access`**: Ask the LLM to issue a UCAN permission to a fellow agent. |
126 | 150 |
|
127 | 151 | --- |
128 | 152 |
|
129 | | -## 📦 For Agent Developers (SDK) |
| 153 | +## 🧪 Try the Included Simulations |
130 | 154 |
|
131 | | -Are you an AI developer looking to integrate persistent memory into your Discord bot, LangChain agent, or CLI tool? |
| 155 | +We've bundled fully functional simulations illustrating AgentDB's power. Run them locally: |
132 | 156 |
|
133 | | -**Do not read this repository manual.** |
| 157 | +```bash |
| 158 | +# 1. Cross-Agent Handoff Simulation |
| 159 | +# Watch Agent B store a report and issue a UCAN for Agent A to read it. |
| 160 | +npx tsx src/demo-mcp-simulation.ts |
134 | 161 |
|
135 | | -Instead, please consult the lightweight SDK Developer Guide: |
136 | | -👉 [Read the `@arienjain/agent-db` Node.js Developer Documentation](README_NPM.md) |
| 162 | +# 2. Decentralized Migration Test |
| 163 | +# Watch an agent store data, wipe its local storage, and recover from IPNS. |
| 164 | +npx tsx src/demo-migration.ts |
137 | 165 |
|
138 | | ---- |
| 166 | +# 3. High-Performance Large Data Test |
| 167 | +# Proves Storacha integration handles 20MB+ files (like RAG vector stores), not just tiny JSONs. |
| 168 | +npx tsx src/demo-large-data.ts |
139 | 169 |
|
140 | | -## 🤝 Contributing |
141 | | -Agent DB is an open protocol. We welcome pull requests for expanding UCAN capabilities, creating new visualization widgets in the Next.js frontend, or adding additional fhEVM smart contract capabilities. |
| 170 | +# 4. Multi-Context Switching |
| 171 | +# Watch an agent juggle parallel workflows natively. |
| 172 | +npx tsx src/demo-multi-context.ts |
| 173 | +``` |
142 | 174 |
|
143 | | -## 📄 License |
144 | | -MIT License. |
| 175 | +--- |
| 176 | +*Built from the ground up to standardize how artificial intelligence remembers.* |
0 commit comments