The Memory Layer for AI Agents - Drop-in memory infrastructure for AI agents and apps. Context that persists. Built for production.
Python agentic-memoryagentic-memory-systemagentsaiai-agentschatgptgenaillmlong-term-memorymemorymemory-managementpythonragstate-management
Fix/supported llm params (#3290)
Parshva Daftari2307dc86135a
diff --git a/docs/components/llms/models/openai.mdx b/docs/components/llms/models/openai.mdxindex 4682bce64..064607a2f 100644--- a/docs/components/llms/models/openai.mdx+++ b/docs/components/llms/models/openai.mdx@@ -6,6 +6,8 @@ title: OpenAITo use OpenAI LLM models, you have to set the `OPENAI_API_KEY` environment variable. You can obtain the OpenAI API key from the [OpenAI Platform](https://platform.openai.com/account/api-keys).+> **Note**: The following are currently unsupported with reasoning models `Parallel tool calling`,`temperature`, `top_p`, `presence_penalty`, `frequency_penalty`, `logprobs`, `top_logprobs`, `logit_bias`, `max_tokens`+## Usage<CodeGroup>diff --git a/mem0/llms/anthropic.py b/mem0/llms/anthropic.pyindex 61c180a0a..2caaec3a7 100644--- a/mem0/llms/anthropic.py+++ b/mem0/llms/anthropic.py@@ -70,8 +70,7 @@ class AnthropicLLM(LLMBase):else:filtered_messages.append(message)- # Get common parameters- params = self._get_common_params(**kwargs)+ params = self._get_supported_params(messages=messages, **kwargs)params.update({"model": self.config.model,diff --git a/mem0/llms/azure_openai.py b/mem0/llms/azure_openai.pyindex e7802bc31..ce97fd44b 100644--- a/mem0/llms/azure_openai.py+++ b/mem0/llms/azure_openai.py@@ -110,27 +110,13 @@ class AzureOpenAILLM(LLMBase):messages[-1]["content"] = user_prompt- # Get common parameters- params = self._get_common_params(**kwargs)- params.update(- {- "model": self.config.model,- "messages": messages,- }- )-- if self.config.model in {"o3-mini", "o1-preview", "o1"}:- # Use common params for these models- pass- else:- # Add additional parameters for other models- params.update(- {- "temperature": self.config.temperature,- "max_tokens": self.config.max_tokens,- "top_p": self.config.top_p,- }- )+ params = self._get_supported_params(messages=messages, **kwargs)++ # Add model and messages+ params.update({+ "model": self.config.model,+ "messages": messages,+ })if tools:params["tools"] = toolsdiff --git a/mem0/llms/base.py b/mem0/llms/base.pyindex 1cc6433a6..121254102 100644--- a/mem0/llms/base.py+++ b/mem0/llms/base.py@@ -40,6 +40,60 @@ class LLMBase(ABC):# This will be handled by individual providerspass+ def _is_reasoning_model(self, model: str) -> bool:+ """+ Check if the model is a reasoning model or GPT-5 series that doesn't support certain parameters.++ Args:+ model: The model name to check++ Returns:+ bool: True if the model is a reasoning model or GPT-5 series+ """+ reasoning_models = {+ "o1", "o1-preview", "o3-mini", "o3",+ "gpt-5", "gpt-5o", "gpt-5o-mini", "gpt-5o-micro",+ }++ if model.lower() in reasoning_models:+ return True++ model_lower = model.lower()+ if any(reasoning_model in model_lower for reasoning_model in ["gpt-5", "o1", "o3"]):+ return True++ return False++ def _get_supported_params(self, **kwargs) -> Dict:+ """+ Get parameters that are supported by the current model.+ Filters out unsupported parameters for reasoning models and GPT-5 series.++ Args:+ **kwargs: Additional parameters to include++ Returns:+ Dict: Filtered parameters dictionary+ """+ model = getattr(self.config, 'model', '')++ if self._is_reasoning_model(model):+ supported_params = {}++ if "messages" in kwargs:+ supported_params["messages"] = kwargs["messages"]+ if "response_format" in kwargs:+ supported_params["response_format"] = kwargs["response_format"]+ if "tools" in kwargs:+ supported_params["tools"] = kwargs["tools"]+ if "tool_choice" in kwargs:+ supported_params["tool_choice"] = kwargs["tool_choice"]++ return supported_params+ else:+ # For regular models, include all common parameters+ return self._get_common_params(**kwargs)+@abstractmethoddef generate_response(self, messages: List[Dict[str, str]], tools: Optional[List[Dict]] = None, tool_choice: str = "auto", **kwargsdiff --git a/mem0/llms/deepseek.py b/mem0/llms/deepseek.pyindex 8b5692f2e..a9877065e 100644--- a/mem0/llms/deepseek.py+++ b/mem0/llms/deepseek.py@@ -91,8 +91,7 @@ class DeepSeekLLM(LLMBase):Returns:str: The generated response."""- # Get common parameters- params = self._get_common_params(**kwargs)+ params = self._get_supported_params(messages=messages, **kwargs)params.update({"model": self.config.model,diff --git a/mem0/llms/lmstudio.py b/mem0/llms/lmstudio.pyindex 2c3f0a9fb..aab5d0777 100644--- a/mem0/llms/lmstudio.py+++ b/mem0/llms/lmstudio.py@@ -91,8 +91,7 @@ class LMStudioLLM(LLMBase):Returns:str: The generated response."""- # Get common parameters- params = self._get_common_params(**kwargs)+ params = self._get_supported_params(messages=messages, **kwargs)params.update({"model": self.config.model,@@ -100,13 +99,11 @@ class LMStudioLLM(LLMBase):})- # Handle response format - LM Studio defaults to json_objectif self.config.lmstudio_response_format:params["response_format"] = self.config.lmstudio_response_formatelif response_format:params["response_format"] = response_formatelse:- # Default to json_object for LM Studioparams["response_format"] = {"type": "json_object"}if tools:diff --git a/mem0/llms/openai.py b/mem0/llms/openai.pyindex e3cb917db..dae1dd48a 100644--- a/mem0/llms/openai.py+++ b/mem0/llms/openai.py@@ -101,14 +101,12 @@ class OpenAILLM(LLMBase):Returns:json: The generated response."""- # Get common parameters- params = self._get_common_params(**kwargs)- params.update(- {- "model": self.config.model,- "messages": messages,- }- )+ params = self._get_supported_params(messages=messages, **kwargs)++ params.update({+ "model": self.config.model,+ "messages": messages,+ })if os.getenv("OPENROUTER_API_KEY"):openrouter_params = {}diff --git a/mem0/llms/vllm.py b/mem0/llms/vllm.pyindex 7953c4ef7..f7cbfbc58 100644--- a/mem0/llms/vllm.py+++ b/mem0/llms/vllm.py@@ -91,8 +91,7 @@ class VllmLLM(LLMBase):Returns:str: The generated response."""- # Get common parameters- params = self._get_common_params(**kwargs)+ params = self._get_supported_params(messages=messages, **kwargs)params.update({"model": self.config.model,