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 thinking option to Moonshot when explicitly configured (#3521)
Kiko030107fda8fa2885
diff --git a/src/agentscope/model/_moonshot/_model.py b/src/agentscope/model/_moonshot/_model.pyindex c92c3c2f7..d77d55e20 100644--- a/src/agentscope/model/_moonshot/_model.py+++ b/src/agentscope/model/_moonshot/_model.py@@ -36,13 +36,15 @@ class MoonshotChatModel(ChatModelBase):gt=0,)- thinking_enable: bool = Field(- default=False,+ thinking_enable: bool | None = Field(+ default=None,title="Thinking",description=("Whether to enable thinking mode. For kimi-k2-thinking, ""thinking is always enabled. For kimi-k2.6, thinking is "- "enabled by default but can be disabled."+ "enabled by default but can be disabled. When None, no "+ "``thinking`` option is sent and the model's default "+ "behavior applies."),)@@ -208,7 +210,7 @@ class MoonshotChatModel(ChatModelBase):if is_k3:if self.parameters.reasoning_effort is not None:kwargs["reasoning_effort"] = self.parameters.reasoning_effort- else:+ elif self.parameters.thinking_enable is not None:thinking_type = ("enabled" if self.parameters.thinking_enable else "disabled")diff --git a/tests/model_moonshot_test.py b/tests/model_moonshot_test.pyindex f7f7119fb..57208061b 100644--- a/tests/model_moonshot_test.py+++ b/tests/model_moonshot_test.py@@ -220,7 +220,8 @@ class TestMoonshotNonStream(IsolatedAsyncioTestCase):)async def test_extra_body_is_not_mutated(self) -> None:- """Defaulting thinking.type leaves the caller's extra_body intact."""+ """Default parameters leave the caller's extra_body intact — no+ ``thinking`` option is injected and the caller's dict is untouched."""mock_create = AsyncMock(return_value=_mock_completion(text="Hello!"),)@@ -235,10 +236,56 @@ class TestMoonshotNonStream(IsolatedAsyncioTestCase):)self.assertDictEqual(mock_create.await_args.kwargs["extra_body"],- {- "custom": "value",- "thinking": {"budget_tokens": 1024, "type": "disabled"},- },+ {"custom": "value", "thinking": {"budget_tokens": 1024}},+ )++ async def test_thinking_omitted_by_default(self) -> None:+ """Default parameters send no ``thinking`` option so the model's+ default behavior applies."""+ mock_create = AsyncMock(+ return_value=_mock_completion(text="Hello!"),+ )+ self.mock_client.chat.completions.create = mock_create++ await self.model([])++ extra_body = mock_create.await_args.kwargs.get("extra_body") or {}+ self.assertNotIn("thinking", extra_body)++ async def test_thinking_disabled_forwarded(self) -> None:+ """``thinking_enable=False`` sends ``thinking.type: disabled``."""+ mock_create = AsyncMock(+ return_value=_mock_completion(text="Hello!"),+ )+ self.mock_client.chat.completions.create = mock_create+ self.model.parameters = MoonshotChatModel.Parameters(+ thinking_enable=False,+ )++ await self.model([])++ extra_body = mock_create.await_args.kwargs["extra_body"]+ self.assertEqual(+ extra_body,+ {"thinking": {"type": "disabled"}},+ )++ async def test_thinking_enabled_forwarded(self) -> None:+ """``thinking_enable=True`` sends ``thinking.type: enabled``."""+ mock_create = AsyncMock(+ return_value=_mock_completion(text="Hello!"),+ )+ self.mock_client.chat.completions.create = mock_create+ self.model.parameters = MoonshotChatModel.Parameters(+ thinking_enable=True,+ )++ await self.model([])++ extra_body = mock_create.await_args.kwargs["extra_body"]+ self.assertEqual(+ extra_body,+ {"thinking": {"type": "enabled"}},)async def test_tool_call_response(