Skip to content

The agent that grows with you

refactor(model-providers): tighten router/openrouter bodies, drop __future__ annotations (py>=3.11)

Teknium48da3172114c
diff --git a/plugins/model-providers/actual/__init__.py b/plugins/model-providers/actual/__init__.py
index 8506eece8b3..03a3a500c8f 100644
--- a/plugins/model-providers/actual/__init__.py
+++ b/plugins/model-providers/actual/__init__.py
@@ -1,7 +1,5 @@
"""Actual Computer provider profile."""
-from __future__ import annotations
-
import os
from providers import register_provider
diff --git a/plugins/model-providers/commandcode/__init__.py b/plugins/model-providers/commandcode/__init__.py
index 4346b096e26..cf031c68137 100644
--- a/plugins/model-providers/commandcode/__init__.py
+++ b/plugins/model-providers/commandcode/__init__.py
@@ -2,8 +2,6 @@
``commandcode-anthropic`` (anthropic_messages, Bearer auth — see
``agent/anthropic_adapter.py``). Same key and base URL for both."""
-from __future__ import annotations
-
import json
import logging
import urllib.request
diff --git a/plugins/model-providers/deepseek/__init__.py b/plugins/model-providers/deepseek/__init__.py
index 6d175375f38..27e49dc6233 100644
--- a/plugins/model-providers/deepseek/__init__.py
+++ b/plugins/model-providers/deepseek/__init__.py
@@ -8,8 +8,6 @@ Retired ``deepseek-chat``/``deepseek-reasoner`` IDs are remapped in
``hermes_cli.model_normalize`` before reaching here.
"""
-from __future__ import annotations
-
from typing import Any
from agent.reasoning_effort import DEEPSEEK_V4_EFFORTS, DEEPSEEK_V4_OVERRIDES, clamp_effort
diff --git a/plugins/model-providers/meta-ai/__init__.py b/plugins/model-providers/meta-ai/__init__.py
index 8cddbbb43e7..fcef99fc253 100644
--- a/plugins/model-providers/meta-ai/__init__.py
+++ b/plugins/model-providers/meta-ai/__init__.py
@@ -6,8 +6,6 @@ top-level ``reasoning_effort`` kwarg — not ``extra_body.reasoning``, whose
emission is gated by a core host allowlist a third-party plugin must not edit.
"""
-from __future__ import annotations
-
import os
from typing import Any
diff --git a/plugins/model-providers/nebius-token-factory/__init__.py b/plugins/model-providers/nebius-token-factory/__init__.py
index 74794c0bf0a..5eac7288835 100644
--- a/plugins/model-providers/nebius-token-factory/__init__.py
+++ b/plugins/model-providers/nebius-token-factory/__init__.py
@@ -1,7 +1,5 @@
"""Nebius Token Factory provider profile."""
-from __future__ import annotations
-
from typing import Any
from agent.reasoning_effort import NEBIUS_EFFORTS, clamp_effort
diff --git a/plugins/model-providers/ollama-cloud/__init__.py b/plugins/model-providers/ollama-cloud/__init__.py
index 9218d54c1a4..5418e193343 100644
--- a/plugins/model-providers/ollama-cloud/__init__.py
+++ b/plugins/model-providers/ollama-cloud/__init__.py
@@ -5,8 +5,6 @@ high|max (``max`` is undocumented but real — ~2.5x more thinking tokens on
DeepSeek V4); Hermes' ``xhigh`` maps to ``max``.
"""
-from __future__ import annotations
-
from typing import Any
from agent.reasoning_effort import OLLAMA_CLOUD_EFFORTS, OLLAMA_CLOUD_OVERRIDES, clamp_effort
diff --git a/plugins/model-providers/opencode-zen/__init__.py b/plugins/model-providers/opencode-zen/__init__.py
index a94bbca85a7..28aacf59560 100644
--- a/plugins/model-providers/opencode-zen/__init__.py
+++ b/plugins/model-providers/opencode-zen/__init__.py
@@ -4,8 +4,6 @@ Both route api_mode per model in core; these profiles carry the
chat_completions reasoning translations (GLM-5.2, Kimi K2, DeepSeek, Ox Alpha).
"""
-from __future__ import annotations
-
from typing import Any
from agent import reasoning_effort as re_
diff --git a/plugins/model-providers/openrouter/__init__.py b/plugins/model-providers/openrouter/__init__.py
index 580b999184d..391167b4090 100644
--- a/plugins/model-providers/openrouter/__init__.py
+++ b/plugins/model-providers/openrouter/__init__.py
@@ -63,8 +63,7 @@ class OpenRouterProfile(ProviderProfile):
return cfg
if clamped and clamped != effort:
logger.debug(
- "openrouter: clamped reasoning effort %r → %r for %s "
- "(catalog supported_efforts=%s)",
+ "openrouter: clamped reasoning effort %r → %r for %s (catalog supported_efforts=%s)",
effort, clamped, model, caps.get("supported_efforts"),
)
cfg = {**cfg, "effort": clamped}
@@ -109,13 +108,8 @@ class OpenRouterProfile(ProviderProfile):
return body
def build_api_kwargs_extras(
- self,
- *,
- reasoning_config: dict | None = None,
- supports_reasoning: bool = False,
- model: str | None = None,
- session_id: str | None = None,
- **context: Any,
+ self, *, reasoning_config: dict | None = None, supports_reasoning: bool = False,
+ model: str | None = None, session_id: str | None = None, **context: Any,
) -> tuple[dict[str, Any], dict[str, Any]]:
"""Pass reasoning_config as extra_body.reasoning; pin Grok's cache via x-grok-conv-id."""
extra_body: dict[str, Any] = {}
diff --git a/plugins/model-providers/router/__init__.py b/plugins/model-providers/router/__init__.py
index 35a4d1dd8a5..1c485e8d029 100644
--- a/plugins/model-providers/router/__init__.py
+++ b/plugins/model-providers/router/__init__.py
@@ -1,16 +1,13 @@
-"""Ramp Router (router.com) provider profile: Responses-only LLM gateway.
-
-Wire notes (verified live): the Responses API is the native wire (``api_mode=
-"codex_responses"`` + the ``api.router.com`` host mandate in ``hermes_cli/providers.py``);
-the catalog is account-scoped so there are no ``fallback_models`` (picker uses
-``fetch_models()``); Router 400s on ``reasoning.effort`` levels outside a model's
-published vocabulary and on any reasoning field for non-reasoning models, so the
-efforts map from ``GET /v1/models`` is cached (memory + disk mirror, background
-warmer; never HTTP on the request hot path) and fed to the codex transport's clamp.
+"""Ramp Router (router.com) provider profile: Responses-only LLM gateway (verified live).
+
+``api_mode="codex_responses"`` + the ``api.router.com`` host mandate in ``hermes_cli/providers.py``
+keep every path on the native wire. The catalog is account-scoped, so no ``fallback_models``
+(picker uses ``fetch_models()``). Router 400s on ``reasoning.effort`` levels outside a model's
+published vocabulary and on any reasoning field for non-reasoning models, so the efforts map
+from ``GET /v1/models`` is cached (memory + disk mirror, background warmer; never HTTP on the
+request hot path) and fed to the codex transport's clamp via ``supported_reasoning_efforts``.
"""
-from __future__ import annotations
-
import json
import logging
import os
@@ -92,10 +89,8 @@ def _parse_efforts(items: Any) -> Optional[dict[str, list[str]]]:
unknown = [level for level in levels if level not in EFFORT_LADDER]
if unknown:
logger.info(
- "router: model %s publishes unrecognized reasoning effort "
- "level(s) %s; ignoring them (update agent/reasoning_effort "
- "EFFORT_LADDER to adopt new vendor tiers)",
- mid, unknown,
+ "router: model %s publishes unrecognized reasoning effort level(s) %s; ignoring them "
+ "(update agent/reasoning_effort EFFORT_LADDER to adopt new vendor tiers)", mid, unknown,
)
levels = [level for level in levels if level in EFFORT_LADDER]
if levels:
@@ -106,7 +101,6 @@ def _parse_efforts(items: Any) -> Optional[dict[str, list[str]]]:
def _disk_path() -> Optional[Path]:
try:
from hermes_constants import get_hermes_home
-
return get_hermes_home() / "cache" / "router_catalog.json"
except Exception:
return None
@@ -190,9 +184,7 @@ def _efforts_cache_only() -> Optional[dict[str, list[str]]]:
if parsed is None:
return None
with _efforts_lock:
- if _efforts_cache is None:
- _efforts_cache = parsed
- cached = _efforts_cache
+ _efforts_cache = cached = _efforts_cache if _efforts_cache is not None else parsed
if age >= _DISK_TTL_SECONDS:
_warm_efforts_async()
return cached
@@ -218,7 +210,6 @@ def _warm_efforts_async() -> None:
items = _fetch_catalog_items()
if items is not None:
_seed_efforts(items)
-
try:
threading.Thread(target=_refresh, name="router-caps-warm", daemon=True).start()
except Exception as exc:
@@ -237,8 +228,7 @@ class RouterProfile(ProviderProfile):
if items is None:
return None
_seed_efforts(items)
- ids = list(dict.fromkeys(str(i["id"]) for i in items if isinstance(i, dict) and i.get("id")))
- return ids or None
+ return list(dict.fromkeys(str(i["id"]) for i in items if isinstance(i, dict) and i.get("id"))) or None
def supported_reasoning_efforts(self, model: Optional[str]) -> Optional[tuple[str, ...]]:
"""Catalog-declared effort vocabulary (cache-only; cold cache -> None + warm)."""
@@ -249,7 +239,7 @@ class RouterProfile(ProviderProfile):
if efforts_by_id is None:
_warm_efforts_async()
return None
- return None if mid not in efforts_by_id else tuple(efforts_by_id[mid])
+ return tuple(efforts_by_id[mid]) if mid in efforts_by_id else None
router = RouterProfile(
diff --git a/plugins/model-providers/zai/__init__.py b/plugins/model-providers/zai/__init__.py
index 482a11866d2..f27cfa0f691 100644
--- a/plugins/model-providers/zai/__init__.py
+++ b/plugins/model-providers/zai/__init__.py
@@ -4,8 +4,6 @@ GLM-4.5+ defaults to thinking ON, so ``reasoning_config`` is translated to
``extra_body.thinking``; GLM-5.2/5.3 also take a native ``reasoning_effort``.
"""
-from __future__ import annotations
-
import re
from typing import Any