feat: add transport types + migrate Anthropic normalize path#13347
Merged
Conversation
Add agent/transports/types.py with three shared dataclasses: - NormalizedResponse: content, tool_calls, finish_reason, reasoning, usage, provider_data - ToolCall: id, name, arguments, provider_data (per-tool-call protocol metadata) - Usage: prompt_tokens, completion_tokens, total_tokens, cached_tokens Add normalize_anthropic_response_v2() to anthropic_adapter.py — wraps the existing v1 function and maps its output to NormalizedResponse. One call site in run_agent.py (the main normalize branch) uses v2 with a back-compat shim to SimpleNamespace for downstream code. No ABC, no registry, no streaming, no client lifecycle. Those land in PR 3 with the first concrete transport (AnthropicTransport). 46 new tests: - test_types.py: dataclass construction, build_tool_call, map_finish_reason - test_anthropic_normalize_v2.py: v1-vs-v2 regression tests (text, tools, thinking, mixed, stop reasons, mcp prefix stripping, edge cases) Part of the provider transport refactor (PR 2 of 9).
This was referenced Apr 21, 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.
Step 2 of the 9-PR provider transport refactor. Adds shared normalized response types and migrates one real Anthropic normalize call site to use them, proving the shape before the ABC lands in PR 3.
Salvage of #13073 onto current main — @kshitijk4poor's authorship preserved via cherry-pick.
Changes
agent/transports/types.py:NormalizedResponse,ToolCall,Usagedataclasses +build_tool_call()/map_finish_reason()helpersagent/anthropic_adapter.py:normalize_anthropic_response_v2()wrapping v1 intoNormalizedResponserun_agent.pyL11375: Anthropic normalize branch now calls v2 + a temporary shim to SimpleNamespace (vanishes in PR 3)Validation
tests/agent/transports/+tests/agent/test_anthropic_normalize_v2.py: 46/46 passtests/agent/ -k "anthropic or normalize": 235/235 pass_build_assistant_message+ L11428 thinking-prefill check readingreasoning_content) succeed.Closes #13073