Tools

Understanding how to use tools with Letta agents

Tools allow agents to take actions that affect the real world. Letta agents can use tools to manage their own memory, send messages to the end user, search the web, and more.

You can add custom tools to Letta by defining your own tools, and also customize the execution environment of the tools. You can import external tool libraries by connecting your Letta agents to MCP (Model Context Protocol) servers. MCP servers are a way to expose APIs to Letta agents.

Pre-built Tools

Default Memory Tools

By default, agents in Letta are created with a set of default tools including send_message (which generates a message to send to the user), core memory tools (allowing the agent to edit its memory blocks), and external memory tools (to read/write from archival memory, and to access recall memory, aka the conversation history):

ToolDescription
send_messageSends a message to the human user.
core_memory_appendAppend to the contents of a block in core memory.
core_memory_replaceReplace the contents of a block in core memory.
conversation_searchSearch prior conversation history (recall memory)
archival_memory_insertAdd a memory to archival memory
archival_memory_searchSearch archival memory via embedding search

You can disable the default tools by setting include_base_tools to false during agent creation. Note that disabling the send_message tool may cause agent messages (intended for the user) to appear as “reasoning” messages in the API and ADE.

Multi-Agent Tools

Letta also includes a set of pre-made tools designed for multi-agent interaction. See our guide on multi-agent for more information.

The web_search tool allows agents to search the web for information.

On Letta Cloud, this tool works out of the box, but when using this tool on a self-hosted Letta server, you must set a TAVILY_API_KEY environment variable either in during server startup or in your agent’s tool execution environment.

Code Interpreter

The run_code tool allows agents to run code (in a sandbox), for example to do data analysis or calculations. Supports Python, Javascript, Typescript, R, and Java.

On Letta Cloud, this tool works out of the box, but when using this tool on a self-hosted Letta server, you must set a E2B_API_KEY environment variable either in during server startup or in your agent’s tool execution environment.

Defining Custom Tools

You can create custom tools in Letta using the SDKs, as well as via the ADE tool builder. See more on defining custom tools here.

Once the tool is created, you can add it to an agent by passing the tool name to the tools parameter in the agent creation.

python
1# create a new agent
2agent = client.agents.create(
3 memory_blocks=[
4 {"label": "human", "limit": 2000, "value": "Name: Bob"},
5 {"label": "persona", "limit": 2000, "value": "You are a friendly agent"}
6 ],
7 model="openai/gpt-4o-mini",
8 embedding="openai/text-embedding-3-small",
9 tools=["my_custom_tool_name"]
10)

Tool Execution

You can customize the environment that your tool runs in (the Python package dependencies and environment variables) by setting a tool execution environment. See more here.

Tool Environment Variables

You can set agent-scoped environment variables for your tools. These environment variables will be accessible in the sandboxed environment that any of the agent tools are run in.

For example, if you define a custom tool that requires an API key to run (e.g. EXAMPLE_TOOL_API_KEY), you can set the variable at time of agent creation by using the tool_exec_environment_variables parameter:

python
1# create an agent with no tools
2agent = client.agents.create(
3 memory_blocks=[
4 {"label": "human", "limit": 2000, "value": "Name: Bob"},
5 {"label": "persona", "limit": 2000, "value": "You are a friendly agent"}
6 ],
7 model="openai/gpt-4o-mini",
8 embedding="openai/text-embedding-3-small",
9 tool_exec_environment_variables={
10 "EXAMPLE_TOOL_API_KEY": "banana"
11 }
12)

Tool Rules

Tool rules allow you to define graph-like constrains on your tools, such as requiring that a tool terminate agent execution or be followed by another tool.

Read more about tool rules here.

External Tool Libraries

Letta also has early support for adding tools from external tool libraries via MCP and Composio.

For more information on setting up MCP servers, see our MCP guide.

For more information on setting up Composio tools, see our Composio guide.