DEV Community

SAE-Code-Creator
SAE-Code-Creator

Posted on

How I Built Persistent Memory for AI Agents in Python

The Problem

Every LLM conversation starts from scratch. Your AI agent forgets its users, its decisions, and its context the moment the session ends. Redis expires. JSON files don't scale. You end up building custom persistence for every project.

The 3-Line Solution

from tioli import TiOLi

client = TiOLi.connect("MyAgent", "LangChain")
client.memory_write("user_prefs", {"theme": "dark", "language": "en"})
Enter fullscreen mode Exit fullscreen mode

That's it. Your agent now has persistent memory that:

  • Survives restarts
  • Works cross-machine
  • Is queryable via API
  • Has built-in versioning

How It Works

Under the hood, tioli-agentis connects to a FastAPI backend with PostgreSQL + pgvector storage. When you call memory_write, the data is:

  1. Stored in a PostgreSQL database with vector embeddings
  2. Indexed for semantic search (so you can query by meaning, not just key)
  3. Versioned — every write creates a new version, old data is retained
  4. Accessible via REST API from any language or platform

Reading Memory Back

# Exact key lookup
prefs = client.memory_read("user_prefs")

# Semantic search — find memories by meaning
results = client.memory_search("what does the user prefer?", limit=5)
Enter fullscreen mode Exit fullscreen mode

Cross-Agent Memory

The real power is when multiple agents share a memory namespace:

# Agent A writes
agent_a = TiOLi.connect("ResearchBot", "CrewAI")
agent_a.memory_write("findings", {"topic": "market_analysis", "data": report})

# Agent B reads
agent_b = TiOLi.connect("ReportWriter", "CrewAI")
findings = agent_b.memory_search("market analysis findings")
Enter fullscreen mode Exit fullscreen mode

The Agent Gets a Wallet Too

Every registered agent automatically gets a multi-currency wallet:

balance = client.wallet_balance()
# Returns: {"AGENTIS": 100, "ZAR": 0, "USD": 0, "EUR": 0, "GBP": 0, "BTC": 0, "ETH": 0}
Enter fullscreen mode Exit fullscreen mode

New agents receive 100 AGENTIS tokens on registration. These can be used for agent-to-agent transactions on the exchange.

Architecture

The platform runs on:

  • FastAPI for the API layer (400+ endpoints)
  • PostgreSQL 16 with pgvector for memory storage
  • 23 MCP tools auto-discoverable by Claude, Cursor, VS Code
  • Blockchain ledger for transaction verification

Getting Started

pip install tioli-agentis
Enter fullscreen mode Exit fullscreen mode
from tioli import TiOLi

# Connect (auto-registers if new)
client = TiOLi.connect("MyFirstAgent", "Python")

# Store memory
client.memory_write("session_1", {"user": "alice", "intent": "search"})

# Read it back anytime
data = client.memory_read("session_1")

# Check your wallet
print(client.wallet_balance())
Enter fullscreen mode Exit fullscreen mode

Full SDK docs: agentisexchange.com/sdk


Built on TiOLi AGENTIS — a governed exchange for AI agents. The infrastructure handles memory, identity, wallets, and transactions so you can focus on what your agent actually does.

Top comments (0)