Skip to content

The agent that grows with you

fix: send reasoning_effort=medium on custom endpoints when agent.reasoning_effort is unset

teknium153815e24dcc4
diff --git a/agent/chat_completion_helpers.py b/agent/chat_completion_helpers.py
index 3ced9df9f9e..98b5019d7f5 100644
--- a/agent/chat_completion_helpers.py
+++ b/agent/chat_completion_helpers.py
@@ -1276,6 +1276,11 @@ def _reasoning_config_for_wire(agent):
# the route default — as the auxiliary ladder does; resending would 400 identically.
agent._wire_reasoning_config = None
return None
+ if cfg is None:
+ # Unset effort: the profile's default (custom/OpenAI-compatible: medium) rather than the
+ # route's own, recorded below as what went out so a rejection of it lands in the branch above.
+ from agent.reasoning_params import unset_reasoning_default
+ cfg = unset_reasoning_default(agent)
if getattr(agent, "_reasoning_disable_rejected", False):
# The route rejects disables. Resend exactly what the session has
# been sending — the user's own config — so the retry lands on the
diff --git a/agent/reasoning_params.py b/agent/reasoning_params.py
index 05b253a6543..072f4d05cc7 100644
--- a/agent/reasoning_params.py
+++ b/agent/reasoning_params.py
@@ -43,6 +43,45 @@ def _cached_probe(agent, cache_attr: str, probe, unknown, definitive):
return value
+def unset_reasoning_default(agent) -> dict | None:
+ """Reasoning config for a main-loop request whose ``agent.reasoning_effort`` is unset.
+
+ Asks the active provider profile (``ProviderProfile.default_reasoning_config``; the custom /
+ OpenAI-compatible profile answers medium) so a route's own default never silently applies —
+ kimi-k3 behind a relay defaults to ``max``, 3x the reasoning tokens of medium. Resolved at
+ request time, so ``/model`` and fallback activation re-evaluate it. None keeps the field off
+ the wire: a non chat-completions transport, a profile without a default (those decide inside
+ ``build_api_kwargs_extras``), a model the catalog / ``model_overrides`` mark
+ ``supports_reasoning: false``, or a local Ollama model whose ``/api/show`` lacks ``thinking``.
+ """
+ if getattr(agent, "api_mode", None) != "chat_completions":
+ return None
+ provider = str(getattr(agent, "provider", "") or "")
+ model = str(getattr(agent, "model", "") or "")
+ try:
+ from providers import get_provider_profile
+
+ profile = get_provider_profile(provider)
+ default = profile.default_reasoning_config(model) if profile is not None else None
+ except Exception:
+ return None
+ if not default:
+ return None
+ try:
+ from agent.models_dev import get_model_capabilities
+
+ caps = get_model_capabilities(provider, model, allow_network=False)
+ except Exception:
+ caps = None
+ if caps is not None and caps.supports_reasoning is False:
+ return None
+ # ``_ollama_num_ctx`` is only ever set for a server detected as Ollama (agent_init); Ollama
+ # 400s ``reasoning_effort`` on a model pulled without the thinking capability.
+ if getattr(agent, "_ollama_num_ctx", None) and not agent._ollama_supports_thinking_cached():
+ return None
+ return dict(default)
+
+
class ReasoningParamsMixin:
"""Reasoning-parameter gating and echo policy (see module docstring)."""
diff --git a/plugins/model-providers/custom/__init__.py b/plugins/model-providers/custom/__init__.py
index 7e54174f7dc..2858553dc8c 100644
--- a/plugins/model-providers/custom/__init__.py
+++ b/plugins/model-providers/custom/__init__.py
@@ -43,6 +43,16 @@ class CustomProfile(ProviderProfile):
"""
return OPENAI_COMPAT_WIRE_EFFORTS
+ def default_reasoning_config(self, model: str | None = None) -> dict | None:
+ """Unset ``agent.reasoning_effort`` → ``medium``, as on the Nous / OpenRouter profiles.
+
+ Leaving the field off lets the endpoint's own default apply, and for a hosted reasoning
+ model that default can be its ceiling: kimi-k3 behind an OpenAI-compatible relay defaults
+ to ``max`` — 3x the reasoning tokens and ~3x the latency of medium. The agent skips this
+ default for models the catalog marks non-reasoning (``agent.reasoning_params``).
+ """
+ return {"enabled": True, "effort": "medium"}
+
def build_api_kwargs_extras(
self, *, reasoning_config: dict | None = None, ollama_num_ctx: int | None = None, **ctx: Any
) -> tuple[dict[str, Any], dict[str, Any]]:
@@ -53,8 +63,10 @@ class CustomProfile(ProviderProfile):
# disabled -> top-level reasoning_effort="none" (Ollama's /v1 ignores
# extra_body.think) plus think=False only on Ollama URLs; enabled+effort ->
# top-level reasoning_effort clamped to the OpenAI-compat wire (GLM/ARK,
- # vLLM and SGLang all top out at "max"; "ultra" verbatim 400s); enabled
- # without effort -> omit so the server default applies. Never emit
+ # vLLM and SGLang all top out at "max"; "ultra" verbatim 400s); None ->
+ # omit so the server default applies (auxiliary calls without an effort, and
+ # the main loop after the route rejected the reasoning field — an unset main
+ # effort arrives here already filled by default_reasoning_config). Never emit
# think=True (Ollama-only flag).
if reasoning_config and isinstance(reasoning_config, dict):
effort = (reasoning_config.get("effort") or "").strip().lower()
diff --git a/providers/base.py b/providers/base.py
index caba1ca9ddc..bc3d7338d41 100644
--- a/providers/base.py
+++ b/providers/base.py
@@ -203,6 +203,16 @@ class ProviderProfile:
"""
return {}
+ def default_reasoning_config(self, model: str | None = None) -> dict | None:
+ """Reasoning config the main loop sends when ``agent.reasoning_effort`` is unset.
+
+ None (default) hands the unset state to ``build_api_kwargs_extras`` as ``reasoning_config=None``,
+ where each profile already decides (Nous/OpenRouter fill medium; Anthropic omits). A profile
+ that would otherwise leave the route's own default in charge returns the config here so the
+ agent records it as what went on the wire (the reasoning-rejection ladder reads that).
+ """
+ return None
+
def build_api_kwargs_extras(
self,
*,
diff --git a/tests/agent/test_unset_reasoning_effort_default.py b/tests/agent/test_unset_reasoning_effort_default.py
new file mode 100644
index 00000000000..7cd65603c5a
--- /dev/null
+++ b/tests/agent/test_unset_reasoning_effort_default.py
@@ -0,0 +1,91 @@
+"""An unset ``agent.reasoning_effort`` resolves to ``medium`` on custom / OpenAI-compatible routes.
+
+The Nous, OpenRouter and AI Gateway profiles already fill medium when no effort is configured; the
+custom profile (``providers.<name>`` blocks, ``--provider custom``) omitted the field, so the
+endpoint's own default applied — for kimi-k3 that is ``max``: 3x the reasoning tokens and ~3x the
+latency of medium. The default is decided at request time in ``_reasoning_config_for_wire`` so the
+rejection ladder sees exactly what went out, and it never overrides an explicit effort.
+"""
+from unittest.mock import patch
+
+import pytest
+
+from agent.chat_completion_helpers import _build_api_kwargs_for_mode
+from agent.models_dev import ModelCapabilities
+from agent.transports.chat_completions import ChatCompletionsTransport
+from providers import get_provider_profile
+
+
+class _Agent:
+ """The attributes ``_build_api_kwargs_for_mode`` reads before handing off to the transport builder."""
+
+ def __init__(self, reasoning_config, *, provider="custom:relay", api_mode="chat_completions"):
+ self.reasoning_config = reasoning_config
+ self.provider = provider
+ self.model = "moonshotai/kimi-k3"
+ self.api_mode = api_mode
+ self.base_url = "http://relay.example/v1"
+ self.tools = []
+ self.request_overrides = None
+ self.service_tier = None
+ self._fast_until = 0.0
+ self._ephemeral_reasoning_off = False
+ self._reasoning_effort_rejected = False
+ self._reasoning_disable_rejected = False
+ self._ollama_num_ctx: int | None = None
+
+ def __getattr__(self, name):
+ return lambda *args, **kwargs: None
+
+
+def _wire_reasoning_config(agent):
+ """The ``reasoning_config`` the main loop hands the transport for this agent's next request."""
+ def _capture(agent, api_messages, tools_for_api, reasoning_config, request_overrides, cache_scope_id):
+ return {"reasoning_config": reasoning_config}
+
+ with patch("agent.chat_completion_helpers._build_chat_completions_kwargs", _capture):
+ return _build_api_kwargs_for_mode(agent, [], [])["reasoning_config"]
+
+
+def _custom_wire_field(reasoning_config):
+ kwargs = ChatCompletionsTransport().build_kwargs(
+ "moonshotai/kimi-k3", [{"role": "user", "content": "hi"}], tools=None,
+ provider_profile=get_provider_profile("custom:relay"), reasoning_config=reasoning_config,
+ base_url="http://relay.example/v1",
+ )
+ return kwargs.get("reasoning_effort")
+
+
+ "configured, expected_wire",
+ [(None, "medium"), ({"enabled": True, "effort": "low"}, "low"), ({"enabled": False}, "none")],
+)
+def test_unset_effort_goes_out_as_medium_and_explicit_efforts_are_untouched(configured, expected_wire):
+ agent = _Agent(configured)
+ with patch("agent.models_dev.get_model_capabilities", return_value=None):
+ sent = _wire_reasoning_config(agent)
+ assert _custom_wire_field(sent) == expected_wire
+ # The rejection ladder classifies the NEXT 400 from what was recorded as sent.
+ assert agent._wire_reasoning_config == sent
+
+
+def test_unset_effort_default_keeps_the_field_off_where_it_would_be_wrong():
+ # A model the catalog / model_overrides mark as non-reasoning.
+ with patch("agent.models_dev.get_model_capabilities", return_value=ModelCapabilities(supports_reasoning=False)):
+ assert _wire_reasoning_config(_Agent(None)) is None
+ with patch("agent.models_dev.get_model_capabilities", return_value=None):
+ # The route already rejected the reasoning field this session (#112781 ladder → route default).
+ rejected = _Agent(None)
+ rejected._reasoning_effort_rejected = True
+ assert _wire_reasoning_config(rejected) is None
+ # A local Ollama model pulled without the thinking capability 400s on reasoning_effort.
+ ollama = _Agent(None)
+ ollama._ollama_num_ctx = 8192
+ ollama._ollama_supports_thinking_cached = lambda: False
+ assert _wire_reasoning_config(ollama) is None
+ # Profiles that decide inside build_api_kwargs_extras (Nous fills medium itself) get None as before.
+ assert _wire_reasoning_config(_Agent(None, provider="nous")) is None
+ # Not a chat-completions wire: the Anthropic adapter's "unset = no thinking kwargs" stands.
+ from agent.reasoning_params import unset_reasoning_default
+ assert unset_reasoning_default(_Agent(None, api_mode="anthropic_messages")) is None
+
diff --git a/website/docs/integrations/providers.md b/website/docs/integrations/providers.md
index 36b02a3ab88..63664d476cb 100644
--- a/website/docs/integrations/providers.md
+++ b/website/docs/integrations/providers.md
@@ -1393,7 +1393,7 @@ Older configs used a top-level `custom_providers:` list instead. It still works
**Context window on `codex_responses` proxies.** A custom entry with `transport: codex_responses` (a local Codex proxy, for example) resolves the context window of Codex OAuth models (`gpt-6-astra`, `gpt-5.6-sol`/`-terra`/`-luna`, `gpt-5.5`, …) from the Codex OAuth table — 272K for most slugs — not from the 1.05M direct-API catalog, so compression fires before the Codex backend's limit and its 272K billing tier. The decision follows the transport, not the hostname; the same holds for `openai-codex` behind `HERMES_CODEX_BASE_URL` or `model.base_url`. A per-model `models.<id>.context_length`, an entry-level `context_length`, or `model.context_length` still wins; the opt-in `-900k` picker variants keep their verified 900K.
-**Reasoning effort on custom endpoints.** The configured `reasoning_effort` (`/reasoning max`, `agent.reasoning_effort`) reaches a custom endpoint unchanged on both the `chat_completions` and the `codex_responses` transport — up to `max`; only the Hermes-internal `ultra` is clamped to `max`. Two exceptions follow the host rather than the entry: a custom entry pointed at `api.openai.com` keeps OpenAI's per-model ladder (`max` is a gpt-5.6-only level there), and an entry pointed at a provider whose profile publishes a per-model vocabulary (Ramp Router) is clamped to that catalog. An endpoint that rejects the level answers with an HTTP 400 instead of Hermes silently downgrading it.
+**Reasoning effort on custom endpoints.** The configured `reasoning_effort` (`/reasoning max`, `agent.reasoning_effort`) reaches a custom endpoint unchanged on both the `chat_completions` and the `codex_responses` transport — up to `max`; only the Hermes-internal `ultra` is clamped to `max`. Two exceptions follow the host rather than the entry: a custom entry pointed at `api.openai.com` keeps OpenAI's per-model ladder (`max` is a gpt-5.6-only level there), and an entry pointed at a provider whose profile publishes a per-model vocabulary (Ramp Router) is clamped to that catalog. An endpoint that rejects the level answers with an HTTP 400 instead of Hermes silently downgrading it. When no effort is configured at all, `chat_completions` requests carry `reasoning_effort: medium` — the same default the Nous Portal and OpenRouter routes apply — rather than leaving the endpoint's own default in charge (kimi-k3's is `max`, about 3x the reasoning tokens of `medium`); models marked `supports_reasoning: false` in the catalog or `model_overrides`, and Ollama models without the `thinking` capability, keep the field off.
Some OpenAI-compatible endpoints need provider-specific request body fields. Add an `extra_body` map to the matching custom provider and Hermes will merge it into each chat-completions request for that endpoint:
diff --git a/website/docs/user-guide/configuration.md b/website/docs/user-guide/configuration.md
index c36d55a482d..a83f6f48dad 100644
--- a/website/docs/user-guide/configuration.md
+++ b/website/docs/user-guide/configuration.md
@@ -1916,7 +1916,7 @@ Model ids contain dots (`claude-opus-4.5`, `qwen3.6:27b`), which `hermes config
:::
:::note Local OpenAI-compatible endpoints
-A custom `base_url` (`http://localhost:11434/v1`, a vLLM, SGLang or router endpoint) receives the resolved effort — `agent.reasoning_effort` or the matching per-model override — as the standard top-level `reasoning_effort` request field, clamped to the values the OpenAI-compatible wire accepts (`none`, `minimal`, `low`, `medium`, `high`, `xhigh`, `max`). The nested `reasoning` object is reserved for endpoints known to accept it (Nous Portal, OpenRouter reasoning-capable models, GitHub Models) because arbitrary servers reject unknown fields with HTTP 400. If your server reads its thinking budget from a different field (Ollama's `think`, vLLM's `chat_template_kwargs`, a router-specific key), set it under the custom provider's [`extra_body`](../integrations/providers.md#named-custom-providers), which is merged into every request routed there.
+A custom `base_url` (`http://localhost:11434/v1`, a vLLM, SGLang or router endpoint) receives the resolved effort — `agent.reasoning_effort` or the matching per-model override — as the standard top-level `reasoning_effort` request field, clamped to the values the OpenAI-compatible wire accepts (`none`, `minimal`, `low`, `medium`, `high`, `xhigh`, `max`). An unset effort is sent as `medium` here too, the same default the Nous Portal and OpenRouter routes apply — leaving the field off would hand the choice to the endpoint, and a hosted reasoning model's own default can be its ceiling (kimi-k3 defaults to `max`: about 3x the reasoning tokens and latency of `medium`). The field stays off for a model the catalog or `model_overrides` mark `supports_reasoning: false`, for a local Ollama model pulled without the `thinking` capability, and for the rest of a session after the endpoint answered `400` to the field. The nested `reasoning` object is reserved for endpoints known to accept it (Nous Portal, OpenRouter reasoning-capable models, GitHub Models) because arbitrary servers reject unknown fields with HTTP 400. If your server reads its thinking budget from a different field (Ollama's `think`, vLLM's `chat_template_kwargs`, a router-specific key), set it under the custom provider's [`extra_body`](../integrations/providers.md#named-custom-providers), which is merged into every request routed there.
:::
**Resolution priority:**