Skip to content
  • Auto
  • Light
  • Dark
DiscordForumGitHubSign up
View as Markdown
Copy Markdown

Open in Claude
Open in ChatGPT

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,
);
}

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",
);
}
}