Building Custom Multi-Agent Tools
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:
async function customSendMessageToAgent( targetAgentId: string, messageContents: string,) { /** * Send a message to a specific Letta agent. * * @param targetAgentId - The identifier of the target Letta agent. * @param messageContents - The message to be sent to the target Letta agent. */ const { LettaClient } = require("@letta-ai/letta-client");
// TODO: point this to the server where the worker agents are running const client = new LettaClient({ baseUrl: "http://127.0.0.1:8283" });
// message all worker agents async const response = await client.agents.sendMessageAsync( targetAgentId, messageContents, );}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:
async function triggerWorkerAgents() { /** * Trigger worker agents to start their tasks, without waiting for a response. */ const { LettaClient } = require("@letta-ai/letta-client");
// TODO: point this to the server where the worker agents are running const client = new LettaClient({ baseUrl: "http://127.0.0.1:8283" });
// message all worker agents async const agents = await client.agents.list({ tags: ["worker"] }); for (const agent of agents) { const response = await client.agents.sendMessageAsync( agent.id, "Start my task", ); }}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", )