Skip to main content
AI agents need a place to store what they’ve learned during a conversation — the user’s name, their preferences, the last topic discussed — and retrieve it on the next turn without passing the entire history through the context window. Cache-Pot’s REMEMBER and RECALL commands provide session-scoped key-value memory built directly into the store. Because it’s backed by Cache-Pot’s native hash type, you get persistence across restarts, optional TTL-based expiry, and direct hash access — all without any extra infrastructure.

How agent memory works

1

Store a fact

Call REMEMBER with a session identifier, a field name, and the value. Cache-Pot writes the field into a hash at the key mem:<session>.
REMEMBER user-123 name "Alice"
REMEMBER user-123 last_topic "vector databases"
2

Retrieve a specific field

Call RECALL with the session and field name to get a single value.
RECALL user-123 name         # "Alice"
RECALL user-123 last_topic   # "vector databases"
3

Retrieve the whole session

Omit the field argument to get all stored fields and values for the session.
RECALL user-123
# 1) "name" 2) "Alice" 3) "last_topic" 4) "vector databases"
REMEMBER session field value is equivalent to HSET mem:session field value, and RECALL session is equivalent to HGETALL mem:session. You can use hash commands directly on mem:<session> if you need finer control.

Basic example

REMEMBER user-123 name "Alice"
REMEMBER user-123 last_topic "vector databases"
REMEMBER user-123 language "English"

RECALL user-123 name           # "Alice"
RECALL user-123 last_topic     # "vector databases"
RECALL user-123                # all fields: name, last_topic, language

Setting TTL on agent memory

Sessions are persistent by default. Use EXPIRE on the underlying mem:<session> key to make a session expire automatically:
REMEMBER user-123 name "Alice"
EXPIRE mem:user-123 3600       # entire session expires in 1 hour

TTL mem:user-123               # seconds remaining
PERSIST mem:user-123           # remove the TTL if you change your mind
Use EXPIRE on a session after every interaction to implement a sliding inactivity timeout — each new REMEMBER call refreshes the window.

Multi-agent example

The snippet below shows an agent storing context during one turn and reading it back on a subsequent turn, using the standard redis-py client.
import redis

r = redis.Redis(host='localhost', port=6379)

session = 'agent-session-abc'

# Turn 1: store what the agent learned
r.execute_command('REMEMBER', session, 'user_preference', 'concise answers')
r.execute_command('REMEMBER', session, 'last_query', 'explain transformers')

# Set a 2-hour inactivity TTL
r.expire(f'mem:{session}', 7200)

# Turn 2 (same or different process): recall context
pref = r.execute_command('RECALL', session, 'user_preference')
print(pref)   # b'concise answers'

last_q = r.execute_command('RECALL', session, 'last_query')
print(last_q) # b'explain transformers'

# Recall everything the agent knows about this session
all_mem = r.execute_command('RECALL', session)
print(all_mem)
# [b'user_preference', b'concise answers', b'last_query', b'explain transformers']

Using via MCP

Agent memory is also accessible from Cache-Pot’s built-in MCP server. AI frameworks that support the Model Context Protocol can call the remember and recall tools directly — no Redis client required.
MCP ToolMaps toDescription
rememberREMEMBER session key valueStore a fact in the session namespace.
recallRECALL session [key]Retrieve one field or the entire session.
See the MCP integration guide for setup instructions and a full list of available tools.
Use descriptive, collision-resistant session names such as user-<uuid> or conversation-<uuid>. Because all session hashes share the same keyspace under the mem: prefix, a predictable naming scheme prevents one session from accidentally overwriting another.