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.

feat: Refactor tests and add safety check (#1995)

Matthew Zhou2929eb801286
diff --git a/letta/agents/voice_agent.py b/letta/agents/voice_agent.py
index 692973725..27c3c7e38 100644
--- a/letta/agents/voice_agent.py
+++ b/letta/agents/voice_agent.py
@@ -131,6 +131,8 @@ class VoiceAgent(BaseAgent):
if agent_state.llm_config.model_endpoint_type == "anthropic":
self.openai_client.api_key = model_settings.anthropic_api_key
self.openai_client.base_url = "https://api.anthropic.com/v1/"
+ elif agent_state.llm_config.model_endpoint_type != "openai":
+ raise ValueError("Letta voice agents are only compatible with OpenAI or Anthropic.")
# Safety check
if agent_state.agent_type != AgentType.voice_convo_agent:
diff --git a/tests/integration_test_voice_agent.py b/tests/integration_test_voice_agent.py
index 9f3db3372..6ace4640f 100644
--- a/tests/integration_test_voice_agent.py
+++ b/tests/integration_test_voice_agent.py
@@ -216,34 +216,6 @@ def voice_agent(server, actor):
return main_agent
[email protected](scope="function")
-def voice_agent_anthropic(server, actor):
- server.tool_manager.upsert_base_tools(actor=actor)
-
- main_agent = server.create_agent(
- request=CreateAgent(
- agent_type=AgentType.voice_convo_agent,
- name="main_agent",
- memory_blocks=[
- CreateBlock(
- label="persona",
- value="You are a personal assistant that helps users with requests.",
- ),
- CreateBlock(
- label="human",
- value="My favorite plant is the fiddle leaf\nMy favorite color is lavender",
- ),
- ],
- model="anthropic/claude-3-5-sonnet-20241022",
- embedding="openai/text-embedding-ada-002",
- enable_sleeptime=True,
- ),
- actor=actor,
- )
-
- return main_agent
-
-
@pytest.fixture
def group_id(voice_agent):
return voice_agent.multi_agent_group.id
@@ -296,6 +268,41 @@ def _assert_valid_chunk(chunk, idx, chunks):
# --- Tests --- #
[email protected]("model", ["openai/gpt-4o-mini", "anthropic/claude-3-5-sonnet-20241022"])
+async def test_model_compatibility(disable_e2b_api_key, client, model, server, group_id, actor):
+ request = _get_chat_request("How are you?")
+ server.tool_manager.upsert_base_tools(actor=actor)
+
+ main_agent = server.create_agent(
+ request=CreateAgent(
+ agent_type=AgentType.voice_convo_agent,
+ name="main_agent",
+ memory_blocks=[
+ CreateBlock(
+ label="persona",
+ value="You are a personal assistant that helps users with requests.",
+ ),
+ CreateBlock(
+ label="human",
+ value="My favorite plant is the fiddle leaf\nMy favorite color is lavender",
+ ),
+ ],
+ model=model,
+ embedding="openai/text-embedding-ada-002",
+ enable_sleeptime=True,
+ ),
+ actor=actor,
+ )
+ async_client = AsyncOpenAI(base_url=f"http://localhost:8283/v1/voice-beta/{main_agent.id}", max_retries=0)
+
+ stream = await async_client.chat.completions.create(**request.model_dump(exclude_none=True))
+ async with stream:
+ async for chunk in stream:
+ if chunk.choices and chunk.choices[0].delta.content:
+ print(chunk.choices[0].delta.content)
+
+
@pytest.mark.asyncio
@pytest.mark.parametrize("message", ["Use search memory tool to recall what my name is."])
@pytest.mark.parametrize("endpoint", ["v1/voice-beta"])
@@ -313,7 +320,7 @@ async def test_voice_recall_memory(disable_e2b_api_key, client, voice_agent, mes
@pytest.mark.asyncio
@pytest.mark.parametrize("endpoint", ["v1/voice-beta"])
-async def test_trigger_summarization(disable_e2b_api_key, client, server, voice_agent_anthropic, group_id, endpoint, actor):
+async def test_trigger_summarization(disable_e2b_api_key, client, server, voice_agent, group_id, endpoint, actor):
server.group_manager.modify_group(
group_id=group_id,
group_update=GroupUpdate(
@@ -327,7 +334,7 @@ async def test_trigger_summarization(disable_e2b_api_key, client, server, voice_
)
request = _get_chat_request("How are you?")
- async_client = AsyncOpenAI(base_url=f"http://localhost:8283/{endpoint}/{voice_agent_anthropic.id}", max_retries=0)
+ async_client = AsyncOpenAI(base_url=f"http://localhost:8283/{endpoint}/{voice_agent.id}", max_retries=0)
stream = await async_client.chat.completions.create(**request.model_dump(exclude_none=True))
async with stream: