Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
feat: move deepseek to new agent loop [LET-4081] (#4266)
cthomas27458ffad5fe
diff --git a/letta/llm_api/deepseek_client.py b/letta/llm_api/deepseek_client.pyindex 1d3828c0c..7c4d9d748 100644--- a/letta/llm_api/deepseek_client.py+++ b/letta/llm_api/deepseek_client.py@@ -1,3 +1,4 @@+import jsonimport osfrom typing import List, Optional@@ -10,6 +11,7 @@ from letta.llm_api.openai_client import OpenAIClientfrom letta.otel.tracing import trace_methodfrom letta.schemas.llm_config import LLMConfigfrom letta.schemas.message import Message as PydanticMessage+from letta.schemas.openai.chat_completion_request import ChatMessage, cast_message_to_subtypefrom letta.schemas.openai.chat_completion_response import ChatCompletionResponsefrom letta.settings import model_settings@@ -36,15 +38,19 @@ class DeepseekClient(OpenAIClient):data = super().build_request_data(messages, llm_config, tools, force_tool_call)def add_functions_to_system_message(system_message: ChatMessage):- system_message.content += f"<available functions> {''.join(json.dumps(f) for f in functions)} </available functions>"+ system_message.content += f"<available functions> {''.join(json.dumps(f) for f in tools)} </available functions>"system_message.content += 'Select best function to call simply respond with a single json block with the fields "name" and "arguments". Use double quotes around the arguments.'+ openai_message_list = [cast_message_to_subtype(m.to_openai_dict(put_inner_thoughts_in_kwargs=False)) for m in messages]+if llm_config.model == "deepseek-reasoner": # R1 currently doesn't support function calling nativelyadd_functions_to_system_message(- data["messages"][0]+ openai_message_list[0]) # Inject additional instructions to the system prompt with the available functions- data["messages"] = map_messages_to_deepseek_format(data["messages"])+ openai_message_list = map_messages_to_deepseek_format(openai_message_list)++ data["messages"] = [m.dict() for m in openai_message_list]return data@@ -94,4 +100,6 @@ class DeepseekClient(OpenAIClient):Handles potential extraction of inner thoughts if they were added via kwargs."""response = ChatCompletionResponse(**response_data)+ if response.choices[0].message.tool_calls:+ return super().convert_response_to_chat_completion(response_data, input_messages, llm_config)return convert_deepseek_response_to_chatcompletion(response)diff --git a/letta/server/rest_api/routers/v1/agents.py b/letta/server/rest_api/routers/v1/agents.pyindex 987e1dc55..df34961ce 100644--- a/letta/server/rest_api/routers/v1/agents.py+++ b/letta/server/rest_api/routers/v1/agents.py@@ -1078,6 +1078,7 @@ async def send_message("azure","xai","groq",+ "deepseek",]# Create a new run for execution tracking@@ -1223,8 +1224,9 @@ async def send_message_streaming("azure","xai","groq",+ "deepseek",]- model_compatible_token_streaming = agent.llm_config.model_endpoint_type in ["anthropic", "openai", "bedrock"]+ model_compatible_token_streaming = agent.llm_config.model_endpoint_type in ["anthropic", "openai", "bedrock", "deepseek"]# Create a new job for execution trackingif settings.track_agent_run:@@ -1480,7 +1482,10 @@ async def _process_message_background("google_vertex","bedrock","ollama",+ "azure",+ "xai","groq",+ "deepseek",]if agent_eligible and model_compatible:if agent.enable_sleeptime and agent.agent_type != AgentType.voice_convo_agent:@@ -1671,6 +1676,7 @@ async def preview_raw_payload("azure","xai","groq",+ "deepseek",]if agent_eligible and model_compatible:@@ -1742,6 +1748,7 @@ async def summarize_agent_conversation("azure","xai","groq",+ "deepseek",]if agent_eligible and model_compatible: