Skip to content

The agent that grows with you

fix(auxiliary): wrap the Messages adapter on the profile's declared api_mode

kshitijk4pooraa40c1d21b22
diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.py
index af95c63b0a0..117c3e5fdae 100644
--- a/agent/auxiliary_client.py
+++ b/agent/auxiliary_client.py
@@ -4548,7 +4548,17 @@ def _wrap_transport(req: _ResolveRequest, client_obj: Any, final_model_str: str,
"(api_mode=%s, model=%s, base_url=%s)",
req.api_mode or "auto-detected", final_model_str, base_url_str[:60] if base_url_str else "")
return CodexAuxiliaryClient(client_obj, final_model_str)
- return _maybe_wrap_anthropic(client_obj, final_model_str, api_key_str, base_url_str, req.api_mode)
+ # A profile that declares the Messages wire (commandcode-anthropic) is on it whatever the URL
+ # looks like; the same declaration gates ``_reasoning_config`` in _build_call_kwargs.
+ api_mode = req.api_mode or _profile_declared_messages_wire(req.provider)
+ return _maybe_wrap_anthropic(client_obj, final_model_str, api_key_str, base_url_str, api_mode)
+
+
+def _profile_declared_messages_wire(provider: str) -> Optional[str]:
+ """``"anthropic_messages"`` when the registered profile declares that api_mode, else None."""
+ from providers import get_provider_profile
+ profile = get_provider_profile(str(provider or "").strip().lower())
+ return "anthropic_messages" if profile is not None and profile.api_mode == "anthropic_messages" else None
def _route_client(req: _ResolveRequest, client_obj: Any, final_model_str: Optional[str]) -> _ResolveResult:
@@ -6153,7 +6163,8 @@ def _build_call_kwargs(
# would reject; Portal Claude is dual-wire, so include it only when the catalog id selects
# /v1/messages. A profile declaring api_mode=anthropic_messages (commandcode-anthropic) is on
# that wire regardless of URL shape — once it overrides build_api_kwargs_extras the generic
- # ``extra_body.reasoning`` fallback the adapter used to read is gone, so this is its only path.
+ # ``extra_body.reasoning`` fallback the adapter used to read is gone, so this is the adapter's
+ # only path. _wrap_transport wraps such providers on the same declaration.
if reasoning_config and isinstance(reasoning_config, dict):
raw_base = base_url or ""
if (
diff --git a/tests/agent/test_auxiliary_client.py b/tests/agent/test_auxiliary_client.py
index c59bb8aa1c0..a8e09d8b870 100644
--- a/tests/agent/test_auxiliary_client.py
+++ b/tests/agent/test_auxiliary_client.py
@@ -2966,6 +2966,17 @@ class TestAnthropicAuxiliaryReasoningTranslation:
)
assert "_reasoning_config" not in chat_kwargs
+ def test_anthropic_messages_profile_resolves_to_messages_adapter(self, monkeypatch):
+ # Bare ``provider: commandcode-anthropic`` (no api_mode) must wrap the client on the
+ # profile's declared wire, or the ``_reasoning_config`` kwarg above would reach a plain
+ # OpenAI client and TypeError.
+ import model_tools # noqa: F401
+ from agent.auxiliary_client import AnthropicAuxiliaryClient, resolve_provider_client
+
+ monkeypatch.setenv("COMMANDCODE_API_KEY", "sk-test-" + "x" * 20)
+ client, _ = resolve_provider_client("commandcode-anthropic", model="claude-haiku-4-5-20251001")
+ assert isinstance(client, AnthropicAuxiliaryClient)
+
class TestAuxiliaryProviderProfileReasoning:
"""Auxiliary calls must reuse provider-profile reasoning wire shapes."""