Expand description
The Anthropic messages adapter (DW-075).
Speaks the Anthropic messages API (POST /v1/messages). The
translation is the deepest of the three dialects:
- System messages lift to the top-level
systemfield (joined with a blank line when several appear). - Tool RESULTS (OpenAI
role: toolmessages) become USER turns carrying atool_resultcontent block; assistant tool calls becometool_useblocks whoseinputis the parsed arguments object. max_tokensis REQUIRED by Anthropic and absent from many OpenAI client calls: the adapter substitutesDEFAULT_MAX_TOKENSand says so in the module docs — the provider refuses an unbounded generation, so a floor is the only way to honor the request at all.- Finish reasons map
end_turn/stop_sequence-> stop,max_tokens-> length,tool_use-> tool calls,refusal-> content filter. - Usage maps
input_tokens/output_tokensto prompt/completion;totalis derived (sum) because Anthropic does not send one.
Streaming (verified in tests, wired at the gateway in DW-077): the
messages-API SSE stream (message_start -> content_block_* ->
message_delta -> message_stop) translates event-by-event; tool
argument fragments arrive as input_json_delta.partial_json and
are re-expressed as OpenAI-style argument-fragment deltas.
Structs§
- Anthropic
Adapter - The Anthropic messages adapter. Stateless singleton.
Constants§
- DEFAULT_
MAX_ TOKENS - The
max_tokensthe adapter substitutes when the client did not send one. Anthropic requires the field; OpenAI clients usually omit it. 4096 is a conservative default that no provider rejects.