Skip to main content
Scope knowledge retrieval per user, agent, or session so tenants and conversations stay isolated.
from praisonaiagents import Agent, MemoryConfig

agent = Agent(
    name="SupportBot",
    instructions="Answer from the customer's knowledge only.",
    knowledge=["./support_docs/"],
    memory=MemoryConfig(user_id="customer_42"),
)

agent.start("What was the status of my refund request?")
The user asks in a scoped session; retrieval filters by tenant and user so answers stay isolated.

How It Works

Quick Start

1

Simple Usage

Set user_id via memory config — the agent passes it to every knowledge search:
from praisonaiagents import Agent, MemoryConfig

agent = Agent(
    name="PersonalAssistant",
    instructions="You are a personal assistant.",
    knowledge=["./documents/"],
    memory=MemoryConfig(user_id="alice"),
)

agent.start("Find my recent notes about the project")
2

With Configuration

Combine scopes for multi-tenant SaaS — pass run_id on retrieve for session-specific context:
from praisonaiagents import Agent, MemoryConfig

session_id = "session_2026_05_30"

agent = Agent(
    name="SupportBot",
    instructions="Answer customer questions using their session history.",
    knowledge=["./support_docs/"],
    memory=MemoryConfig(user_id="customer_42"),
)

agent.retrieve("Refund status?", run_id=session_id)

How It Works

The agent forwards user_id and agent_id (auto-generated) to the knowledge backend. Vector stores combine filters with $and when multiple scopes are set.
ScopeSourcePurpose
user_idMemoryConfig(user_id=…)Per-user isolation
agent_idagent.agent_id (auto)Per-agent isolation
run_idretrieve(…, run_id=…) or store metadataPer-session isolation

Configuration Options

OptionTypeDefaultDescription
user_idstr"praison"User scope on MemoryConfig
agent_idstrauto UUIDAgent scope (read-only property)
run_idstrNoneSession scope on retrieve/store
Backends: ChromaDB supports all scopes; mem0 requires at least one scope identifier.

Best Practices

Use memory=MemoryConfig(user_id=customer_id) in SaaS apps — each customer’s retrieval stays separate.
Scope temporary conversation context with agent.retrieve(query, run_id=session_id).
mem0 enforces scope at ingest; ChromaDB filters at query time with combined $and clauses.
Prefer readable IDs like customer_alice_123 over opaque tokens for easier debugging.

Knowledge Backends

Vector store backends and scoping support

Knowledge

Configure sources and retrieval