Redis Agent Memory quickstart
Store and retrieve a conversation, then recall long-term memory with Python, TypeScript, cURL, or the Iris CLI.
Build the memory for a travel assistant: save a conversation, retrieve it, and recall the user’s food preferences in a later conversation.
Before you begin
To complete this quickstart, you need:
- A Redis Cloud account that can create Redis Agent Memory services.
- An eligible Redis Cloud database, or permission to create one.
The database must be active, run a supported Redis version, and use a Pro or Essentials plan. It must also have a public endpoint, Redis Search, and the default user enabled.
Redis Agent Memory doesn't support Flex, Active-Active, or AWS PrivateLink databases.
For the complete list, see prerequisites and limitations.
Follow one tab throughout the page. The Python SDK and command-line interface (CLI) require Python 3.11 or later. The cURL and CLI examples use Bash and jq. The CLI reads sessions and memories but does not write them, so the CLI tab starts at Retrieve the conversation.
Create a Redis Agent Memory service
-
Sign in to the Redis Cloud console.
-
Select Agent Memory under Iris in the navigation menu.
-
Select Create Agent Memory service, or New service if you already have a service. Then select Customize settings.
-
Enter a service name, select an eligible database, and select its
defaultuser. -
Under Memory configuration, enter these values:
Setting Value What it controls Short-term TTL 1dayHow long session memory is retained. Long-term TTL 365daysHow long long-term memories are retained. Extraction cadence 1minuteHow often session events are processed for extraction. One minute is for this quickstart; use a longer production interval unless you need rapid extraction. -
Select Create.
-
On the service's Configuration tab, select Create API key and create a key with access to the service. Copy the key and store it securely.
Redis Cloud displays the API key's token only once. If you lose it, create a new key.
The one-minute extraction interval makes the result easier to observe in this example. For screenshots and configuration details, see create a Redis Agent Memory service.
Connect to the service
-
For Python or CLI examples, install the unified package:
python -m venv .venv source .venv/bin/activate python -m pip install 'redis-iris>=1.4.0' -
For TypeScript, use Node.js 22 or later and install the Agent Memory SDK.
npm install '@redis-iris/agent-memory@^1.5.0' -
For cURL, install
curlandjq. -
Open the Redis Agent Memory service in the Redis Cloud console. On the Configuration tab, copy the Store ID and the URL from the URL List. Save them with your API key in
.env. Use the endpoint's base address, includinghttps://, without the/iris/data/v1/agent-memory/...path.IRIS_AGENT_MEMORY_URL='<data-plane-endpoint>' IRIS_AGENT_MEMORY_STORE_ID='<store-id>' IRIS_AGENT_MEMORY_API_KEY='<api-key>' -
Load the file in the shell where you run the examples:
set -a; source .env; set +a -
Expand an example to copy the complete program. Use the file name and command for your tab.
Tab File Command Python quickstart.pypython quickstart.pyTypeScript quickstart.mtsnpx tsx quickstart.mtscURL quickstart.shbash quickstart.shCLI quickstart.cli.shbash quickstart.cli.sh
Keep .env out of source control and keys out of application logs and model prompts. Use iris.toml profiles for several deployments.
For a self-managed service with ownership enforcement, use the authenticated client setup in Delegate a user with an agent key and replace quickstart-user with the verified user ID.
AgentMemory.from_env() reads the connection values. Its .client property exposes every Agent Memory operation; the conversation, recall, remember, and forget methods cover the common agent tasks. Check that the overall status and each feature are HEALTHY.
import time
from redis_iris.agent_memory import AgentMemory
OWNER_ID = "quickstart-user"
SESSION_ID = "travel-planning-session"
memory = AgentMemory.from_env()
health = memory.client.store_health()
print(health.status.value)
for name, feature in health.features.items():
print(f" {name}: {feature.status.value}")
import time
from redis_iris.agent_memory import AgentMemory
OWNER_ID = "quickstart-user"
SESSION_ID = "travel-planning-session"
memory = AgentMemory.from_env()
health = memory.client.store_health()
print(health.status.value)
for name, feature in health.features.items():
print(f" {name}: {feature.status.value}")
conversation = memory.conversation(owner=OWNER_ID, session_id=SESSION_ID)
saved = conversation.user(
"I am visiting Tokyo and Kyoto next month. I am vegetarian and prefer spicy food."
)
print("Saved event", saved.event_id)
transcript = conversation.transcript()
print("Owner:", transcript.owner)
for event in transcript.events:
print(event.role, event.actor_id, event.text)
question = "What dietary requirements and food preferences does the user have?"
for _ in range(30): # extraction runs in the background
known = memory.recall(question, owner=OWNER_ID)
if known:
break
time.sleep(10)
print(known.as_prompt())
import { AgentMemory } from "@redis-iris/agent-memory";
const memory = new AgentMemory({
serverURL: process.env.IRIS_AGENT_MEMORY_URL!,
storeId: process.env.IRIS_AGENT_MEMORY_STORE_ID!,
apiKey: process.env.IRIS_AGENT_MEMORY_API_KEY!,
});
const OWNER_ID = "quickstart-user";
const SESSION_ID = "travel-planning-session";
const health = await memory.storeHealth();
console.log(health.status);
for (const [name, feature] of Object.entries(health.features)) {
console.log(` ${name}: ${feature.status}`);
}
import { AgentMemory } from "@redis-iris/agent-memory";
const memory = new AgentMemory({
serverURL: process.env.IRIS_AGENT_MEMORY_URL!,
storeId: process.env.IRIS_AGENT_MEMORY_STORE_ID!,
apiKey: process.env.IRIS_AGENT_MEMORY_API_KEY!,
});
const OWNER_ID = "quickstart-user";
const SESSION_ID = "travel-planning-session";
const health = await memory.storeHealth();
console.log(health.status);
for (const [name, feature] of Object.entries(health.features)) {
console.log(` ${name}: ${feature.status}`);
}
const saved = await memory.addSessionEvent(SESSION_ID, {
actorId: OWNER_ID,
role: "USER",
content: [{ text: "I am visiting Tokyo and Kyoto next month. I am vegetarian and prefer spicy food." }],
createdAt: new Date(),
idempotencyKey: crypto.randomUUID(),
});
console.log("Saved event", saved.event.eventId);
const transcript = await memory.getSessionMemory(SESSION_ID);
console.log("Owner:", transcript.ownerId);
for (const event of transcript.events) {
console.log(event.role, event.actorId, event.content);
}
const query = "What dietary requirements and food preferences does the user have?";
for (let attempt = 0; attempt < 30; attempt += 1) {
const { items } = await memory.searchLongTermMemory({
query,
filter: { ownerId: { eq: OWNER_ID } },
limit: 5,
});
if (items.length > 0) {
for (const item of items) console.log(item.text);
break;
}
await new Promise((resolve) => setTimeout(resolve, 10_000));
}
set -euo pipefail
MEMORY_API="${IRIS_AGENT_MEMORY_URL%/}/iris/data/v1/agent-memory/stores/$IRIS_AGENT_MEMORY_STORE_ID"
OWNER_ID=quickstart-user
SESSION_ID=travel-planning-session
curl --fail-with-body --silent --show-error \
"$MEMORY_API/health" \
-H "Authorization: Bearer $IRIS_AGENT_MEMORY_API_KEY" | jq .
set -euo pipefail
set -euo pipefail
MEMORY_API="${IRIS_AGENT_MEMORY_URL%/}/iris/data/v1/agent-memory/stores/$IRIS_AGENT_MEMORY_STORE_ID"
OWNER_ID=quickstart-user
SESSION_ID=travel-planning-session
curl --fail-with-body --silent --show-error \
"$MEMORY_API/health" \
-H "Authorization: Bearer $IRIS_AGENT_MEMORY_API_KEY" | jq .
jq -n --arg owner "$OWNER_ID" --arg now "$(date -u +%Y-%m-%dT%H:%M:%SZ)" --arg key "$(uuidgen)" '{
actorId: $owner,
role: "USER",
content: [{text: "I am visiting Tokyo and Kyoto next month. I am vegetarian and prefer spicy food."}],
createdAt: $now,
idempotencyKey: $key
}' > event.json
curl --fail-with-body --silent --show-error \
-X POST "$MEMORY_API/sessions/$SESSION_ID/events" \
-H "Authorization: Bearer $IRIS_AGENT_MEMORY_API_KEY" \
-H 'Content-Type: application/json' --data-binary @event.json | jq .
curl --fail-with-body --silent --show-error \
"$MEMORY_API/sessions/$SESSION_ID" \
-H "Authorization: Bearer $IRIS_AGENT_MEMORY_API_KEY" | jq '.events[] | {role, actorId, content}'
jq -n --arg owner "$OWNER_ID" '{
query: "What dietary requirements and food preferences does the user have?",
filter: {ownerId: {eq: $owner}},
limit: 5
}' > search.json
for _ in $(seq 30); do # extraction runs in the background
RESULTS=$(curl --fail-with-body --silent --show-error \
-X POST "$MEMORY_API/memories/search" \
-H "Authorization: Bearer $IRIS_AGENT_MEMORY_API_KEY" \
-H 'Content-Type: application/json' --data-binary @search.json)
[ "$(jq '.items | length' <<< "$RESULTS")" -gt 0 ] && break
sleep 10
done
jq '.items[] | {memoryId, text, memoryType}' <<< "$RESULTS"
Save a conversation
Session memory is the conversation transcript. Each message is an event, stored with the conversation's session ID and the sender's actor ID. Save a user's travel plans:
conversation = memory.conversation(owner=OWNER_ID, session_id=SESSION_ID)
saved = conversation.user(
"I am visiting Tokyo and Kyoto next month. I am vegetarian and prefer spicy food."
)
print("Saved event", saved.event_id)
const saved = await memory.addSessionEvent(SESSION_ID, {
actorId: OWNER_ID,
role: "USER",
content: [{ text: "I am visiting Tokyo and Kyoto next month. I am vegetarian and prefer spicy food." }],
createdAt: new Date(),
idempotencyKey: crypto.randomUUID(),
});
console.log("Saved event", saved.event.eventId);
jq -n --arg owner "$OWNER_ID" --arg now "$(date -u +%Y-%m-%dT%H:%M:%SZ)" --arg key "$(uuidgen)" '{
actorId: $owner,
role: "USER",
content: [{text: "I am visiting Tokyo and Kyoto next month. I am vegetarian and prefer spicy food."}],
createdAt: $now,
idempotencyKey: $key
}' > event.json
curl --fail-with-body --silent --show-error \
-X POST "$MEMORY_API/sessions/$SESSION_ID/events" \
-H "Authorization: Bearer $IRIS_AGENT_MEMORY_API_KEY" \
-H 'Content-Type: application/json' --data-binary @event.json | jq .
Run the write once. Repeating it with a new idempotency key adds the same message again.
Retrieve the conversation
Retrieve the session to check that the message was stored:
transcript = conversation.transcript()
print("Owner:", transcript.owner)
for event in transcript.events:
print(event.role, event.actor_id, event.text)
const transcript = await memory.getSessionMemory(SESSION_ID);
console.log("Owner:", transcript.ownerId);
for (const event of transcript.events) {
console.log(event.role, event.actorId, event.content);
}
curl --fail-with-body --silent --show-error \
"$MEMORY_API/sessions/$SESSION_ID" \
-H "Authorization: Bearer $IRIS_AGENT_MEMORY_API_KEY" | jq '.events[] | {role, actorId, content}'
set -euo pipefail
iris agent-memory sessions show travel-planning-session
set -euo pipefail
iris agent-memory sessions show travel-planning-session
iris agent-memory memories search \
"What dietary requirements and food preferences does the user have?" \
--owner quickstart-user --prompt
What to expect: One USER event from quickstart-user with the travel message. Redis Agent Memory adds an event ID and timestamps, so the application can recover the conversation later using only the session ID.
Recall an extracted preference
Redis Agent Memory processes session events in the background and creates long-term memories for information that may be useful in later conversations. You configured the extraction cadence to one minute when you created the service. The examples search every 10 seconds until a memory appears; the CLI runs one search, so rerun it if the result is empty.
question = "What dietary requirements and food preferences does the user have?"
for _ in range(30): # extraction runs in the background
known = memory.recall(question, owner=OWNER_ID)
if known:
break
time.sleep(10)
print(known.as_prompt())
const query = "What dietary requirements and food preferences does the user have?";
for (let attempt = 0; attempt < 30; attempt += 1) {
const { items } = await memory.searchLongTermMemory({
query,
filter: { ownerId: { eq: OWNER_ID } },
limit: 5,
});
if (items.length > 0) {
for (const item of items) console.log(item.text);
break;
}
await new Promise((resolve) => setTimeout(resolve, 10_000));
}
jq -n --arg owner "$OWNER_ID" '{
query: "What dietary requirements and food preferences does the user have?",
filter: {ownerId: {eq: $owner}},
limit: 5
}' > search.json
for _ in $(seq 30); do # extraction runs in the background
RESULTS=$(curl --fail-with-body --silent --show-error \
-X POST "$MEMORY_API/memories/search" \
-H "Authorization: Bearer $IRIS_AGENT_MEMORY_API_KEY" \
-H 'Content-Type: application/json' --data-binary @search.json)
[ "$(jq '.items | length' <<< "$RESULTS")" -gt 0 ] && break
sleep 10
done
jq '.items[] | {memoryId, text, memoryType}' <<< "$RESULTS"
iris agent-memory memories search \
"What dietary requirements and food preferences does the user have?" \
--owner quickstart-user --prompt
What to expect: Results similar to User is vegetarian and User prefers spicy food. Your application did not create these memories directly. Redis Agent Memory derived them from the session event. The exact text and memory types can vary.
The extracted memory remains searchable after the session expires, subject to the long-term memory time to live (TTL). You can change the extraction cadence and both TTLs in the Redis Agent Memory service configuration.
Clean up
Run cleanup only on the store and owner you used for the quickstart. The examples delete the quickstart session and memories owned by quickstart-user. The CLI also deletes that owner’s other sessions.
from redis_iris.agent_memory import AgentMemory
memory = AgentMemory.from_env()
memory.client.delete_session_memory(session_id="travel-planning-session")
memory_ids = []
cursor = None
while True:
page = memory.client.search_long_term_memory(request={
"filter_": {"owner_id": {"eq": "quickstart-user"}},
"limit": 100,
"cursor": cursor,
})
memory_ids.extend(item.memory_id for item in page.items)
cursor = page.next_cursor
if not cursor:
break
for start in range(0, len(memory_ids), 100):
memory.client.bulk_delete_long_term_memories(memory_ids=memory_ids[start:start + 100])
from redis_iris.agent_memory import AgentMemory
memory = AgentMemory.from_env()
memory.client.delete_session_memory(session_id="travel-planning-session")
memory_ids = []
cursor = None
while True:
page = memory.client.search_long_term_memory(request={
"filter_": {"owner_id": {"eq": "quickstart-user"}},
"limit": 100,
"cursor": cursor,
})
memory_ids.extend(item.memory_id for item in page.items)
cursor = page.next_cursor
if not cursor:
break
for start in range(0, len(memory_ids), 100):
memory.client.bulk_delete_long_term_memories(memory_ids=memory_ids[start:start + 100])
import { AgentMemory } from "@redis-iris/agent-memory";
const memory = new AgentMemory({
serverURL: process.env.IRIS_AGENT_MEMORY_URL!,
storeId: process.env.IRIS_AGENT_MEMORY_STORE_ID!,
apiKey: process.env.IRIS_AGENT_MEMORY_API_KEY!,
});
await memory.deleteSessionMemory("travel-planning-session");
const memoryIds: string[] = [];
let cursor: string | undefined;
do {
const page = await memory.searchLongTermMemory({
filter: { ownerId: { eq: "quickstart-user" } },
limit: 100,
cursor,
});
memoryIds.push(...page.items.map((item) => item.memoryId));
cursor = page.nextCursor;
} while (cursor);
for (let start = 0; start < memoryIds.length; start += 100) {
await memory.bulkDeleteLongTermMemories({ memoryIds: memoryIds.slice(start, start + 100) });
}
import { AgentMemory } from "@redis-iris/agent-memory";
const memory = new AgentMemory({
serverURL: process.env.IRIS_AGENT_MEMORY_URL!,
storeId: process.env.IRIS_AGENT_MEMORY_STORE_ID!,
apiKey: process.env.IRIS_AGENT_MEMORY_API_KEY!,
});
await memory.deleteSessionMemory("travel-planning-session");
const memoryIds: string[] = [];
let cursor: string | undefined;
do {
const page = await memory.searchLongTermMemory({
filter: { ownerId: { eq: "quickstart-user" } },
limit: 100,
cursor,
});
memoryIds.push(...page.items.map((item) => item.memoryId));
cursor = page.nextCursor;
} while (cursor);
for (let start = 0; start < memoryIds.length; start += 100) {
await memory.bulkDeleteLongTermMemories({ memoryIds: memoryIds.slice(start, start + 100) });
}
set -euo pipefail
MEMORY_API="${IRIS_AGENT_MEMORY_URL%/}/iris/data/v1/agent-memory/stores/$IRIS_AGENT_MEMORY_STORE_ID"
AUTH="Authorization: Bearer $IRIS_AGENT_MEMORY_API_KEY"
curl --fail-with-body --silent --show-error -X DELETE \
"$MEMORY_API/sessions/travel-planning-session" -H "$AUTH"
CURSOR=
IDS='[]'
while :; do
PAGE=$(jq -n --arg cursor "$CURSOR" '{
filter: {ownerId: {eq: "quickstart-user"}}, limit: 100
} + (if $cursor == "" then {} else {cursor: $cursor} end)' |
curl --fail-with-body --silent --show-error -X POST "$MEMORY_API/memories/search" \
-H "$AUTH" -H 'Content-Type: application/json' --data-binary @-)
IDS=$(jq -c --argjson ids "$IDS" '$ids + [.items[].memoryId]' <<< "$PAGE")
CURSOR=$(jq -r '.nextCursor // empty' <<< "$PAGE")
if [ -z "$CURSOR" ]; then break; fi
done
while IFS= read -r BODY; do
curl --fail-with-body --silent --show-error -X POST "$MEMORY_API/memories/bulk-delete" \
-H "$AUTH" -H 'Content-Type: application/json' --data "$BODY" | jq .
done < <(jq -c '. as $ids | range(0; length; 100) as $start | {memoryIds: $ids[$start:$start+100]}' <<< "$IDS")
set -euo pipefail
MEMORY_API="${IRIS_AGENT_MEMORY_URL%/}/iris/data/v1/agent-memory/stores/$IRIS_AGENT_MEMORY_STORE_ID"
AUTH="Authorization: Bearer $IRIS_AGENT_MEMORY_API_KEY"
curl --fail-with-body --silent --show-error -X DELETE \
"$MEMORY_API/sessions/travel-planning-session" -H "$AUTH"
CURSOR=
IDS='[]'
while :; do
PAGE=$(jq -n --arg cursor "$CURSOR" '{
filter: {ownerId: {eq: "quickstart-user"}}, limit: 100
} + (if $cursor == "" then {} else {cursor: $cursor} end)' |
curl --fail-with-body --silent --show-error -X POST "$MEMORY_API/memories/search" \
-H "$AUTH" -H 'Content-Type: application/json' --data-binary @-)
IDS=$(jq -c --argjson ids "$IDS" '$ids + [.items[].memoryId]' <<< "$PAGE")
CURSOR=$(jq -r '.nextCursor // empty' <<< "$PAGE")
if [ -z "$CURSOR" ]; then break; fi
done
while IFS= read -r BODY; do
curl --fail-with-body --silent --show-error -X POST "$MEMORY_API/memories/bulk-delete" \
-H "$AUTH" -H 'Content-Type: application/json' --data "$BODY" | jq .
done < <(jq -c '. as $ids | range(0; length; 100) as $start | {memoryIds: $ids[$start:$start+100]}' <<< "$IDS")
set -euo pipefail
iris agent-memory memories forget --owner quickstart-user --yes
set -euo pipefail
iris agent-memory memories forget --owner quickstart-user --yes
Next steps
Generate a complete conversational agent with the AI agent builder. Select Redis Iris Conversational Assistant, then choose Python or JavaScript.
Follow the developer guide to use memory in an agent’s request cycle. For specific features, see Sessions, Custom memory types, Namespaces, and MCP.