Build and run agents you can see, understand and trust.
Python agentchatbotlarge-language-modelsllmllm-agentmcpmulti-agentmulti-modalreact-agentrealtime-agentvoice-agentvoice-assistant
feat(model): only send think option to Ollama when explicitly configured (#3510)
Kiko030157bcda2e4de3
diff --git a/src/agentscope/model/_ollama/_model.py b/src/agentscope/model/_ollama/_model.pyindex 63e205222..93ca944a4 100644--- a/src/agentscope/model/_ollama/_model.py+++ b/src/agentscope/model/_ollama/_model.py@@ -35,11 +35,13 @@ class OllamaChatModel(ChatModelBase):gt=0,)- thinking_enable: bool = Field(- default=False,+ thinking_enable: bool | None = Field(+ default=None,title="Thinking",description="Whether to enable thinking"- " (for models like qwen3, deepseek-r1).",+ " (for models like qwen3, deepseek-r1)."+ " When None, the ``think`` option is not sent and the"+ " model's default behavior applies.",)temperature: float | None = Field(@@ -173,7 +175,8 @@ class OllamaChatModel(ChatModelBase):if options:kwargs["options"] = options- kwargs["think"] = self.parameters.thinking_enable+ if self.parameters.thinking_enable is not None:+ kwargs["think"] = self.parameters.thinking_enablekwargs.update(generate_kwargs)diff --git a/tests/model_ollama_test.py b/tests/model_ollama_test.pyindex 03d091c38..0e90f36aa 100644--- a/tests/model_ollama_test.py+++ b/tests/model_ollama_test.py@@ -403,6 +403,69 @@ class TestOllamaFormatTools(unittest.TestCase):self.assertIsNone(fmt_choice)+class TestOllamaThinkParameter(IsolatedAsyncioTestCase):+ """The ``think`` option is only sent when explicitly configured."""++ def setUp(self) -> None:+ self.model = _make_model(stream=False)+ self.mock_client = MagicMock()+ self.model.client = self.mock_client+ self.mock_client.chat = AsyncMock(+ return_value=_mock_completion(content="Hi"),+ )++ async def _call_and_get_kwargs(self) -> dict:+ """Run one call and return the kwargs passed to client.chat."""+ await self.model([])+ call = self.mock_client.chat.await_args+ return call.kwargs++ async def test_think_omitted_by_default(self) -> None:+ """Default parameters leave ``think`` out of the request so the+ model's own default behavior applies."""+ kwargs = await self._call_and_get_kwargs()+ self.assertEqual(+ kwargs,+ {+ "model": "qwen3:8b",+ "messages": [],+ "stream": False,+ },+ )++ async def test_think_true_forwarded(self) -> None:+ """``thinking_enable=True`` sends ``think: true``."""+ self.model.parameters = OllamaChatModel.Parameters(+ thinking_enable=True,+ )+ kwargs = await self._call_and_get_kwargs()+ self.assertEqual(+ kwargs,+ {+ "model": "qwen3:8b",+ "messages": [],+ "stream": False,+ "think": True,+ },+ )++ async def test_think_false_forwarded(self) -> None:+ """``thinking_enable=False`` sends ``think: false``."""+ self.model.parameters = OllamaChatModel.Parameters(+ thinking_enable=False,+ )+ kwargs = await self._call_and_get_kwargs()+ self.assertEqual(+ kwargs,+ {+ "model": "qwen3:8b",+ "messages": [],+ "stream": False,+ "think": False,+ },+ )++def _api_chat_transport(messages: list[dict | list[dict]],stream: bool,