import os
from anthropic import Anthropic
from memoryos import Memory
def main() -> None:
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": "Please remember that 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()
if __name__ == "__main__":
main()