Python Client

MemGPT support two types of Python clients:

  1. A LocalClient: This runs MemGPT agents locally, so does not require connecting to a MemGPT server.
  2. A RESTClient: This connects to a MemGPT server running locally or in the cloud.

Local Python Client

The LocalClient will run MemGPT agents locally, so is the fastest way to get started.

from memgpt import create_client, LocalClient

# create with `create_client` 
client = create_client()

# create directly 
client = LocalClient() 

REST Python Client

When connecting to the MemGPT server, the Python client can either connect as an administrator (which can create users and API keys) or as an individual user.

Admin Client

User creation and authentication is managed through the Admin client, which is authenticated via the server token (set by the MEMGPT_SERVER_PASS environment variable, or generated when memgpt server is run). You can view a working example of the Admin client here.

You can create an admin client by connecting to the server URL with the server token:

from memgpt import Admin

admin = Admin(base_url="http://localhost:8283", token="your_token")

Creating Users

You can create users via the Admin client. Each user has a unique UUID, and can only access data (e.g. agents, data sources, etc.) which the user created.

response = admin.create_user()
user_id = response.user_id # unique UUID for the user 
api_key = response.api_key # bearer token for authentication

User Client

You can connect to the user endpoints of a MemGPT service via the RESTClient. Each instance of the RESTClient corresponds to a single user.

from memgpt import create_client, RESTClient 

# create with `create_client` 
client = create_client(base_url="http://localhost:8283", token=token)

# create directly 
client = RESTClient(base_url="http://localhost:8283", token=token)

Creating agents

agent_state = client.create_agent(name="my_agent")