TOOL WIKI · MEMORY & STATE
Redis
Provides fast data structures for caches, session context, and application state.
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.
Separate working conversation state from candidate long-term facts.
candidateTo 02 · Write policyRetain only permitted information and preserve where it came from.
retainTo 03 · RedisTime-bounded context and frequently accessed session data. Configure expiry, durability, and eviction intentionally; defaults are not a policy.
recordsTo 05 · Context builderUse verified tenant and subject identifiers when retrieving memory.
queryBack to 03 · RedisChoose useful records within the current context budget.
contextBack to 01 · InteractionApply corrections and deletion to records, derived indexes, and caches.
maintainBack to 03 · Redis
Time-bounded context and frequently accessed session data. Configure expiry, durability, and eviction intentionally; defaults are not a policy.
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.
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 redisTry a small integration
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
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
Explore the same layer
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.