Skip to content

An AI Agent that interacts with Windows OS at GUI level.

Python

Fix thinking passback for Google, Mistral, and Ollama providers

jeomondfe403410b45
diff --git a/windows_use/providers/google/llm.py b/windows_use/providers/google/llm.py
index 2c1e739..2c895c4 100644
--- a/windows_use/providers/google/llm.py
+++ b/windows_use/providers/google/llm.py
@@ -322,9 +322,12 @@ class ChatGoogle(BaseChatLLM):
if function_calls:
fc = function_calls[0]
fc_id = getattr(fc, "id", None) or f"call_{uuid.uuid4().hex[:8]}"
+ thinking_content = self._extract_thinking(response)
+ thinking_obj = Thinking(content=thinking_content, signature=None) if thinking_content else None
return LLMEvent(
type=LLMEventType.TOOL_CALL,
tool_call=ToolCall(id=fc_id, name=fc.name, params=dict(fc.args) if fc.args else {}),
+ thinking=thinking_obj,
usage=usage,
)
diff --git a/windows_use/providers/mistral/llm.py b/windows_use/providers/mistral/llm.py
index 673e8fb..7e03891 100644
--- a/windows_use/providers/mistral/llm.py
+++ b/windows_use/providers/mistral/llm.py
@@ -122,10 +122,16 @@ class ChatMistral(BaseChatLLM):
# Mistral requires assistant message with tool_calls followed by tool message
# API expects 9 alphanumeric chars; model returns long IDs (toolu_...)
tool_id = _mistral_tool_call_id(msg.id)
+ thinking = getattr(msg, "thinking", None)
+ asst_content: str | list = (
+ [{"type": "thinking", "thinking": [{"type": "text", "text": thinking}]}]
+ if thinking
+ else ""
+ )
mistral_messages.append(
{
"role": "assistant",
- "content": "",
+ "content": asst_content,
"tool_calls": [
{
"id": tool_id,
@@ -239,9 +245,11 @@ class ChatMistral(BaseChatLLM):
logger.warning(f"Failed to parse tool arguments: {e}")
params = {}
+ thinking_obj = Thinking(content=thinking, signature=None) if thinking else None
content = LLMEvent(
type=LLMEventType.TOOL_CALL,
tool_call=ToolCall(id=tool_call.id, name=tool_call.function.name, params=params),
+ thinking=thinking_obj,
usage=usage,
)
else:
diff --git a/windows_use/providers/ollama/llm.py b/windows_use/providers/ollama/llm.py
index a5b3b4a..360327c 100644
--- a/windows_use/providers/ollama/llm.py
+++ b/windows_use/providers/ollama/llm.py
@@ -98,13 +98,14 @@ class ChatOllama(BaseChatLLM):
elif isinstance(msg, ToolMessage):
# Ollama expects assistant message with tool_calls followed by tool message
# Reconstruct for history consistency
- ollama_messages.append(
- {
- "role": "assistant",
- "content": "",
- "tool_calls": [{"function": {"name": msg.name, "arguments": msg.params}}],
- }
- )
+ asst_msg: dict = {
+ "role": "assistant",
+ "content": "",
+ "tool_calls": [{"function": {"name": msg.name, "arguments": msg.params}}],
+ }
+ if getattr(msg, "thinking", None):
+ asst_msg["thinking"] = msg.thinking
+ ollama_messages.append(asst_msg)
ollama_messages.append({"role": "tool", "content": msg.content or ""})
return ollama_messages
@@ -140,6 +141,7 @@ class ChatOllama(BaseChatLLM):
args = json.loads(args) if args else {}
except json.JSONDecodeError:
args = {}
+ thinking_obj = Thinking(content=thinking, signature=None) if thinking else None
return LLMEvent(
type=LLMEventType.TOOL_CALL,
tool_call=ToolCall(
@@ -147,6 +149,7 @@ class ChatOllama(BaseChatLLM):
name=func.get("name"),
params=args,
),
+ thinking=thinking_obj,
usage=usage,
)
thinking_obj = Thinking(content=thinking, signature=None) if thinking else None