Serving Multiple Users

You may be building a multi-user application with Letta, in which each user is associated with a specific agent. In this scenario, you can use the notion of tags (part of the agent state) to associate each agent with a user in your application.

Using Agent Tags to Identify Users

Let’s assume that you have an application with multiple users that you’re building on a self-hosted Letta Server or Letta Cloud. Each user has a unique username, starting at user_1, and incrementing up as you add more users to the platform.

To associate agents you create in Letta with your users, you can specify a tag when creating an agent, and set the tag to the user’s unique ID. For example, with user_1, we would set the tags parameter to ["user_1"] in our create agent request:

1curl -X POST https://app.letta.com/v1/agents/ \
2 -H "Authorization: Bearer <token>" \
3 -H "Content-Type: application/json" \
4 -d '{
5 "memory_blocks": [],
6 "llm": "anthropic/claude-3-5-sonnet-20241022",
7 "context_window_limit": 200000,
8 "embedding": "openai/text-embedding-ada-002",
9 "tags": ["user_1"]
10}'

Then, if I wanted to search for agents associated with a specific user (e.g. called user_id), I could use the tags parameter in the list agents request:

1curl -X GET "https://app.letta.com/v1/agents/?tags=user_1" \
2 -H "Accept: application/json"

Full example using the Python SDK

In this example we’ll create an agent with a (user) tag, then search for all agents with that tag. This example assumes that you have a self-hosted Letta Server running on localhost (for example, by running docker run ...).

python
1from letta_client import Letta
2
3# in this example we'll connect to a self-hosted Letta Server
4client = Letta(base_url="http://localhost:8283")
5user_id = "my_uuid"
6
7# create an agent with the user_id tag
8agent = client.agents.create(
9 memory_blocks=[],
10 model="anthropic/claude-3-5-sonnet-20241022",
11 context_window_limit=200000,
12 embedding="openai/text-embedding-ada-002",
13 tags=[user_id]
14)
15print(f"Created agent with id {agent.id}, tags {agent.tags}")
16
17# list agents
18user_agents = client.agents.list(tags=[user_id])
19agent_ids = [agent.id for agent in user_agents]
20print(f"Found matching agents {agent_ids}")

Creating and Viewing Tags in the ADE

You can also modify tags in the ADE. Simply click the Advanced Settings tab in the top-left of the ADE to view an agent’s tags. You can create new tags by typing the tag name in the input field and hitting enter.

Built with