Skip to main content

Quickstart

Get MemoryRelay working with your AI agent in under 5 minutes.

Prerequisites

  • Python 3.9+
  • An API key -- sign up at app.memoryrelay.ai and create a key from the dashboard

Install the SDK

pip install memoryrelay

Initialize the Client

from memoryrelay import MemoryRelay

client = MemoryRelay(api_key="mem_your_api_key_here")
tip

You can also set the MEMORYRELAY_API_KEY environment variable and omit the api_key parameter:

export MEMORYRELAY_API_KEY="mem_your_api_key_here"
client = MemoryRelay()  # reads from environment

Create an Agent

Agents are the isolation boundary for memories. Each agent has its own memory namespace.

agent = client.agents.create(name="my-agent")
print(f"Agent created: {agent.id}")

Store a Memory

memory = client.memories.create(
agent_id=agent.id,
content="The user prefers dark mode and uses VS Code as their primary editor.",
metadata={"source": "user_preferences", "confidence": 0.95}
)
print(f"Memory stored: {memory.id}")

Search by Meaning

Retrieve memories using natural language queries. MemoryRelay finds semantically similar content, not just keyword matches.

results = client.memories.search(
query="What editor does the user prefer?",
agent_id=agent.id,
limit=5
)

for result in results.data:
print(f"[{result.score:.2f}] {result.memory.content}")

Full Sync Example

Putting it all together:

from memoryrelay import MemoryRelay

# Initialize
client = MemoryRelay(api_key="mem_your_api_key_here")

# Create an agent
agent = client.agents.create(name="dev-assistant")

# Store some memories
client.memories.create(
agent_id=agent.id,
content="Project uses FastAPI with PostgreSQL and Redis for caching."
)

client.memories.create(
agent_id=agent.id,
content="Authentication is handled via JWT tokens with 1-hour expiration."
)

client.memories.create(
agent_id=agent.id,
content="The team decided to use Alembic for database migrations on 2025-01-15."
)

# Search for relevant context
results = client.memories.search(
query="How does authentication work?",
agent_id=agent.id,
limit=3
)

for r in results.data:
print(f"[{r.score:.2f}] {r.memory.content}")

# Clean up
client.close()

Async Example

For async applications, use AsyncMemoryRelay. The API is identical, but all methods are awaitable.

import asyncio
from memoryrelay import AsyncMemoryRelay

async def main():
async with AsyncMemoryRelay(api_key="mem_your_api_key_here") as client:
# Create an agent
agent = await client.agents.create(name="async-assistant")

# Store a memory
await client.memories.create(
agent_id=agent.id,
content="Deployment pipeline uses GitHub Actions with staging and production environments."
)

# Search
results = await client.memories.search(
query="How is the project deployed?",
agent_id=agent.id
)

for r in results.data:
print(f"[{r.score:.2f}] {r.memory.content}")

asyncio.run(main())
info

The async client uses async with for automatic cleanup. If you create the client without a context manager, call await client.close() when you are done.

Extract Entities

After storing a memory, you can trigger entity extraction to automatically identify people, technologies, and other named entities:

# Trigger extraction
client.memories.extract_entities(memory.id)

# Check extraction status
status = client.memories.get_extraction_status(memory.id)
print(f"Extraction: {status['status']}, entities found: {status.get('entity_count', 0)}")

Next Steps

  • Core Concepts -- Learn about agents, entities, sessions, decisions, and patterns
  • Authentication -- Understand API key scopes and rate limiting
  • API Reference -- Full REST API documentation with request/response schemas
  • Python SDK -- Complete SDK reference with all available resources