Decentralised AI agent memory SDK — powered by Shelby Protocol and Aptos
Project description
shelmem
Decentralised AI agent memory SDK for Python.
Store agent memories on Shelby Protocol's decentralised hot storage with on-chain proof via Aptos.
Install
pip install shelmem
Usage
from shelmem import ShelMem
mem = ShelMem(
supabase_url="https://your-project.supabase.co",
supabase_key="your-service-role-key",
shelby_api_key="your-shelby-api-key", # optional
aptos_private_key="your-ed25519-private-key", # required when mock=False
network="testnet", # testnet | shelbynet
mock=True, # default: True
)
write()
Store a memory for an agent. Async method.
result = await mem.write(
agent_id="agent-001",
memory="User prefers concise responses",
context="preferences",
metadata={"source": "chat"}, # optional
)
print(result.shelby_object_id) # shelby://...
print(result.aptos_tx_hash) # 0x...
print(result.timestamp) # 2025-01-15T10:30:00Z
recall()
Retrieve memories for an agent. Async method.
memories = await mem.recall(
agent_id="agent-001",
context="preferences", # optional
limit=10, # optional, default 10
)
for m in memories:
print(m.memory, m.context, m.timestamp, m.aptos_tx_hash)
delete()
Remove a memory by its Supabase row ID. Synchronous method.
mem.delete("uuid-of-memory-row")
How It Works
- write() encodes the memory to UTF-8 bytes, uploads to Shelby via HTTP gateway, records metadata in Supabase, and returns the Shelby address + Aptos proof
- recall() queries Supabase metadata by agent_id/context, downloads content bytes from Shelby, and returns decoded strings
- Every write produces a
shelby://address and an Aptos transaction hash as cryptographic proof
Mock Mode
By default, mock=True generates deterministic hash-based addresses without network calls. Set mock=False and provide aptos_private_key to write to the live Shelby testnet.
Environment Variables
The SDK reads these if not passed in the constructor:
| Variable | Description |
|---|---|
SHELBY_API_KEY |
Shelby Protocol API key |
SHELBY_ACCOUNT_PRIVATE_KEY |
Ed25519 private key for signing |
SHELBY_NETWORK |
testnet or shelbynet |
SHELBY_MOCK |
true or false |
SUPABASE_URL |
Supabase project URL |
SUPABASE_ANON_KEY |
Supabase anon/service key |
Supabase Setup
Create a Supabase project, then run this SQL in the SQL Editor:
CREATE EXTENSION IF NOT EXISTS vector;
CREATE TABLE IF NOT EXISTS memories (
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
agent_id TEXT NOT NULL,
context TEXT NOT NULL,
memory_preview TEXT,
shelby_object_id TEXT NOT NULL,
aptos_tx_hash TEXT,
content_hash CHAR(64),
memory_type TEXT DEFAULT 'observation',
verified BOOLEAN,
embedding vector(1536),
metadata JSONB DEFAULT '{}',
created_at TIMESTAMPTZ DEFAULT now(),
updated_at TIMESTAMPTZ DEFAULT now()
);
CREATE INDEX idx_memories_agent_id ON memories(agent_id);
CREATE INDEX idx_memories_agent_context ON memories(agent_id, context);
CREATE INDEX idx_memories_created_at ON memories(created_at DESC);
ALTER TABLE memories ENABLE ROW LEVEL SECURITY;
CREATE POLICY "Allow all" ON memories FOR ALL USING (true) WITH CHECK (true);
Types
@dataclass
class WriteResult:
shelby_object_id: str
aptos_tx_hash: str
content_hash: str
memory_type: str
timestamp: str
@dataclass
class MemoryRecord:
memory: str
context: str
timestamp: str
aptos_tx_hash: str
content_hash: str
memory_type: str
verified: Optional[bool] # True=authentic, False=tampered, None=unverifiable
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file shelmem-0.2.0.tar.gz.
File metadata
- Download URL: shelmem-0.2.0.tar.gz
- Upload date:
- Size: 13.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0473de2cffbce4fd7e2afdf4e38c31920d8d8646119f530fe3c6a91888e79e3a
|
|
| MD5 |
52df6280a4aee0e1184d8f2b378f8a01
|
|
| BLAKE2b-256 |
42e3223675420ed0cdc2c290b208ea9b4bb297c539bfc82191944af90d8e48b4
|
File details
Details for the file shelmem-0.2.0-py3-none-any.whl.
File metadata
- Download URL: shelmem-0.2.0-py3-none-any.whl
- Upload date:
- Size: 13.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5caa0013b8e95a830ee076ce91e044f2b9cce3a7db9d2d1d0bb476d70f573ba1
|
|
| MD5 |
95cd64da568251ef4bf621c6ead62374
|
|
| BLAKE2b-256 |
5f961a0ff528f9ae21b32bce3e66ddf2197042a50c60f84199cb1ea5e504dd4c
|