The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(copilot): one GitHub effort clamp for the profile and main agent
kshitijk4poord24aadfdd160
diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.pyindex c6e76c5749f..83c7fc16242 100644--- a/agent/auxiliary_client.py+++ b/agent/auxiliary_client.py@@ -1506,7 +1506,7 @@ class _CodexCompletionsAdapter:reasoning_cfg = extra_body.get("reasoning")if isinstance(reasoning_cfg, dict):# Shared per-model vocabulary with the main transport ("max" only where the model publishes it; "minimal"/"ultra"- # rejected; ``()`` = the model takes no ``reasoning`` field at all — gpt-4o/4.1 on api.openai.com,+ # clamp to a listed level; ``()`` = the model takes no ``reasoning`` field at all — gpt-4o/4.1 on api.openai.com,# #76255). ``enabled: False`` goes on the wire as ``effort: none`` where the vocabulary has it,# since an omitted field leaves the model's default effort on (#75227).from agent.reasoning_effort import clamp_effortdiff --git a/agent/reasoning_params.py b/agent/reasoning_params.pyindex 4fb54d5d827..3749faa67e4 100644--- a/agent/reasoning_params.py+++ b/agent/reasoning_params.py@@ -8,7 +8,6 @@ import timefrom agent.lazy_forward import forward as _forward, forward_static as _forward_staticfrom agent.message_sanitization import matches_reasoning_echo_family-from agent.reasoning_effort import clamp_effortfrom utils import base_url_host_matches# Static OpenRouter fallback when the live /v1/models capability cache is cold.@@ -140,7 +139,7 @@ class ReasoningParamsMixin:def _github_models_reasoning_extra_body(self) -> dict | None:"""Format reasoning payload for GitHub Models/OpenAI-compatible routes."""try:- from hermes_cli.models import github_model_reasoning_efforts+ from hermes_cli.models import clamp_github_reasoning_effort, github_model_reasoning_effortsexcept Exception:return None@@ -151,13 +150,7 @@ class ReasoningParamsMixin:cfg = self.reasoning_config if isinstance(self.reasoning_config, dict) else {}if cfg.get("enabled") is False:return None- effort = str(cfg.get("effort", "medium")).strip().lower()-- if effort not in supported:- effort = clamp_effort(effort, supported)- if effort not in supported:- effort = "medium" if "medium" in supported else supported[0]- return {"effort": effort}+ return {"effort": clamp_github_reasoning_effort(cfg.get("effort"), supported)}_build_assistant_message = _forward("agent.chat_completion_helpers", "build_assistant_message")diff --git a/agent/transports/codex.py b/agent/transports/codex.pyindex ab2f0e10158..89a889fc03f 100644--- a/agent/transports/codex.py+++ b/agent/transports/codex.py@@ -14,7 +14,7 @@ from agent.reasoning_effort import (CODEX_ASTRA_EFFORTS, CODEX_LEGACY_EFFORTS,XAI_GROK46_EFFORTS, XAI_LEGACY_EFFORTS, clamp_effort, is_astra_model,# Same declared vocabulary + shared clamp as the main Codex transport (agent.reasoning_effort):- # per-model — "max" availability varies; "minimal"/"ultra" require wire translation.+ # per-model — "max" availability varies; "minimal"/"ultra" clamp to a listed level.codex_supported_efforts,)from agent.transports.base import ProviderTransportdiff --git a/hermes_cli/models.py b/hermes_cli/models.pyindex 31615e63430..830c798a3e9 100644--- a/hermes_cli/models.py+++ b/hermes_cli/models.py@@ -545,6 +545,18 @@ def clamp_reasoning_effort_to_supported(return _clamp_effort(effort, supported_efforts)+def clamp_github_reasoning_effort(effort: Any, supported: list[str]) -> str:+ """Copilot/GitHub Models effort for a non-empty *supported* list: the level itself when listed,+ else the nearest WEAKER listed level; bespoke names the ladder can't place fall to ``medium``+ (or the first listed level)."""+ effort = str(effort or "medium").strip().lower()+ if effort not in supported:+ effort = _clamp_effort(effort, supported)+ if effort not in supported:+ effort = "medium" if "medium" in supported else supported[0]+ return effort++def _fetch_live_catalog_index(url: str, timeout: float, opener) -> Optional[tuple[list, dict[str, dict[str, Any]]]]:"""GET an OpenAI-style ``/models`` listing → ``(raw data array, {id: item})``, or None when theendpoint is unreachable or the payload has no ``data`` list."""diff --git a/plugins/model-providers/copilot/__init__.py b/plugins/model-providers/copilot/__init__.pyindex 98e9c54431c..745ee4a2814 100644--- a/plugins/model-providers/copilot/__init__.py+++ b/plugins/model-providers/copilot/__init__.py@@ -21,22 +21,15 @@ class CopilotProfile(ProviderProfile):if not (supports_reasoning and model):return {}, {}try:- from hermes_cli.models import clamp_reasoning_effort_to_supported, github_model_reasoning_efforts+ from hermes_cli.models import clamp_github_reasoning_effort, github_model_reasoning_effortssupported = github_model_reasoning_efforts(model)if not supported:return {}, {}if not reasoning_config:return {"reasoning": {"effort": "medium"}}, {}- effort = reasoning_config.get("effort", "medium")- # Honor a level the live catalog lists; otherwise clamp to the nearest WEAKER- # supported level (never drop straight to medium, which inverted the ladder:- # ultra < high). Bespoke levels the ladder can't place fall to medium (or [0]).- # See #74295.- if effort not in supported:- effort = clamp_reasoning_effort_to_supported(effort, list(supported))- if effort not in supported:- effort = "medium" if "medium" in supported else supported[0]+ # Never drop straight to medium, which inverted the ladder (ultra < high). See #74295.+ effort = clamp_github_reasoning_effort(reasoning_config.get("effort"), supported)return {"reasoning": {"effort": effort}}, {}except Exception:return {}, {}diff --git a/tests/agent/transports/test_codex_transport.py b/tests/agent/transports/test_codex_transport.pyindex e3eb50040f9..64c1efc0092 100644--- a/tests/agent/transports/test_codex_transport.py+++ b/tests/agent/transports/test_codex_transport.py@@ -43,13 +43,9 @@ class TestCodexBuildKwargs:])def test_astra_copilot_forwards_configured_reasoning(self, transport, model, effort, expected):from agent.reasoning_params import ReasoningParamsMixin- from hermes_cli.config import get_config_path, load_configfrom hermes_constants import resolve_reasoning_config- get_config_path().write_text(json.dumps({- "model": {"default": model}, "agent": {"reasoning_effort": effort},- }), encoding="utf-8")- reasoning = resolve_reasoning_config(load_config(), model)+ reasoning = resolve_reasoning_config({"agent": {"reasoning_effort": effort}}, model)agent = SimpleNamespace(model=model, reasoning_config=reasoning)kw = transport.build_kwargs(model=model, messages=[{"role": "user", "content": "Hi"}],@@ -59,16 +55,6 @@ class TestCodexBuildKwargs:)assert kw.get("reasoning") == ({"effort": expected} if expected else None)- @pytest.mark.parametrize("model, expected", [- ("gpt-6-astra", ["low", "medium", "high", "xhigh", "max"]),- ("openai/gpt-6-astra", ["low", "medium", "high", "xhigh", "max"]),- ("gpt-6-astra-pro", []), # speed-tier / unknown suffixes stay off the Astra ladder- ])- def test_copilot_offline_astra_efforts_use_exact_slug(self, model, expected):- from hermes_cli.models import github_model_reasoning_efforts-- assert github_model_reasoning_efforts(model, catalog=[]) == expected-def test_astra_direct_request_applies_model_contract_after_overrides(self, transport):kw = transport.build_kwargs(model="gpt-6-astra",diff --git a/tests/plugins/model_providers/test_copilot_profile.py b/tests/plugins/model_providers/test_copilot_profile.pyindex bf1d3fc01b9..67d994acb67 100644--- a/tests/plugins/model_providers/test_copilot_profile.py+++ b/tests/plugins/model_providers/test_copilot_profile.py@@ -8,7 +8,7 @@ unconditionally collapsing ``xhigh`` to ``high`` (which silently capped modelsthat actually support the higher level).These tests pin that contract without going live, by stubbing the catalog-lookup ``github_model_reasoning_efforts``.+lookup ``github_model_reasoning_efforts`` or passing it an explicit ``catalog=``."""from __future__ import annotations@@ -34,7 +34,7 @@ def copilot_profile():def _patch_efforts(monkeypatch, efforts):- """Stub the catalog lookup the profile calls for supported efforts."""+ """Stub the catalog lookup the profile and main-agent path call for supported efforts."""import hermes_cli.models as models_modmonkeypatch.setattr(models_mod, "github_model_reasoning_efforts", lambda model: list(efforts)@@ -100,3 +100,41 @@ class TestCopilotReasoningEffortClamp:supports_reasoning=True,)assert extra_body["reasoning"] == {"effort": "low"}+++class TestCopilotOfflineAstraEfforts:+ """With no live catalog entry, Astra still advertises its own ladder (exact slugs only),+ and a structured catalog entry keeps precedence over the offline fallback."""++ @pytest.mark.parametrize("model, expected", [+ ("gpt-6-astra", ["low", "medium", "high", "xhigh", "max"]),+ ("openai/gpt-6-astra", ["low", "medium", "high", "xhigh", "max"]),+ ("gpt-6-astra-pro", []), # speed-tier / unknown suffixes stay off the Astra ladder+ ])+ def test_offline_fallback_uses_exact_astra_slugs(self, model, expected):+ from hermes_cli.models import github_model_reasoning_efforts++ assert github_model_reasoning_efforts(model, catalog=[]) == expected++ def test_structured_catalog_beats_offline_fallback(self):+ from hermes_cli.models import github_model_reasoning_efforts++ catalog = [{"id": "gpt-6-astra", "capabilities": {+ "type": "chat", "supports": {"reasoning_effort": ["low", "high"]}}}]+ assert github_model_reasoning_efforts("gpt-6-astra", catalog=catalog) == ["low", "high"]++[email protected]("effort, expected", [+ ("xhigh", "high"), ("max", "high"), ("ultra", "high"), ("minimal", "minimal"),+ ("garbage", "medium"), (" HIGH ", "high"),+])+def test_main_agent_github_clamp_never_escalates(monkeypatch, effort, expected):+ """The main-agent GitHub path shares the profile's clamp: unsupported levels step down to+ the nearest weaker listed one (max/ultra no longer fall all the way to medium)."""+ from types import SimpleNamespace++ from agent.reasoning_params import ReasoningParamsMixin++ _patch_efforts(monkeypatch, ["minimal", "low", "medium", "high"])+ agent = SimpleNamespace(model="gpt-5.4", reasoning_config={"enabled": True, "effort": effort})+ assert ReasoningParamsMixin._github_models_reasoning_extra_body(agent) == {"effort": expected}