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: Patch batch routes (#4916)

Matthew Zhoub0bc04fec775
diff --git a/letta/agents/letta_agent_batch.py b/letta/agents/letta_agent_batch.py
index 5d1e6b172..c0385e1de 100644
--- a/letta/agents/letta_agent_batch.py
+++ b/letta/agents/letta_agent_batch.py
@@ -192,6 +192,7 @@ class LettaAgentBatch(BaseAgent):
log_event(name="send_llm_batch_request")
batch_response = await llm_client.send_llm_batch_request_async(
+ agent_type=agent_states[0].agent_type,
agent_messages_mapping=agent_messages_mapping,
agent_tools_mapping=agent_tools_mapping,
agent_llm_config_mapping=agent_llm_config_mapping,
diff --git a/letta/llm_api/anthropic_client.py b/letta/llm_api/anthropic_client.py
index 724b41d51..d01d8da79 100644
--- a/letta/llm_api/anthropic_client.py
+++ b/letta/llm_api/anthropic_client.py
@@ -89,6 +89,7 @@ class AnthropicClient(LLMClientBase):
@trace_method
async def send_llm_batch_request_async(
self,
+ agent_type: AgentType,
agent_messages_mapping: Dict[str, List[PydanticMessage]],
agent_tools_mapping: Dict[str, List[dict]],
agent_llm_config_mapping: Dict[str, LLMConfig],
@@ -115,7 +116,7 @@ class AnthropicClient(LLMClientBase):
try:
requests = {
agent_id: self.build_request_data(
- agent_type=agent_llm_config_mapping[agent_id].agent_type,
+ agent_type=agent_type,
messages=agent_messages_mapping[agent_id],
llm_config=agent_llm_config_mapping[agent_id],
tools=agent_tools_mapping[agent_id],
diff --git a/letta/llm_api/llm_client_base.py b/letta/llm_api/llm_client_base.py
index f0b2d0fe5..a8a3595b7 100644
--- a/letta/llm_api/llm_client_base.py
+++ b/letta/llm_api/llm_client_base.py
@@ -109,6 +109,7 @@ class LLMClientBase:
async def send_llm_batch_request_async(
self,
+ agent_type: AgentType,
agent_messages_mapping: Dict[str, List[Message]],
agent_tools_mapping: Dict[str, List[dict]],
agent_llm_config_mapping: Dict[str, LLMConfig],
diff --git a/tests/test_llm_clients.py b/tests/test_llm_clients.py
index 099a98a92..8ce7ebb32 100644
--- a/tests/test_llm_clients.py
+++ b/tests/test_llm_clients.py
@@ -5,7 +5,7 @@ import pytest
# Import your AnthropicClient and related types
from letta.llm_api.anthropic_client import AnthropicClient
-from letta.schemas.enums import MessageRole
+from letta.schemas.enums import AgentType, MessageRole
from letta.schemas.llm_config import LLMConfig
from letta.schemas.message import Message as PydanticMessage
@@ -81,7 +81,9 @@ async def test_send_llm_batch_request_async_success(
mock_get_client.return_value = mock_client
# Call the method under test.
- response = await anthropic_client.send_llm_batch_request_async(mock_agent_messages, mock_agent_tools, mock_agent_llm_config)
+ response = await anthropic_client.send_llm_batch_request_async(
+ AgentType.memgpt_agent, mock_agent_messages, mock_agent_tools, mock_agent_llm_config
+ )
# Assert that the response is our dummy response.
assert response.id == dummy_beta_message_batch.id
@@ -100,4 +102,6 @@ async def test_send_llm_batch_request_async_mismatched_keys(anthropic_client, mo
"""
mismatched_tools = {"agent-2": []} # Different agent ID than in the messages mapping.
with pytest.raises(ValueError, match="Agent mappings for messages and tools must use the same agent_ids."):
- await anthropic_client.send_llm_batch_request_async(mock_agent_messages, mismatched_tools, mock_agent_llm_config)
+ await anthropic_client.send_llm_batch_request_async(
+ AgentType.memgpt_agent, mock_agent_messages, mismatched_tools, mock_agent_llm_config
+ )