0G Mem

The verifiable memory and runtime stack for sovereign AI agents.

0G Mem

Created At

Open Agents

Project Description

0G Mem is a decentralized AI agent runtime and memory stack designed to break vendor lock-in and give users true ownership over their AI's knowledge and operations. Built on the 0G Labs infrastructure, it decouples the core components of AI agents—memory, inference, and interface—into an open, verifiable, and interoperable system.

The architecture consists of three primary layers. The Memory layer provides a persistent, evolving knowledge base for agents. User context is encrypted client-side using their wallet key, stored on the decentralized 0G Storage network, and its state is anchored on the 0G Chain via Merkle proofs. This memory is dynamic; it strengthens with retrieval and decays with disuse, with every change being provably recorded on-chain. The Agent Runtime layer shifts inference from proprietary APIs to decentralized 0G Compute, ensuring operational sovereignty. Every execution, including memory state, tool calls, and decisions, is logged to 0G's Data Availability layer, creating a fully transparent and auditable trail of the agent's actions.

Finally, the Pluggability layer ensures broad compatibility. 0G Mem exposes a Memory-Centric Protocol (MCP) server, allowing seamless integration with any MCP-compatible client, such as Claude Desktop or Cursor, without requiring code changes. The system is accessible through multiple interfaces, including a Next.js web application, a Telegram bot, and a terminal TUI, all connecting to the same unified, user-owned memory store. This multi-faceted approach empowers developers to build and deploy sovereign AI agents that are portable, transparent, and truly owned by their users.

How it's Made

0G Mem is built in Python with four tightly integrated 0G Labs components. The memory layer uses 0G Storage for encrypted blob persistence, 0G Chain (EVM, chain ID 16602) for Merkle root anchoring via a custom MemoryRegistry contract, and 0G DA for immutable audit logging via gRPC DisperseBlob. Inference runs through 0G Compute via an OpenAI-compatible client.

The trickiest integration was 0G Storage — no Python SDK exists, so every upload/download spawns a Node.js subprocess (scripts/zg_storage.js using @0gfoundation/0g-ts-sdk) and reads the JSON result from the last line of stdout. Hacky, but it works across all deployment targets.

Embeddings use sentence-transformers/all-MiniLM-L6-v2 locally (384-dim), with 0G Serving and OpenAI as fallbacks. The Merkle tree is a custom Python implementation — SHA-256 leaves over blob IDs, with inclusion proofs verifiable both off-chain and via MemoryRegistry.verifyInclusion() on-chain.

Session batching was a key design decision: multiple memory.add() calls within a turn are buffered in a MemorySession context manager, writing to storage and DA immediately but deferring the chain updateRoot() to a single transaction per turn — dramatically reducing gas costs.

Cross-machine sync (push_index / pull_index) works by uploading an encrypted full-index snapshot to 0G Storage, then storing its blob ID in the daTxHash field of an updateRoot call — piggybacking the chain's own history as a discovery mechanism, so any machine with the same wallet key can scan backwards and find all snapshots.

Memory is exposed via three interfaces (Textual TUI, Telegram bot, MCP server over stdio) all sharing the same encrypted store — wallet address as canonical agent_id, derived deterministically via eth_account.

background image mobile

Join the mailing list

Get the latest news and updates