Add the native Anthropic Messages client with recorded fixtures (N2 WP2) #26

Merged
weichen merged 1 commits from feature/n2-anthropic-wp2 into main 2026-10-07 13:22:41 +00:00
Owner

Why: acceptance clause 1 requires the anthropic preset to complete a tool-call round against recorded HTTP fixtures; audit N4 root cause was an offline body builder the real client never used, with no tool_use/thinking on the wire.

What:

  • runtime/llm/anthropic.go: native client — POST {base}/messages with x-api-key + anthropic-version, shared anthropicBody (BuildBody and the live client use one pack function), SSE parser for message_start/content_block_*/message_delta incl. thinking_delta/signature_delta/input_json_delta, stop_reason mapping.
  • Message.Thinking blocks (signature + redacted) round-trip on requests; system and last tool carry cache_control.
  • anthropic preset switches to ProtocolAnthropic (compat shim stays available via models.json); ClientFor implements the branch; audit N4 closes.
  • Recorded fixtures in runtime/llm/testdata/anthropic/ — no real keys, no network.

Evidence: GOWORK=off go vet + go test -count=1 ./... green; TestAnthropicPresetToolRound (acceptance ①) drives preset → tools request → tool_use → tool_result → final text with signature round-trip; OpenAI path untouched (Client.Protocol zero value, all direct constructions unaffected).

Impact: preset semantic change is intentional and recorded in the N2 card; no product code consumes Presets/Lookup (verified by grep).

Refs: Agent-System-Documents#42 (N2 plan WP2), audit N4

Why: acceptance clause 1 requires the anthropic preset to complete a tool-call round against recorded HTTP fixtures; audit N4 root cause was an offline body builder the real client never used, with no tool_use/thinking on the wire. What: - runtime/llm/anthropic.go: native client — POST {base}/messages with x-api-key + anthropic-version, shared anthropicBody (BuildBody and the live client use one pack function), SSE parser for message_start/content_block_*/message_delta incl. thinking_delta/signature_delta/input_json_delta, stop_reason mapping. - Message.Thinking blocks (signature + redacted) round-trip on requests; system and last tool carry cache_control. - anthropic preset switches to ProtocolAnthropic (compat shim stays available via models.json); ClientFor implements the branch; audit N4 closes. - Recorded fixtures in runtime/llm/testdata/anthropic/ — no real keys, no network. Evidence: GOWORK=off go vet + go test -count=1 ./... green; TestAnthropicPresetToolRound (acceptance ①) drives preset → tools request → tool_use → tool_result → final text with signature round-trip; OpenAI path untouched (Client.Protocol zero value, all direct constructions unaffected). Impact: preset semantic change is intentional and recorded in the N2 card; no product code consumes Presets/Lookup (verified by grep). Refs: Agent-System-Documents#42 (N2 plan WP2), audit N4
weichen added 1 commit 2026-10-07 13:21:33 +00:00
Add the native Anthropic Messages client with recorded fixtures (N2 WP2)
ci / vet-and-test (pull_request) Successful in 50s
ci / docker-checkout-hostgateway (pull_request) Successful in 1s
e63a9f38dd
Why: acceptance clause 1 requires the anthropic preset to complete a
tool-call round against recorded HTTP fixtures; audit N4's root cause
was an offline body builder the real client never used, with no
tool_use/thinking support on the wire.
Evidence: GOWORK=off go vet + go test -count=1 ./... green;
TestAnthropicPresetToolRound drives the preset through tools request →
tool_use → tool_result → final text with thinking-signature round-trip
against byte-recorded SSE fixtures; TestAnthropicBodyShape pins block
forms and cache_control; legacy OpenAI path untouched (Client.Protocol
zero value).
Impact: the anthropic preset now means the native Messages API (the
compat shim remains reachable via models.json custom providers); audit
N4 closes. BuildBody shares anthropicBody with the live client.
Refs: Agent-System-Documents#42 (N2 plan WP2), audit N4
weichen merged commit d6053baf4c into main 2026-10-07 13:22:41 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: weichen/Agent-Native#26