This guide will show you how to create a Letta agent with the Letta APIs or SDKs (Python/Typescript). To create agents with a low-code UI, see our ADE quickstart.
Create an agent
1 | from letta_client import Letta |
2 | |
3 | client = Letta(token="LETTA_API_KEY") |
4 | |
5 | agent_state = client.agents.create( |
6 | model="openai/gpt-4.1", |
7 | embedding="openai/text-embedding-3-small", |
8 | memory_blocks=[ |
9 | { |
10 | "label": "human", |
11 | "value": "The human's name is Chad. They like vibe coding." |
12 | }, |
13 | { |
14 | "label": "persona", |
15 | "value": "My name is Sam, the all-knowing sentient AI." |
16 | } |
17 | ], |
18 | tools=["web_search", "run_code"] |
19 | ) |
20 | |
21 | print(agent_state.id) |
Message your agent
The Letta API supports streaming both agent steps and streaming tokens. For more information on streaming, see our streaming guide.
Once the agent is created, we can send the agent a message using its id field:
1 | response = client.agents.messages.create( |
2 | agent_id=agent_state.id, |
3 | messages=[ |
4 | { |
5 | "role": "user", |
6 | "content": "hows it going????" |
7 | } |
8 | ] |
9 | ) |
10 | |
11 | for message in response.messages: |
12 | print(message) |
The response contains the agent’s full response to the message, which includes reasoning steps (chain-of-thought), tool calls, tool responses, and assistant (agent) messages:
1 | { |
2 | "messages": [ |
3 | { |
4 | "id": "message-29d8d17e-7c50-4289-8d0e-2bab988aa01e", |
5 | "date": "2024-12-12T17:05:56+00:00", |
6 | "message_type": "reasoning_message", |
7 | "reasoning": "User seems curious and casual. Time to engage!" |
8 | }, |
9 | { |
10 | "id": "message-29d8d17e-7c50-4289-8d0e-2bab988aa01e", |
11 | "date": "2024-12-12T17:05:56+00:00", |
12 | "message_type": "assistant_message", |
13 | "content": "Hey there! I'm doing great, thanks for asking! How about you?" |
14 | } |
15 | ], |
16 | "usage": { |
17 | "completion_tokens": 56, |
18 | "prompt_tokens": 2030, |
19 | "total_tokens": 2086, |
20 | "step_count": 1 |
21 | } |
22 | } |
You can read more about the response format from the message route here.
View your agent in the ADE
Another way to interact with Letta agents is via the Agent Development Environment (or ADE for short). The ADE is a UI on top of the Letta API that allows you to quickly build, prototype, and observe your agents.
If we navigate to our agent in the ADE, we should see our agent’s state in full detail, as well as the message that we sent to it:
Next steps
Congratulations! 🎉 You just created and messaged your first stateful agent with Letta, using both the Letta ADE, API, and Python/Typescript SDKs. See the following resources for next steps for building more complex agents with Letta:
- Create and attach custom tools to your agent
- Customize agentic memory management
- Version and distribute your agent with agent templates
- View the full API and SDK reference