Skip to content

feat: add transport types + migrate Anthropic normalize path#13347

Merged
teknium1 merged 1 commit into
mainfrom
hermes/hermes-a11c6da1
Apr 21, 2026
Merged

feat: add transport types + migrate Anthropic normalize path#13347
teknium1 merged 1 commit into
mainfrom
hermes/hermes-a11c6da1

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

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, Usage dataclasses + build_tool_call() / map_finish_reason() helpers
  • agent/anthropic_adapter.py: normalize_anthropic_response_v2() wrapping v1 into NormalizedResponse
  • run_agent.py L11375: Anthropic normalize branch now calls v2 + a temporary shim to SimpleNamespace (vanishes in PR 3)
  • Tests: 46 new (v1-vs-v2 regression across text, tools, thinking, mixed, stop reasons, mcp_ prefix, edge cases + dataclass/helper unit tests)

Validation

  • tests/agent/transports/ + tests/agent/test_anthropic_normalize_v2.py: 46/46 pass
  • tests/agent/ -k "anthropic or normalize": 235/235 pass
  • E2E parity check: v2+shim produces assistant_message byte-identical to v1 across thinking+text+tools, text-only, refusal, context-overflow, and unknown stop_reason paths. All downstream attribute reads (_build_assistant_message + L11428 thinking-prefill check reading reasoning_content) succeed.

Closes #13073

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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants