Your First Letta Agent
This example walks you through creating your first Letta agent from scratch. Unlike traditional chatbots that forget everything between conversations, Letta agents are stateful - they maintain persistent memory and can learn about you over time.
By the end of this guide, you’ll understand how to create an agent, send it messages, and see how it automatically updates its memory based on your interactions.
This example uses Letta Cloud. Generate an API key at app.letta.com/api-keys and set it as LETTA_API_KEY in your environment. Self-hosted servers only need an API key if authentication is enabled. You can learn more about self-hosting here.
What You’ll Learn
- Initializing the Letta client
- Creating an agent with memory blocks
- Sending messages and receiving responses
- How agents update their own memory
- Inspecting memory tool calls and block contents
Prerequisites
You will need to install letta-client to interface with a Letta server:
Steps
Step 1: Initialize Client
A client is a connection to a Letta server. It’s used to create and interact with agents, as well as any of Letta’s other features.
Step 2: Create Agent
Now that we have a client, let’s create an agent with memory blocks that define what the agent knows about itself and you. Memory blocks can be used for any purpose, but we’re building a simple chatbot that stores information about its personality (persona) and you (human).
Expected Output
Memory blocks are the foundation of Letta agents. The persona block defines the agent’s identity and behavior, while the human block stores information about the user. Learn more in the Memory Blocks guide.
Step 3: Send Your First Message
Now let’s send a message to the agent to see what it can do.
Expected Output
Step 4: Provide Information for the Agent to Remember
Now let’s give the agent some information about yourself. If prompted correctly, the agent can add this information to a relevant memory block using one of its default memory tools. Unless tools are modified during creation, new agents usually have memory_insert and memory_replace tools.
Expected Output
Notice the tool_call_message showing the agent using the memory_replace tool to update the human block. This is how Letta agents manage their own memory.
Step 5: Inspect Agent Memory
Let’s see what the agent remembers. We’ll print out both the summary and the full content of each memory block:
The persona block should have:
I am a friendly AI assistant here to help you learn about Letta.
The human block should have something like:
Name: Cameron
Notice how the human block now contains “Name: Cameron” instead of “Name: User”. The agent used the memory_replace tool to update its memory based on the information you provided.
Complete Example
Here’s the full code in one place that you can run:
Key Concepts
Letta agents maintain memory across conversations, unlike stateless chat APIs
Modular memory components that agents can read and update during conversations
Agents remember user preferences, conversation history, and learned information
Agents intelligently update their memory as they learn more about you