Skip to content

armgit / letta

Public Imported from GitHub
0

Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.

fix: Remove async multiagent tool (#2994)

Matthew Zhou375e77da1a24
diff --git a/letta/constants.py b/letta/constants.py
index 44bf420d5..85d3d382e 100644
--- a/letta/constants.py
+++ b/letta/constants.py
@@ -113,7 +113,7 @@ BASE_VOICE_SLEEPTIME_TOOLS = [
"finish_rethinking_memory",
]
# Multi agent tools
-MULTI_AGENT_TOOLS = ["send_message_to_agent_and_wait_for_reply", "send_message_to_agents_matching_tags", "send_message_to_agent_async"]
+MULTI_AGENT_TOOLS = ["send_message_to_agent_and_wait_for_reply", "send_message_to_agents_matching_tags"]
# Used to catch if line numbers are pushed in
# MEMORY_TOOLS_LINE_NUMBER_PREFIX_REGEX = re.compile(r"^Line \d+: ", re.MULTILINE)
diff --git a/letta/functions/function_sets/multi_agent.py b/letta/functions/function_sets/multi_agent.py
index 34e372e5d..458798e4a 100644
--- a/letta/functions/function_sets/multi_agent.py
+++ b/letta/functions/function_sets/multi_agent.py
@@ -7,7 +7,6 @@ from letta.functions.helpers import (
_send_message_to_all_agents_in_group_async,
execute_send_message_to_agent,
extract_send_message_from_steps_messages,
- fire_and_forget_send_to_agent,
)
from letta.schemas.enums import MessageRole
from letta.schemas.message import MessageCreate
@@ -44,37 +43,6 @@ def send_message_to_agent_and_wait_for_reply(self: "Agent", message: str, other_
)
-def send_message_to_agent_async(self: "Agent", message: str, other_agent_id: str) -> str:
- """
- Sends a message to a specific Letta agent within the same organization. The sender's identity is automatically included, so no explicit introduction is required in the message. This function does not expect a response from the target agent, making it suitable for notifications or one-way communication.
-
- Args:
- message (str): The content of the message to be sent to the target agent.
- other_agent_id (str): The unique identifier of the target Letta agent.
-
- Returns:
- str: A confirmation message indicating the message was successfully sent.
- """
- message = (
- f"[Incoming message from agent with ID '{self.agent_state.id}' - to reply to this message, "
- f"make sure to use the 'send_message_to_agent_async' tool, or the agent will not receive your message] "
- f"{message}"
- )
- messages = [MessageCreate(role=MessageRole.system, content=message, name=self.agent_state.name)]
-
- # Do the actual fire-and-forget
- fire_and_forget_send_to_agent(
- sender_agent=self,
- messages=messages,
- other_agent_id=other_agent_id,
- log_prefix="[send_message_to_agent_async]",
- use_retries=False, # or True if you want to use _async_send_message_with_retries
- )
-
- # Immediately return to caller
- return "Successfully sent message"
-
-
def send_message_to_agents_matching_tags(self: "Agent", message: str, match_all: List[str], match_some: List[str]) -> List[str]:
"""
Sends a message to all agents within the same organization that match the specified tag criteria. Agents must possess *all* of the tags in `match_all` and *at least one* of the tags in `match_some` to receive the message.
diff --git a/letta/services/agent_manager.py b/letta/services/agent_manager.py
index 1e98c90fb..fc477dc35 100644
--- a/letta/services/agent_manager.py
+++ b/letta/services/agent_manager.py
@@ -287,7 +287,7 @@ class AgentManager:
tool_rules = list(agent_create.tool_rules or [])
if agent_create.include_base_tool_rules:
for tn in tool_names:
- if tn in {"send_message", "send_message_to_agent_async", "memory_finish_edits"}:
+ if tn in {"send_message", "memory_finish_edits"}:
tool_rules.append(TerminalToolRule(tool_name=tn))
elif tn in (BASE_TOOLS + BASE_MEMORY_TOOLS + BASE_SLEEPTIME_TOOLS):
tool_rules.append(ContinueToolRule(tool_name=tn))
@@ -451,7 +451,7 @@ class AgentManager:
tool_rules = list(agent_create.tool_rules or [])
if agent_create.include_base_tool_rules:
for tn in tool_names:
- if tn in {"send_message", "send_message_to_agent_async", "memory_finish_edits"}:
+ if tn in {"send_message", "memory_finish_edits"}:
tool_rules.append(TerminalToolRule(tool_name=tn))
elif tn in (BASE_TOOLS + BASE_MEMORY_TOOLS + BASE_MEMORY_TOOLS_V2 + BASE_SLEEPTIME_TOOLS):
tool_rules.append(ContinueToolRule(tool_name=tn))
diff --git a/letta/services/tool_executor/multi_agent_tool_executor.py b/letta/services/tool_executor/multi_agent_tool_executor.py
index e43626976..b91308e03 100644
--- a/letta/services/tool_executor/multi_agent_tool_executor.py
+++ b/letta/services/tool_executor/multi_agent_tool_executor.py
@@ -10,7 +10,6 @@ from letta.schemas.sandbox_config import SandboxConfig
from letta.schemas.tool import Tool
from letta.schemas.tool_execution_result import ToolExecutionResult
from letta.schemas.user import User
-from letta.services.tool_executor.tool_executor import logger
from letta.services.tool_executor.tool_executor_base import ToolExecutor
@@ -30,7 +29,6 @@ class LettaMultiAgentToolExecutor(ToolExecutor):
assert agent_state is not None, "Agent state is required for multi-agent tools"
function_map = {
"send_message_to_agent_and_wait_for_reply": self.send_message_to_agent_and_wait_for_reply,
- "send_message_to_agent_async": self.send_message_to_agent_async,
"send_message_to_agents_matching_tags": self.send_message_to_agents_matching_tags_async,
}
@@ -54,21 +52,6 @@ class LettaMultiAgentToolExecutor(ToolExecutor):
return str(await self._process_agent(agent_id=other_agent_id, message=augmented_message))
- async def send_message_to_agent_async(self, agent_state: AgentState, message: str, other_agent_id: str) -> str:
- # 1) Build the prefixed system‐message
- prefixed = (
- f"[Incoming message from agent with ID '{agent_state.id}' - "
- f"to reply to this message, make sure to use the "
- f"'send_message_to_agent_async' tool, or the agent will not receive your message] "
- f"{message}"
- )
-
- task = asyncio.create_task(self._process_agent(agent_id=other_agent_id, message=prefixed))
-
- task.add_done_callback(lambda t: (logger.error(f"Async send_message task failed: {t.exception()}") if t.exception() else None))
-
- return "Successfully sent message"
-
async def send_message_to_agents_matching_tags_async(
self, agent_state: AgentState, message: str, match_all: List[str], match_some: List[str]
) -> str:
diff --git a/tests/integration_test_multi_agent.py b/tests/integration_test_multi_agent.py
index 6e9cbf8c9..ad1139e84 100644
--- a/tests/integration_test_multi_agent.py
+++ b/tests/integration_test_multi_agent.py
@@ -15,7 +15,6 @@ from letta.schemas.tool import Tool
from letta.server.server import SyncServer
from letta.services.agent_manager import AgentManager
from tests.helpers.utils import retry_until_success
-from tests.utils import wait_for_incoming_message
@pytest.fixture(scope="module")
@@ -351,71 +350,3 @@ def test_send_message_to_agents_with_tags_complex_tool_use(client, roll_dice_too
],
)
print("Manager agent followup message: \n\n" + "\n".join([str(m) for m in response.messages]))
-
-
-# @retry_until_success(max_attempts=5, sleep_time_seconds=2)
-def test_agents_async_simple(client):
- """
- Test two agents with multi-agent tools sending messages back and forth to count to 5.
- The chain is started by prompting one of the agents.
- """
- # Create two agents with multi-agent tools
- send_message_to_agent_async_tool_id = client.tools.list(name="send_message_to_agent_async")[0].id
- charles_state = client.agents.create(
- name="charles",
- tool_ids=[send_message_to_agent_async_tool_id],
- memory_blocks=[
- {
- "label": "human",
- "value": "Chad - I'm interested in hearing poem.",
- },
- {
- "label": "persona",
- "value": "You are an AI agent that can communicate with your agent buddy using `send_message_to_agent_async`, who has some great poem ideas (so I've heard).",
- },
- ],
- model="openai/gpt-4o-mini",
- embedding="letta/letta-free",
- )
-
- sarah_state = client.agents.create(
- name="sarah",
- tool_ids=[send_message_to_agent_async_tool_id],
- memory_blocks=[
- {
- "label": "human",
- "value": "No human - you are to only communicate with the other AI agent.",
- },
- {
- "label": "persona",
- "value": "You are an AI agent that can communicate with your agent buddy using `send_message_to_agent_async`, who is interested in great poem ideas.",
- },
- ],
- model="openai/gpt-4o-mini",
- embedding="letta/letta-free",
- )
-
- # Start the count chain with Agent1
- initial_prompt = f"I want you to talk to the other agent with ID {sarah_state.id} using `send_message_to_agent_async`. Specifically, I want you to ask him for a poem idea, and then craft a poem for me."
- client.agents.messages.create(
- agent_id=charles_state.id,
- messages=[{"role": "user", "content": initial_prompt}],
- )
-
- found_in_charles = wait_for_incoming_message(
- client=client,
- agent_id=charles_state.id,
- substring="[Incoming message from agent with ID",
- max_wait_seconds=10,
- sleep_interval=0.5,
- )
- assert found_in_charles, "Charles never received the system message from Sarah (timed out)."
-
- found_in_sarah = wait_for_incoming_message(
- client=client,
- agent_id=sarah_state.id,
- substring="[Incoming message from agent with ID",
- max_wait_seconds=10,
- sleep_interval=0.5,
- )
- assert found_in_sarah, "Sarah never received the system message from Charles (timed out)."