When designing memory isolation, you can structure namespaces using different levels of granularity. Common patterns include:
- Organization-level: Isolate memories for an entire company or group using an
{org_id}. - User within organization: Create a hierarchy where memories are nested under an organization and then a specific user (e.g.,
("memories", "{org_id}", "{user_id}")). This allows for tools like create_search_memory_tool to potentially search across an entire organization if the namespace is configured at the {org_id} level. - Categorical/Feature-level: Organize memories by type or specific agent context (e.g.,
("agent_name", "memories", "{user_id}", "preferences")).
# Organization-level
tool = create_manage_memory_tool(
namespace=("memories", "{org_id}")
)
app = create_react_agent("anthropic:claude-3-5-sonnet-latest", tools=[tool])
app.invoke(
{"messages": [{"role": "user", "content": "I'm questioning the new company health plan.."}]},
config={"configurable": {"org_id": "acme"}}
)
# User within organization
tool = create_manage_memory_tool(
namespace=("memories", "{org_id}", "{user_id}")
)
# If you wanted to, you could let the agent
# search over all users within an organization
tool = create_search_memory_tool(
namespace=("memories", "{org_id}")
)
app = create_react_agent("anthropic:claude-3-5-sonnet-latest", tools=[tool])
app.invoke(
{"messages": [{"role": "user", "content": "What's our policy on dogs at work?"}]},
config={"configurable": {"org_id": "acme", "user_id": "alice"}}
)
# Categorical organization
tool = create_manage_memory_tool(
namespace=("agent_smith", "memories", "{user_id}", "preferences")
)
app = create_react_agent("anthropic:claude-3-5-sonnet-latest", tools=[tool])
app.invoke(
{"messages": [{"role": "user", "content": "I like dolphins"}]},
config={"configurable": {"user_id": "alice"}}
)