TOOL WIKI · MEMORY & STATE

Redis

Provides fast data structures for caches, session context, and application state.

Download example files Code + setup + checks in a ZIP
Jump to a section 10 sections

EXAMPLE USE CASE

Cache a user preference with a real TTL

A returning user’s preference or an unfinished run needs an explicit owner, storage lifetime and recall rule.

Input
A tenant/user-qualified hash key and a one-hour lifetime.
Expected output
The value, source/version fields and a positive TTL.
  • Success check: The stored preference can be recalled for the intended user. Inspect the record and its source rather than only the generated answer.
  • Try a failure: A zero/missing TTL or wrong-tenant key should fail the application’s recall contract.

Example scope: Actual Redis transaction and expiry; a cache is not the authoritative durable source.

Official reference · Redis

WHAT IT ISData store
WHERE IT FITSMemory & state
SEE HOW THE SYSTEM FITS TOGETHERSELECT A COMPONENT
candidateretainqueryrecordscontextmaintainInteractionSubject + evidenceWrite policySelect and verifyRedisData storeRecall requestAuthenticated scopeContext builderRelevant selected factsLifecycle controlsCorrect, expire, delete
  1. Separate working conversation state from candidate long-term facts.

  2. Retain only permitted information and preserve where it came from.

  3. Time-bounded context and frequently accessed session data. Configure expiry, durability, and eviction intentionally; defaults are not a policy.

  4. Use verified tenant and subject identifiers when retrieving memory.

  5. Choose useful records within the current context budget.

  6. Apply corrections and deletion to records, derived indexes, and caches.

Redis

Time-bounded context and frequently accessed session data. Configure expiry, durability, and eviction intentionally; defaults are not a policy.

Follow the arrows, then select a component to inspect its responsibility. On mobile, downward arrows connect the next step; bent arrows identify branches and return paths. Select a destination to jump to that component.

When to consider it

  • Time-bounded context and frequently accessed session data.

A design decision to make

  • Configure expiry, durability, and eviction intentionally; defaults are not a policy.

Prerequisites and setup

  • Docker and Python 3.11+. This is a loopback-only scratch Redis instance.
Shell
docker run --name asg-redis -d -p 127.0.0.1:6380:6379 redis:8
python3 -m venv .venv
source .venv/bin/activate
pip install redis

Try a small integration

memory.py

Python · memory.py
import redis

client = redis.Redis(host="localhost", port=6380, decode_responses=True)
key = "tenant:a:user:u1:preference:format"
with client.pipeline(transaction=True) as pipeline:
    pipeline.hset(key, mapping={"value":"bullets","source":"explicit-user-request","version":"1"})
    pipeline.expire(key, 3600)
    pipeline.execute()
assert client.hget(key,"value") == "bullets"
assert client.ttl(key) > 0
assert not client.exists("tenant:b:user:u1:preference:format")
print(client.hgetall(key), "ttl:", client.ttl(key))

Run and check the result

Shell
python memory.py
  • The stored preference can be recalled for the intended user. Inspect the record and its source rather than only the generated answer.
  • A different user must not inherit this preference.

Common failures

  • Extraction acceptance does not establish immediate query visibility; inspect job/index state when results are empty.
  • Do not silently copy memory across users after a failed lookup.

Production decisions

  • Define allowed memory types, evidence/provenance, correction, expiry and user deletion before accepting automatic writes.
  • Derive user and tenant scope from authenticated application state. Test cross-user recall, expired facts and deletion from every derived index.
  • Choose eviction, persistence and replication policies deliberately. A cache eviction must not destroy the only authoritative copy of a required record.

Keep exploring

A layered architecture for agent memoryA context pipeline for a long-running agent

Explore the same layer

Mem0LettaZepGraphiti

Compare candidates on your own workload. This entry describes a product’s role; it is not a claim that products in the category are interchangeable.