feat: add transport ABC + AnthropicTransport wired to all paths#13366
Merged
Conversation
Add ProviderTransport ABC (4 abstract methods: convert_messages, convert_tools, build_kwargs, normalize_response) plus optional hooks (validate_response, extract_cache_stats, map_finish_reason). Add transport registry with lazy discovery — get_transport() auto-imports transport modules on first call. Add AnthropicTransport — delegates to existing anthropic_adapter.py functions, wired to ALL Anthropic code paths in run_agent.py: - Main normalize loop (L10775) - Main build_kwargs (L6673) - Response validation (L9366) - Finish reason mapping (L9534) - Cache stats extraction (L9827) - Truncation normalize (L9565) - Memory flush build_kwargs + normalize (L7363, L7395) - Iteration-limit summary + retry (L8465, L8498) Zero direct adapter imports remain for transport methods. Client lifecycle, streaming, auth, and credential management stay on AIAgent. 20 new tests (ABC contract, registry, AnthropicTransport methods). 359 anthropic-related tests pass (0 failures). PR 3 of the provider transport refactor.
dd68325 to
d763086
Compare
This was referenced Apr 21, 2026
This was referenced May 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PR 3 of the provider transport refactor (PR 1: #12975, PR 2: #13073).
Adds the ProviderTransport ABC and the first concrete transport (AnthropicTransport), wired to all Anthropic code paths in run_agent.py. When this merges, every Anthropic format-conversion and normalization call goes through the transport — no dead code, no dormant abstraction.
What ships
agent/transports/base.py— ProviderTransport ABCconvert_messages,convert_tools,build_kwargs,normalize_responsevalidate_response,extract_cache_stats,map_finish_reasonagent/transports/__init__.py— Transport registryregister_transport(api_mode, cls)/get_transport(api_mode)_discover_transports()auto-imports transport modules on first callagent/transports/anthropic.py— AnthropicTransportanthropic_adapter.pyfunctions — zero duplicated logicregister_transport('anthropic_messages', ...)run_agent.py— All Anthropic paths wired (9 sites):normalize_response()build_kwargs()validate_response()map_finish_reason()extract_cache_stats()normalize_response()build_kwargs()+normalize_response()build_kwargs()+normalize_response()Zero direct adapter imports remain for transport methods. Client lifecycle, streaming, auth stay on AIAgent.
What stays on agent (explicitly NOT in the transport)
build_anthropic_client) — 9 sites_anthropic_messages_create) — 3 sites_call_anthropic) — 1 siteTest plan