Blog
How to implement hierarchical memory for AI agents
When your agents serve many users and a whole team, one flat pile of memories stops working. Each user's facts have to stay private, the team's decisions have to reach every agent, and each business client's data needs a wall around it. Redis Agent Memory addresses this with stores for isolation, owners for identity, and namespace hierarchies for organization. This guide shows how to build that tree with Redis Agent Memory in Redis Iris, from the layout and ownership rules to promotion, retrieval and forgetting.
A team of agents needs memory at the user, team and organization levels
Picture a bank's support bot with a billing agent and a refunds agent. A user tells the billing agent to pay refunds by bank transfer instead of PayPal. Meanwhile, the payments team has decided that every new payout method is confirmed by email before the first refund. The bank also runs the bot for several business clients, and their data needs to be isolated.
The agent needs memory at three levels:
- The organization level holds all the memories for one business client.
- The team level holds the memories every agent on a team shares, such as the payments team's rule that every new payout method is confirmed by email before the first refund.
- The user level holds memories that are specific to one person.
For this to work, every memory needs an owner: the user a personal memory belongs to, or the team space a shared memory was written to. Your backend should check the owner before your agent reads anything, so the refunds agent sees a user’s payout method only while it's helping that specific user.
Building a strong memory hierarchy comes down to a few choices: how the levels map onto your storage, who sets each memory's owner, how knowledge moves up from one user to the team, how your agent recalls several levels at once, and how each level forgets.
How Redis Iris manages memory hierarchy
Iris maps each organization to a store and each team and user to a namespace
Redis Agent Memory keeps memories in a store and organizes them with a namespace hierarchy. Inside a store, each root namespace has a scope. A personal root belongs to one owner, such as a user. A shared root has no owner and holds what a team uses across users. Under either kind of root, your agents can create children by name or by path, such as payments/decisions, and Iris creates any missing levels of the path. For the bank bot, one client's store looks like this:
Each namespace keeps a stable ID, so your team can rename or reorganize the tree without touching the code that writes to it.
Establishing memory ownership
Every memory in Iris has an owner. For a conversation, Iris takes the owner from the first event's actor, and memories it extracts inherit that owner. Iris needs a stable user ID from your app's sign-in, such as its login session or a verified identity-provider claim. Your backend authorizes every memory request by setting the owner filter on every personal search from that ID. A request for one user returns only that user's memories, because your backend sets the filter.
The shared levels work through namespace IDs. A shared namespace groups memories across users or agents. Your backend decides which shared namespace IDs each request may read or write. The refunds agent's requests include payments/decisions, and your backend leaves payments/decisions out of a marketing agent's requests in the same store.
On self-managed installs, an operator can also turn on server-side ownership enforcement. Iris then compares each personal record's owner with the user's verified token. Another user's personal records are hidden from reads, searches and changes, and shared records stay open to callers with the store's permission.
How Iris handles hierarchy with namespaces
A conversation joins a namespace with its first event, and the memories Iris extracts from that conversation in the background land in the same namespace. When your application already knows what to store, it writes the memory directly with its owner and namespace ID.
Here's the layout in the redis-iris Python SDK. Your application creates the user's personal namespace and the team's shared path once, saves their IDs, and recalls from both in one call:
The refunds agent gets the user's payout method and the team's confirmation rule in one prompt block. A recall for another user returns that user's own memories and the same team rule.
Iris can promote memories to shared namespaces
Some of what one user tells your agent turns out to matter for everyone. Say several users report that a refund failed after their bank changed its transfer rules. Your agent can write that lesson as a new team memory in payments/incidents, without any user's personal details, or move a memory that's already in a shared namespace to the one where it belongs. Iris never routes a personal memory on its own, so a user's details reach team space only when your agent puts them there.
As the team's memory grows, Iris keeps it organized. Namespace routing lets an administrator write rules for a store, using a text pattern or a plain-language instruction a model evaluates. When your agent moves a shared memory without naming a destination, Iris picks the shared namespace whose rules it matches. A decision about payout methods lands in payments/decisions, and an outage note lands in payments/incidents. Admission rules work the other way. They reject content that doesn't belong in a namespace, even when an agent names that namespace directly.
When the team settles a rule for good, your team can add it to Agent Playbooks, which holds the answers and procedures your business approved, so every agent gives the same approved answer.
Iris lets your agent recall user and team memories in one request
At each turn, your agent needs the user's own memories and the team's. The recall call in the sample searches the owner's memories and then each shared namespace you pass, and returns them as one block for the prompt. Namespace filters match the exact IDs your backend passes, so a request reaches only the levels that user is allowed to see. To include a whole branch, such as every namespace under payments, your backend lists that namespace's children and passes the IDs the user may read.
The rest of Iris builds on the shared levels. Summary views can keep a shared summary of a namespace's memories current with continuous refresh, so every agent on the team starts from the same picture of payments/decisions. Lens traces each agent turn, so an operator can see which memories an agent used for which user.
How Iris forgets memories
When a user asks the bank to erase their data, your backend can call memory.forget with that user’s ID. It deletes every session and long-term memory owned by that ID, including user-owned records placed in shared namespaces. To drop single records, your agent deletes memories by ID. You set separate retention periods for session memory and long-term memory, and moving a memory to another namespace keeps its expiration, so promotion doesn't reset the clock. When the team stops using a namespace, an administrator archives it so nothing new lands there, and deletes it once it's empty.
Get started with Redis Iris
A team of agents needs memory at three levels: the organization, the team and the user. Iris gives each business client its own store, with a namespace for each team and each user inside it. Each memory's owner comes from your app's sign-in, and your backend sets which personal and shared namespaces every request reads. Your agent writes a user's preferences to that user's namespace and team rules to a shared one, promotes a lesson to the team by writing it to a shared namespace, and recalls both levels in one request. When a user asks you to erase their data, one call deletes their memories, retention periods expire old ones, and an administrator archives a namespace the team stops using. To build this tree for your own agents, sign up for Redis Iris and create your first Agent Memory service.
Get started with Redis today
Speak to a Redis expert and learn more about enterprise-grade Redis today.




