The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(custom): clamp top-level reasoning_effort to Groq's none/default vocabulary on api.groq.com
teknium1981cb8302046
diff --git a/plugins/model-providers/custom/__init__.py b/plugins/model-providers/custom/__init__.pyindex 01909ebd074..7e54174f7dc 100644--- a/plugins/model-providers/custom/__init__.py+++ b/plugins/model-providers/custom/__init__.py@@ -7,6 +7,7 @@ from urllib.parse import urlparsefrom agent.reasoning_effort import OPENAI_COMPAT_WIRE_EFFORTS, clamp_effortfrom providers import register_providerfrom providers.base import ProviderProfile+from utils import base_url_host_matchesdef _looks_like_ollama_endpoint(base_url: str | None) -> bool:@@ -62,6 +63,10 @@ class CustomProfile(ProviderProfile):top_level["reasoning_effort"] = "none"if _looks_like_ollama_endpoint(ctx.get("base_url")):extra_body["think"] = False+ elif effort and base_url_host_matches(str(ctx.get("base_url") or ""), "api.groq.com"):+ # Groq's OpenAI-compatible wire accepts top-level reasoning_effort only as+ # "none" / "default"; any graded level ("medium", "high") 400s (#75089).+ top_level["reasoning_effort"] = "default"elif effort:top_level["reasoning_effort"] = clamp_effort(effort, OPENAI_COMPAT_WIRE_EFFORTS)return extra_body, top_leveldiff --git a/tests/agent/test_auxiliary_named_custom_providers.py b/tests/agent/test_auxiliary_named_custom_providers.pyindex 9b2485d62b3..1090e79977a 100644--- a/tests/agent/test_auxiliary_named_custom_providers.py+++ b/tests/agent/test_auxiliary_named_custom_providers.py@@ -553,14 +553,20 @@ class TestKeyedCustomProviderReasoningWire:@pytest.mark.parametrize("provider", ["groq", "main", "custom:groq"])def test_keyed_entry_sends_top_level_reasoning_effort(self, tmp_path, provider):+ """api.groq.com takes top-level reasoning_effort only as 'none'/'default' (#75089), so the+ configured 'medium' is clamped to 'default' — the bare-key case goes through ``call_llm``."""_write_config(tmp_path, self._KEYED)- from agent.auxiliary_client import _build_call_kwargs- kwargs = _build_call_kwargs(- provider, "vendor/model", [{"role": "user", "content": "hi"}],- reasoning_config={"enabled": True, "effort": "medium"},- base_url="https://api.groq.com/openai/v1",- )- assert kwargs.get("reasoning_effort") == "medium"+ from agent.auxiliary_client import _build_call_kwargs, call_llm+ common = dict(reasoning_config={"enabled": True, "effort": "medium"}, base_url="https://api.groq.com/openai/v1")+ if provider == "groq":+ client = MagicMock(base_url=common["base_url"])+ with patch("agent.auxiliary_client._get_cached_client", return_value=(client, "vendor/model")), \+ patch("agent.auxiliary_client._validate_llm_response", side_effect=lambda resp, _t, **_kw: resp):+ call_llm(provider=provider, model="vendor/model", messages=[{"role": "user", "content": "hi"}], **common)+ kwargs = client.chat.completions.create.call_args.kwargs+ else:+ kwargs = _build_call_kwargs(provider, "vendor/model", [{"role": "user", "content": "hi"}], **common)+ assert kwargs.get("reasoning_effort") == "default"assert "reasoning" not in (kwargs.get("extra_body") or {})def test_profile_backed_and_unknown_providers_keep_their_wire(self, tmp_path):diff --git a/tests/plugins/model_providers/test_custom_profile.py b/tests/plugins/model_providers/test_custom_profile.pyindex 33a59db9211..d725ebdd966 100644--- a/tests/plugins/model_providers/test_custom_profile.py+++ b/tests/plugins/model_providers/test_custom_profile.py@@ -169,6 +169,25 @@ class TestCustomReasoningWireShape:)assert eb.get("think") is not True+ @pytest.mark.parametrize(+ "reasoning_config, expected",+ [({"enabled": True, "effort": "high"}, "default"), ({"enabled": False, "effort": "medium"}, "none")],+ )+ def test_groq_host_clamps_effort_to_groq_vocabulary(self, custom_profile, reasoning_config, expected):+ """api.groq.com accepts top-level reasoning_effort only as 'none' / 'default' (#75089).++ Drives the main transport so the clamp is proven where production reads it.+ """+ from agent.transports.chat_completions import ChatCompletionsTransport++ kwargs = ChatCompletionsTransport().build_kwargs(+ model="qwen/qwen3.6-27b", messages=[{"role": "user", "content": "ping"}], tools=None,+ provider_profile=custom_profile, reasoning_config=reasoning_config,+ base_url="https://api.groq.com/openai/v1", provider_name="custom",+ )+ assert kwargs["reasoning_effort"] == expected+ assert "think" not in kwargs.get("extra_body", {}) and "reasoning" not in kwargs.get("extra_body", {})+class TestCustomReasoningWithNumCtx:"""Ollama num_ctx and reasoning are independent and compose."""