Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add settings for multi-agent configuration #2418

Merged
merged 6 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions letta/functions/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,7 @@
from composio.constants import DEFAULT_ENTITY_ID
from pydantic import BaseModel

from letta.constants import (
COMPOSIO_ENTITY_ENV_VAR_KEY,
DEFAULT_MESSAGE_TOOL,
DEFAULT_MESSAGE_TOOL_KWARG,
MULTI_AGENT_CONCURRENT_SENDS,
MULTI_AGENT_SEND_MESSAGE_MAX_RETRIES,
MULTI_AGENT_SEND_MESSAGE_TIMEOUT,
)
from letta.constants import COMPOSIO_ENTITY_ENV_VAR_KEY, DEFAULT_MESSAGE_TOOL, DEFAULT_MESSAGE_TOOL_KWARG
from letta.functions.interface import MultiAgentMessagingInterface
from letta.orm.errors import NoResultFound
from letta.schemas.enums import MessageRole
Expand All @@ -23,6 +16,7 @@
from letta.schemas.message import Message, MessageCreate
from letta.schemas.user import User
from letta.server.rest_api.utils import get_letta_server
from letta.settings import settings


# TODO: This is kind of hacky, as this is used to search up the action later on composio's side
Expand Down Expand Up @@ -290,8 +284,8 @@ async def async_execute_send_message_to_agent(
sender_agent=sender_agent,
target_agent_id=other_agent_id,
messages=messages,
max_retries=MULTI_AGENT_SEND_MESSAGE_MAX_RETRIES,
timeout=MULTI_AGENT_SEND_MESSAGE_TIMEOUT,
max_retries=settings.multi_agent_send_message_max_retries,
timeout=settings.multi_agent_send_message_timeout,
logging_prefix=log_prefix,
)

Expand Down Expand Up @@ -429,8 +423,8 @@ async def background_task():
sender_agent=sender_agent,
target_agent_id=other_agent_id,
messages=messages,
max_retries=MULTI_AGENT_SEND_MESSAGE_MAX_RETRIES,
timeout=MULTI_AGENT_SEND_MESSAGE_TIMEOUT,
max_retries=settings.multi_agent_send_message_max_retries,
timeout=settings.multi_agent_send_message_timeout,
logging_prefix=log_prefix,
)
sender_agent.logger.info(f"{log_prefix} fire-and-forget success with retries: {result}")
Expand Down Expand Up @@ -489,7 +483,7 @@ async def _send_message_to_agents_matching_all_tags_async(sender_agent: "Agent",
messages = [MessageCreate(role=MessageRole.system, content=augmented_message, name=sender_agent.agent_state.name)]

# Possibly limit concurrency to avoid meltdown:
sem = asyncio.Semaphore(MULTI_AGENT_CONCURRENT_SENDS)
sem = asyncio.Semaphore(settings.multi_agent_concurrent_sends)

async def _send_single(agent_state):
async with sem:
Expand All @@ -499,7 +493,7 @@ async def _send_single(agent_state):
target_agent_id=agent_state.id,
messages=messages,
max_retries=3,
timeout=30,
timeout=settings.multi_agent_send_message_timeout,
)

tasks = [asyncio.create_task(_send_single(agent_state)) for agent_state in matching_agents]
Expand Down
5 changes: 5 additions & 0 deletions letta/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ class Settings(BaseSettings):
pg_pool_recycle: int = 1800 # When to recycle connections
pg_echo: bool = False # Logging

# multi agent settings
multi_agent_send_message_max_retries: int = 3
multi_agent_send_message_timeout: int = 20 * 60
multi_agent_concurrent_sends: int = 15

@property
def letta_pg_uri(self) -> str:
if self.pg_uri:
Expand Down