From 738d0900fddd865c80379af742f4a79c3fa39125 Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Thu, 23 Apr 2026 13:39:44 +0530 Subject: [PATCH] refactor: migrate auxiliary_client Anthropic path to use transport MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace direct normalize_anthropic_response() call in _AnthropicCompletionsAdapter.create() with AnthropicTransport.normalize_response() via get_transport(). Before: auxiliary_client called adapter v1 directly, bypassing the transport layer entirely. After: auxiliary_client → get_transport('anthropic_messages') → transport.normalize_response() → adapter v1 → NormalizedResponse. The adapter v1 function (normalize_anthropic_response) now has zero callers outside agent/anthropic_adapter.py and the transport. This unblocks collapsing v1 to return NormalizedResponse directly in a follow-up (the remaining 2-layer chain becomes 1-layer). WS1 item 2 of Cycle 2 (#14418). --- agent/auxiliary_client.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.py index 4f8c9a0a4..f8fe50d89 100644 --- a/agent/auxiliary_client.py +++ b/agent/auxiliary_client.py @@ -573,7 +573,8 @@ class _AnthropicCompletionsAdapter: self._is_oauth = is_oauth def create(self, **kwargs) -> Any: - from agent.anthropic_adapter import build_anthropic_kwargs, normalize_anthropic_response + from agent.anthropic_adapter import build_anthropic_kwargs + from agent.transports import get_transport messages = kwargs.get("messages", []) model = kwargs.get("model", self._model) @@ -610,7 +611,28 @@ class _AnthropicCompletionsAdapter: anthropic_kwargs["temperature"] = temperature response = self._client.messages.create(**anthropic_kwargs) - assistant_message, finish_reason = normalize_anthropic_response(response) + _transport = get_transport("anthropic_messages") + _nr = _transport.normalize_response( + response, strip_tool_prefix=self._is_oauth + ) + + # Map NormalizedResponse → OpenAI-compatible SimpleNamespace + tool_calls = None + if _nr.tool_calls: + tool_calls = [ + SimpleNamespace( + id=tc.id, + type="function", + function=SimpleNamespace(name=tc.name, arguments=tc.arguments), + ) + for tc in _nr.tool_calls + ] + assistant_message = SimpleNamespace( + content=_nr.content, + tool_calls=tool_calls, + reasoning=_nr.reasoning, + ) + finish_reason = _nr.finish_reason usage = None if hasattr(response, "usage") and response.usage: