An AI Agent that interacts with Windows OS at GUI level.
Python
Fix reasoning_content passback across all providers
jeomon9116d94fe017
diff --git a/windows_use/providers/azure_openai/llm.py b/windows_use/providers/azure_openai/llm.pyindex 2008358..07acc38 100644--- a/windows_use/providers/azure_openai/llm.py+++ b/windows_use/providers/azure_openai/llm.py@@ -118,7 +118,7 @@ class ChatAzureOpenAI(BaseChatLLM):openai_messages.append({"role": "user", "content": content_list})elif isinstance(msg, AIMessage):msg_dict: dict = {"role": "assistant", "content": msg.content or ""}- if self._is_reasoning_model() and getattr(msg, "thinking", None):+ if getattr(msg, "thinking", None):msg_dict["reasoning_content"] = msg.thinkingopenai_messages.append(msg_dict)elif isinstance(msg, ToolMessage):@@ -128,9 +128,10 @@ class ChatAzureOpenAI(BaseChatLLM):"type": "function","function": {"name": msg.name, "arguments": json.dumps(msg.params)},}- openai_messages.append(- {"role": "assistant", "content": None, "tool_calls": [tool_call]}- )+ assistant_msg: dict = {"role": "assistant", "content": None, "tool_calls": [tool_call]}+ if getattr(msg, "thinking", None):+ assistant_msg["reasoning_content"] = msg.thinking+ openai_messages.append(assistant_msg)openai_messages.append({"role": "tool", "tool_call_id": msg.id, "content": msg.content or ""})@@ -167,13 +168,9 @@ class ChatAzureOpenAI(BaseChatLLM):thinking_tokens=thinking_tokens,)- # Extract thinking/reasoning content (for o-series models)- thinking = None- if self._is_reasoning_model():- if hasattr(message, "reasoning_content"):- thinking = message.reasoning_content- elif hasattr(choice, "reasoning_content"):- thinking = choice.reasoning_content+ thinking = getattr(message, "reasoning_content", None) or getattr(+ choice, "reasoning_content", None+ )thinking_obj = Thinking(content=thinking, signature=None) if thinking else None@@ -403,11 +400,7 @@ class ChatAzureOpenAI(BaseChatLLM):delta = chunk.choices[0].delta# Handle reasoning content for o-series models- if (- self._is_reasoning_model()- and hasattr(delta, "reasoning_content")- and delta.reasoning_content- ):+ if hasattr(delta, "reasoning_content") and delta.reasoning_content:if not think_started:think_started = Trueyield LLMStreamEvent(type=LLMStreamEventType.THINK_START)@@ -521,11 +514,7 @@ class ChatAzureOpenAI(BaseChatLLM):delta = chunk.choices[0].delta- if (- self._is_reasoning_model()- and hasattr(delta, "reasoning_content")- and delta.reasoning_content- ):+ if hasattr(delta, "reasoning_content") and delta.reasoning_content:if not think_started:think_started = Trueyield LLMStreamEvent(type=LLMStreamEventType.THINK_START)diff --git a/windows_use/providers/cerebras/llm.py b/windows_use/providers/cerebras/llm.pyindex 3787861..d1e5875 100644--- a/windows_use/providers/cerebras/llm.py+++ b/windows_use/providers/cerebras/llm.py@@ -134,8 +134,13 @@ class ChatCerebras(BaseChatLLM):"type": "function","function": {"name": msg.name, "arguments": json.dumps(msg.params)},}+ thinking = getattr(msg, "thinking", None)cerebras_messages.append(- {"role": "assistant", "content": None, "tool_calls": [tool_call]}+ {+ "role": "assistant",+ "content": self._format_assistant_content(None, thinking) if thinking else None,+ "tool_calls": [tool_call],+ })cerebras_messages.append({"role": "tool", "tool_call_id": msg.id, "content": msg.content or ""}diff --git a/windows_use/providers/groq/llm.py b/windows_use/providers/groq/llm.pyindex 4c13d16..326d3d2 100644--- a/windows_use/providers/groq/llm.py+++ b/windows_use/providers/groq/llm.py@@ -120,7 +120,7 @@ class ChatGroq(BaseChatLLM):groq_messages.append({"role": "user", "content": content_list})elif isinstance(msg, AIMessage):msg_dict: dict = {"role": "assistant", "content": msg.content or ""}- if self._is_reasoning_model() and getattr(msg, "thinking", None):+ if getattr(msg, "thinking", None):msg_dict["reasoning"] = msg.thinkinggroq_messages.append(msg_dict)elif isinstance(msg, ToolMessage):@@ -130,9 +130,10 @@ class ChatGroq(BaseChatLLM):"type": "function","function": {"name": msg.name, "arguments": json.dumps(msg.params)},}- groq_messages.append(- {"role": "assistant", "content": None, "tool_calls": [tool_call]}- )+ assistant_msg: dict = {"role": "assistant", "content": None, "tool_calls": [tool_call]}+ if getattr(msg, "thinking", None):+ assistant_msg["reasoning"] = msg.thinking+ groq_messages.append(assistant_msg)groq_messages.append({"role": "tool", "tool_call_id": msg.id, "content": msg.content or ""})diff --git a/windows_use/providers/openai/llm.py b/windows_use/providers/openai/llm.pyindex 025ddcc..ec749f3 100644--- a/windows_use/providers/openai/llm.py+++ b/windows_use/providers/openai/llm.py@@ -178,13 +178,9 @@ class ChatOpenAI(BaseChatLLM):thinking_tokens=thinking_tokens,)- # Extract thinking/reasoning content (for o1 models)- thinking = None- if self._is_reasoning_model():- if hasattr(message, "reasoning_content"):- thinking = message.reasoning_content- elif hasattr(choice, "reasoning_content"):- thinking = choice.reasoning_content+ thinking = getattr(message, "reasoning_content", None) or getattr(+ choice, "reasoning_content", None+ )thinking_obj = Thinking(content=thinking, signature=None) if thinking else None@@ -404,11 +400,7 @@ class ChatOpenAI(BaseChatLLM):delta = chunk.choices[0].delta- if (- self._is_reasoning_model()- and hasattr(delta, "reasoning_content")- and delta.reasoning_content- ):+ if hasattr(delta, "reasoning_content") and delta.reasoning_content:if not think_started:think_started = Trueyield LLMStreamEvent(type=LLMStreamEventType.THINK_START)@@ -525,11 +517,7 @@ class ChatOpenAI(BaseChatLLM):delta = chunk.choices[0].delta- if (- self._is_reasoning_model()- and hasattr(delta, "reasoning_content")- and delta.reasoning_content- ):+ if hasattr(delta, "reasoning_content") and delta.reasoning_content:if not think_started:think_started = Trueyield LLMStreamEvent(type=LLMStreamEventType.THINK_START)