hackquest logo

0G-Memory

0G-Memory is a persistent memory SDK for AI agents backed by 0G Storage (KV + Log layers).

Videos

Project image 1
Project image 2
Project image 3
Project image 4

Tech Stack

React
Next
Web3
Ethers
Solidity

Description

AI agents today are amnesiac by design. Every session starts cold. Client context is lost. There is no cryptographic proof that stored data was not modified. Memory lives in centralized databases that agents cannot outlive.

**0G-Memory** is a drop-in SDK that gives any AI agent persistent, verifiable, cross-session memory — backed entirely by the 0G decentralized stack.

### How it works

A single npm package (`0g-memory-sdk`) wraps three primitives:

| Method | Layer | What it does |
|---|---|---|
| `remember(key, value)` | 0G Log + 0G KV | Writes a value permanently to the Log layer (immutable, Merkle-provable) and registers a `key → rootHash` pointer in KV so it is retrievable from any machine |
| `recall(key)` | 0G KV → 0G Log | Resolves the key via the KV index, then fetches the value from the Log layer |
| `archive(record)` | 0G Log | Writes typed business records (invoices, payments, audit events) and returns a StorageScan URL as a verifiable proof |

Any agent with the same private key and agent ID gets full memory — across machines, restarts, and serverless deployments. No database. No vendor lock-in. No single point of failure.

### AgentBill — the reference application

To demonstrate real-world utility, we built **AgentBill**: an autonomous invoicing agent that uses the full 0G stack end-to-end.

1. **0G Compute** — a Qwen-2.5-7B model (TEE-verified inference) parses a natural-language job description and generates a structured invoice
2. **0G Memory** — the agent recalls the client's history from previous sessions to personalise the invoice and detect returning clients
3. **0G Storage** — the final invoice is archived to the Log layer, producing an immutable root hash
4. **0G Chain** — the invoice is registered on-chain via an escrow contract (`AgentPayment.sol`), and the client pays 0.001 OG from their MetaMask wallet on the Galileo testnet

The result is a fully autonomous agent that builds a verifiable, permanent financial history — without any traditional backend infrastructure.

Progress During Hackathon

### SDK (`0g-memory-sdk`)
- Designed and implemented the three-method API: `remember`, `recall`, `archive`
- Integrated with 0G Storage Log layer (permanent, content-addressed writes via `MemData` + `Indexer.upload`)
- Integrated with 0G Storage KV layer for the distributed key→rootHash index (`KvClient.getValue`, `Batcher` writes)
- Replaced all local-filesystem dependencies with `Indexer.downloadToBlob` so the SDK works in both Node.js and browser environments
- Added `deriveAgentId` utility for deterministic, collision-resistant agent identity from a wallet key
- Implemented a legacy local-file fallback in `recall()` with automatic KV migration — preserving backward compatibility for data written by earlier versions
- Published to npm as [`0g-memory-sdk@0.1.1`](https://www.npmjs.com/package/0g-memory-sdk) with dual ESM/CJS build via `tsup`, full TypeScript declarations, and JSDoc on every public method

### AgentBill Demo App
- Full-stack Next.js 14 application (App Router, server-side API routes)
- `/demo` — two-column editorial UI: wallet connect (MetaMask, 0G Galileo Testnet), invoice form, animated pipeline loader, invoice card, memory panel (returning client detection), storage/chain proof panel, on-chain pay button
- `/pitch` — 10-slide full-screen scroll-snap pitch deck with keyboard navigation and progress dots
- Dark/light theme toggle with no-flash localStorage persistence
- Deployed and running against the 0G Galileo testnet

### Smart Contract (`AgentPayment.sol`)
- Deployed to 0G Galileo testnet
- `registerInvoice(invoiceId, agentWallet, storageRootHash)` — links each invoice to its 0G Storage proof on-chain
- `pay(invoiceId)` — escrow-style payment with event emission for auditability

### Confirmed working on testnet
- AI invoice generation via 0G Compute (Qwen-2.5-7B)
- Storage archival to 0G Log layer with root hash proof
- Client memory recall across independent sessions
- On-chain invoice registration and payment on Galileo

Fundraising Status

0G-Memory is currently pre-seed and not actively fundraising. This project was built as a hackathon submission to demonstrate a concrete, production-ready use case for the 0G decentralized AI stack.

The immediate roadmap — if continued beyond the hackathon — would focus on:

- **Developer adoption** — grow `0g-memory-sdk` usage among AI agent developers building on 0G
- **Multi-agent coordination** — shared memory streams across agent swarms via namespaced KV streams
- **Encryption** — client-side encryption of memory values so only the agent's key can read them
- **Agent marketplace** — a registry of agents that expose memory-backed services, settled via AgentPayment contracts

We are open to conversations with the 0G ecosystem team and early-stage investors who see decentralized agent infrastructure as a foundational layer for the next wave of autonomous AI.
Team Leader
AAlpha Taco
Project Link
Deploy Ecosystem
0G-Galileo-Testnet0G-Galileo-Testnet
Sector
AIDeFiNFTInfra