Skip to content

The agent that grows with you

fix(aux): parameter rungs hand a 429 on, and Fireworks gets top-level reasoning_effort

teknium17f03867523f6
diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.py
index 7816c3ad0b4..a7550e2a5fe 100644
--- a/agent/auxiliary_client.py
+++ b/agent/auxiliary_client.py
@@ -7019,8 +7019,11 @@ def _rung(step: "_LadderStep", accept: Callable[[Exception], bool]):
def _param_rung_accepts(exc: Exception) -> bool:
"""After a parameter-strip retry: fall through to the max_tokens/payment/auth
- chains with the stripped kwargs; re-raise anything those chains won't handle."""
+ chains with the stripped kwargs; re-raise anything those chains won't handle.
+ A 429 on the retry is the credential/provider-fallback rungs' job, so it falls
+ through too (the pre-ladder max_tokens rung accepted rate limits)."""
return (_is_payment_error(exc) or _is_connection_error(exc) or _is_auth_error(exc)
+ or _is_rate_limit_error(exc)
or "max_tokens" in str(exc) or "unsupported_parameter" in str(exc)
# Parameter rungs chain in any order (a reasoning-strip retry can 400 on temperature,
# a temperature-strip retry on max_tokens), and a route-gating 400 after a strip still
diff --git a/plugins/model-providers/fireworks/__init__.py b/plugins/model-providers/fireworks/__init__.py
index 3d57f99b630..4c0496bbd18 100644
--- a/plugins/model-providers/fireworks/__init__.py
+++ b/plugins/model-providers/fireworks/__init__.py
@@ -1,12 +1,32 @@
"""Fireworks AI provider profile. Models are addressed by full catalog ID
(``accounts/fireworks/models/<slug>``), tracking fw-ai/fireconnect ``setup-cli``."""
+from typing import Any
+
from hermes_cli import __version__ as _HERMES_VERSION
from providers import register_provider
from providers.base import ProviderProfile
-fireworks = ProviderProfile(
+class FireworksProfile(ProviderProfile):
+ """Map Hermes reasoning controls onto Fireworks' OpenAI-compatible wire."""
+
+ def build_api_kwargs_extras(
+ self, *, reasoning_config: dict | None = None, **context: Any
+ ) -> tuple[dict[str, Any], dict[str, Any]]:
+ # Fireworks rejects the nested ``extra_body.reasoning`` fallback some OpenAI-compatible
+ # gateways accept (#109774); its documented control is top-level ``reasoning_effort``
+ # (``none`` disables thinking). Overriding here marks the profile reasoning-aware, so the
+ # transport never sends the generic fallback on this route.
+ if not isinstance(reasoning_config, dict):
+ return {}, {}
+ if reasoning_config.get("enabled") is False:
+ return {}, {"reasoning_effort": "none"}
+ effort = reasoning_config.get("effort")
+ return {}, ({"reasoning_effort": effort} if effort else {})
+
+
+fireworks = FireworksProfile(
name="fireworks", aliases=("fireworks-ai", "fw"), display_name="Fireworks AI",
description="Fireworks AI — OpenAI-compatible direct model API",
signup_url="https://app.fireworks.ai/settings/users/api-keys", env_vars=("FIREWORKS_API_KEY",),
diff --git a/tests/agent/test_auxiliary_parameter_rung_chaining.py b/tests/agent/test_auxiliary_parameter_rung_chaining.py
index ee7dc44ef93..dd77fd1fa6e 100644
--- a/tests/agent/test_auxiliary_parameter_rung_chaining.py
+++ b/tests/agent/test_auxiliary_parameter_rung_chaining.py
@@ -78,3 +78,28 @@ def test_fallback_candidate_recovers_from_rejected_temperature():
assert resp.choices[0].message.content == "ok"
sent = [c.kwargs for c in client.chat.completions.create.call_args_list]
assert [("temperature" in k) for k in sent] == [True, False]
+
+
+def test_rate_limit_after_parameter_strip_falls_through_to_later_rungs():
+ """A 429 on the stripped retry belongs to the credential/provider-fallback rungs; the
+ parameter rungs must hand it on with the stripped kwargs, not raise out of the ladder."""
+ import httpx
+ import openai
+
+ request = httpx.Request("POST", "https://api.example/v1/chat/completions")
+ rate_limited = openai.RateLimitError(
+ "Error code: 429 - Rate limit exceeded", body=None,
+ response=httpx.Response(429, request=request, json={"error": {"message": "Rate limit exceeded"}}))
+ client = MagicMock(base_url="https://api.example/v1")
+ client.chat.completions.create.side_effect = rate_limited
+ route = _LadderRoute(**{**dict.fromkeys(_LadderRoute._fields), "client": client, "task": "title_generation",
+ "tag": "", "async_mode": False, "base_info": "", "resolved_provider": ""})
+ kwargs = {"model": "m", "messages": [], "max_tokens": 64}
+ first_err = _Bad400("Error code: 400 - Unsupported parameter: 'max_tokens' is not supported with this model.")
+
+ resp, err, final_kwargs = _drive_ladder(
+ _ladder_parameter_rungs(first_err, route, kwargs, 64),
+ lambda step: step.args[0].chat.completions.create(**step.args[1]))
+
+ assert resp is None and err is rate_limited
+ assert "max_tokens" not in final_kwargs
diff --git a/tests/plugins/model_providers/test_fireworks_profile.py b/tests/plugins/model_providers/test_fireworks_profile.py
index bf12649adce..cb12cbff86e 100644
--- a/tests/plugins/model_providers/test_fireworks_profile.py
+++ b/tests/plugins/model_providers/test_fireworks_profile.py
@@ -92,3 +92,31 @@ class TestFireworksModelDefaults:
assert model.startswith("accounts/fireworks/models/"), model
assert "/routers/" not in model
assert "turbo" not in model.lower(), model
+
+
+class TestFireworksReasoning:
+ @pytest.mark.parametrize(
+ "provider, reasoning_config, expect_top_level, expect_generic",
+ [
+ # Fireworks: thinking-off goes out as the documented top-level control, never as the
+ # nested ``extra_body.reasoning`` the API 400s on (#109774, salvaged from #109807).
+ ("fireworks", {"enabled": False}, {"reasoning_effort": "none"}, False),
+ ("fireworks", {"enabled": True, "effort": "low"}, {"reasoning_effort": "low"}, False),
+ # Control: a route without a reasoning-aware profile keeps the generic fallback.
+ ("unregistered-gateway", {"enabled": False}, {}, True),
+ ],
+ )
+ def test_auxiliary_reasoning_wire_shape(
+ self, fireworks_profile, provider, reasoning_config, expect_top_level, expect_generic
+ ):
+ from agent.auxiliary_client import _build_call_kwargs
+
+ kwargs = _build_call_kwargs(
+ provider, "accounts/fireworks/models/glm-5p2",
+ [{"role": "user", "content": "Generate a title"}],
+ reasoning_config=reasoning_config, base_url="https://api.fireworks.ai/inference/v1",
+ task="title_generation",
+ )
+
+ assert {k: v for k, v in kwargs.items() if k == "reasoning_effort"} == expect_top_level
+ assert ("reasoning" in kwargs.get("extra_body", {})) is expect_generic