Define and customize tools

Letta has a native integration with Composio, which supports over 7000 pre-made tools to connect with popular services such as Slack, GitHub, Discord, etc. You can also create your own custom tools from scratch using Python.

Default Letta Tools

By default, agents in Letta are created with the following tools:

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

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

Custom Tools

You can create custom tools in Letta in Python. When you define the function for the tool, you must make sure to have a properly formatting docstring for Letta to parse the function schema.

1from letta import Letta
2
3client = Letta(token="LETTA_API_KEY")
4
5# define a function with a docstring
6def roll_dice() -> str:
7 """
8 Simulate the roll of a 20-sided die (d20).
9
10 This function generates a random integer between 1 and 20, inclusive,
11 which represents the outcome of a single roll of a d20.
12
13 Returns:
14 str: The result of the die roll.
15 """
16 import random
17
18 dice_role_outcome = random.randint(1, 20)
19 output_string = f"You rolled a {dice_role_outcome}"
20 return output_string
21
22
23# create the tool
24tool = client.tools.create_from_function(
25 func=roll_dice
26)
27print(f"Created tool {tool.name}")

Adding tools to agents in the Python SDK

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.

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-ada-002",
9 tool_ids=[tool.id]
10)

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:

1curl -X POST http://localhost:8283/v1/agents/ \
2 -H "Content-Type: application/json" \
3 -d '{
4 "llm":"openai/gpt-4o-mini",
5 "embedding":"openai/text-embedding-ada-002",
6 "tool_exec_environment_variables": {
7 "EXAMPLE_TOOL_API_KEY": "banana"
8 },
9 "memory_blocks": []
10}'

External Tool Libraries

Letta also has early support for adding tools from the external tool library Composio. This integrations works by converting the external library tools into Letta tools.

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

Excluding Default Tools

To skip adding default tools when creating a new agent, you can add in include_default_tools=False to the agent creation:

1# create an agent with no tools
2agent = client.agents.create(
3 include_default_tools=False
4)

Warning: this will create an agent with no tools, so the agent will have no ability to manage memory or search conversation history.

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.

Accessing Agent State

Tools that use agent_state currently do not work in the ADE live tool tester (they will error when you press “Run”), however if the tool is correct it will work once you attach it to an agent.

If you need to directly access the state of an agent inside a tool, you can use the reserved agent_state keyword argument, for example:

1def get_agent_id(agent_state: "AgentState") -> str:
2 """
3 A custom tool that returns the agent ID
4
5 Returns:
6 str: The agent ID
7 """
8 return agent_state.id
Built with