Agent long-term memory
Give an AI agent durable, per-user memory with Telys — partition by user, write observations, and recall relevant history before every turn.
Give an agent durable memory that survives process restarts: one Telys collection, partitioned per user, that you write observations into and recall from before each turn. The store lives on disk under a path you control — no external database, no network calls.
The pattern repeats across agent frameworks:
One collection, partitioned by a
scopekey built withscope_key(...).Write observations with
add_texts(append-only); correct facts withupsert_texts.Recall the most relevant memories with
search_text, scoped to the user withEq.Persist with
save()so memory survives restarts.
Why partition per user
Every memory belongs to one user, and a query must never leak another user's memories. Telys enforces this at the storage layer: the collection is partitioned by a scope column, and a scoped query only touches its own partition. Compose the scope key with scope_key(...), which joins its parts with a unit separator so keys never collide:
from telys import scope_key
scope_key("user", "alice") # -> "user\x1falice"
scope_key("user", "alice", "project", "telys") # multi-part, still one keyFull example
AgentMemory wraps a Telys collection with the four operations an agent needs: remember an observation, recall relevant memories, correct a fact, and forget by id.
Recall before every turn
Recall first, generate second. Before building the prompt, pull the most relevant memories for the current user and inject them as context. After the turn, write any new observations back.
Expected result
Running agent_memory.py prints Alice's memories ranked by relevance, the language preference highest. Bob's memory never appears — the query is scoped to Alice:
After save(), the collection is written under ./agent-memory/memories/; collection.json is the commit point. Re-running the script reopens the saved collection with the memories intact — that is the long-term part.
Next steps
Last updated
Was this helpful?