Skip to main content
Tenant-scoped MemoryOS with Anthropic Claude. Same pattern as OpenAI: add memories, retrieve before the model call, skip context only when passthrough is active.
import os
from anthropic import Anthropic
from memoryos import Memory

memory = Memory(api_key=os.environ["MEMORYOS_API_KEY"])
anthropic = Anthropic(api_key=os.environ["ANTHROPIC_API_KEY"])

external_user_id = "customer-123"
latest_user_message = "How should you tailor the response for me?"

memory.add(
    messages=[{"role": "user", "content": "I like structured answers with short bullet points."}],
    external_user_id=external_user_id,
)

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

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

response = anthropic.messages.create(
    model="claude-sonnet-4-20250514",
    max_tokens=500,
    system=system_prompt,
    messages=[{"role": "user", "content": latest_user_message}],
)

print(response.content[0].text)
memory.close()
Key rules:
  • Keep MEMORYOS_API_KEY server-side
  • Always call Claude, even when MemoryOS is in passthrough
  • Use Memory Passport only when one user intentionally shares memory across multiple agents
For the cross-agent flow, see Cross-agent memory sharing.