REST API Examples

Hello World: A Guide to the MemMachine RESTful API

This guide provides a quick and simple way to get started with the MemMachine RESTful API using curl commands. It can also be found in our Quick Start Guide.

Prerequisites

First, make sure your FastAPI application is running. Open your terminal, navigate to the directory containing your app.py file, and run the following command. The output should confirm that the server is listening for requests.
uvicorn app:app --reload
1

Get All Sessions

The simplest way to start is by checking for existing sessions. This GET request doesn’t require any data. You will likely see an empty list since no sessions have been created yet.
curl http://127.0.0.1:8080/v1/sessions
2

Add a New Memory

This is where you’ll create your first memory episode. The POST /v1/memories endpoint requires a JSON body that includes session details, a producer, a recipient, and the content of the memory itself.Command:
curl -X POST "http://127.0.0.1:8080/v1/memories" \
-H "Content-Type: application/json" \
-d '{
  "session": {
    "group_id": "test_group",
    "agent_id": ["test_agent"],
    "user_id": ["test_user"],
    "session_id": "session_123"
  },
  "producer": "test_user",
  "produced_for": "test_agent",
  "episode_content": "This is a simple test memory.",
  "episode_type": "message",
  "metadata": {}
}'
Expected Output:You will receive an empty 200 OK response, confirming the memory was added successfully.
3

Search for the Memory

Now that a memory has been added, let’s try to find it. The POST /v1/memories/search endpoint also requires a JSON body to specify the search query and session.Command:
curl -X POST "http://127.0.0.1:8080/v1/memories/search" \
-H "Content-Type: application/json" \
-d '{
  "session": {
    "group_id": "test_group",
    "agent_id": ["test_agent"],
    "user_id": ["test_user"],
    "session_id": "session_123"
  },
  "query": "simple test memory",
  "filter": {},
  "limit": 5
}'
Expected Output:You should see a 200 OK response containing the search results, including the memory episode you just added. The output will be formatted as a JSON object, confirming that your memory was successfully found.
4

Delete the Session Data

To clean up after your test, you can use the DELETE /v1/memories endpoint. This also requires a JSON body to specify which session’s data should be removed.Command:
curl -X DELETE "http://127.0.0.1:8080/v1/memories" \
-H "Content-Type: application/json" \
-d '{
  "session": {
    "group_id": "test_group",
    "agent_id": ["test_agent"],
    "user_id": ["test_user"],
    "session_id": "session_123"
  }
}'