Files
letta-server/fern/pages/agents/multiagent_custom.mdx
Kian Jones b8e9a80d93 merge this (#4759)
* wait I forgot to comit locally

* cp the entire core directory and then rm the .git subdir
2025-09-17 15:47:40 -07:00

54 lines
1.9 KiB
Plaintext

---
title: Building Custom Multi-Agent Tools
sidebarTitle: Custom Tools
slug: guides/agents/multi-agent-custom-tools
---
<Tip>
We recommend using the [pre-made multi-agent messaging tools](/guides/agents/multi-agent) for most use cases, but advanced users can write custom tools to support complex communication patterns.
</Tip>
You can also write your own agent communication tools by using the Letta API and writing a custom tool in Python.
Since Letta runs as a service, you can make request to the server from a custom tool to send messages to other agents via API calls.
Here's a simple example of a tool that sends a message to a specific agent:
```python title="python"
def custom_send_message_to_agent(target_agent_id: str, message_contents: str):
"""
Send a message to a specific Letta agent.
Args:
target_agent_id (str): The identifier of the target Letta agent.
message_contents (str): The message to be sent to the target Letta agent.
"""
from letta_client import Letta
# TODO: point this to the server where the worker agents are running
client = Letta(base_url="http://127.0.0.1:8283")
# message all worker agents async
response = client.agents.send_message_async(
agent_id=target_agent_id,
message=message_contents,
)
```
Below is an example of a tool that triggers agents tagged with `worker` to start their tasks:
```python title="python"
def trigger_worker_agents():
"""
Trigger worker agents to start their tasks, without waiting for a response.
"""
from letta_client import Letta
# TODO: point this to the server where the worker agents are running
client = Letta(base_url="http://127.0.0.1:8283")
# message all worker agents async
for agent in client.agents.list(tags=["worker"]):
response = client.agents.send_message_async(
agent_id=agent.id,
message="Start my task",
)
```