Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

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:

  1. One collection, partitioned by a scope key built with scope_key(...).

  2. Write observations with add_texts (append-only); correct facts with upsert_texts.

  3. Recall the most relevant memories with search_text, scoped to the user with Eq.

  4. Persist with save() so memory survives restarts.

Telys embeds and searches through the signed native runtime. Install it with pipx install telys (or pip install telys), sign in with telys login, then verify with telys runtime verify. The Algenta* embedders also need the native kernel, which the verified install provides. See Install Telys and Verify your install.

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 key

Full 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.

add_texts is append-only and raises KeyError if an id exists — what you want for observations. Use upsert_texts (as remember_fact does) to overwrite in place, such as a changing preference. See Add & upsert records.

Next steps

Last updated

Was this helpful?