Skip to main content
Four steps to get MemoryOS working with your AI:
  1. Install the SDK
  2. Store a memory
  3. Retrieve memories
  4. Use context in a model call
For the cross-agent Memory Passport flow, see Cross-agent memory sharing. For domain-specific products, the same calls below still apply — enable your domain first, then use:

Step 1: Install

# Python
pip install memoryos openai

# TypeScript
npm install @memoryos/sdk openai

Step 2: Store a memory

import os
from memoryos import Memory

client = Memory(api_key=os.environ["MEMORYOS_API_KEY"])

result = client.add(
    messages=[
        {
            "role": "user",
            "content": "Please remember that I prefer concise technical explanations and Python examples.",
        }
    ],
    external_user_id="customer-123",
)

print(result.status)   # "queued"
client.close()

Step 3: Retrieve memories

import os
from memoryos import Memory

client = Memory(api_key=os.environ["MEMORYOS_API_KEY"])

memories = client.get(
    query="How should I answer this user?",
    external_user_id="customer-123",
    limit=5,
)

if memories.has_context:
    print(memories.system_prompt_addition)

client.close()

Step 4: Use context in an AI call

Retrieve before the model call. Prepend system_prompt_addition when available. Always call the LLM — even if memory is empty or in passthrough.
import os
from memoryos import Memory
from openai import OpenAI

memory = Memory(api_key=os.environ["MEMORYOS_API_KEY"])
openai_client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])

external_user_id = "customer-123"
user_message = "What kind of answer format do I like?"

memories = memory.get(query=user_message, external_user_id=external_user_id, limit=5)

system_prompt = "You are a helpful assistant."
if memories.has_context:
    system_prompt = f"{system_prompt}\n\n{memories.system_prompt_addition}"

response = openai_client.responses.create(
    model="gpt-4.1-mini",
    input=[
        {"role": "system", "content": system_prompt},
        {"role": "user", "content": user_message},
    ],
)

print(response.output_text)
memory.close()

What to expect

  • add() returns queued, passthrough, or a quality gate block — not an error
  • get() always returns a typed result, even with zero memories
  • is_passthrough / isPassthrough being true means skip memory context but still call the LLM
  • system_prompt_addition is safe to prepend as-is
  • if your tenant has a domain schema enabled, system_prompt_addition includes domain-aware context automatically

Next steps