feat: v1/messages support, part 2 (client): add native Anthropic v1/messages client - #2283
feat: v1/messages support, part 2 (client): add native Anthropic v1/messages client#2283RobGeada wants to merge 2 commits into
Conversation
Add an optional reasoning field to the ChatMessage dataclass so reasoning content survives round-tripping through to_dict/from_dict, and extract it from OpenAI-compatible responses via the 'reasoning' key in addition to 'reasoning_content'. Signed-off-by: Rob Geada <rob@geada.net>
PR merge guidance@RobGeada thanks for the PR. GitHub is currently blocking merge for one or more repository requirements:
Relevant guide: |
Signed-off-by: Rob Geada <rob@geada.net>
358b32a to
8f415a4
Compare
|
thanks, @RobGeada - a couple of comments that require follow-up:
|
| {"role": "assistant", "content": blocks if blocks else [{"type": "text", "text": ""}]} | ||
| ) | ||
|
|
||
| elif msg.role == Role.TOOL: |
There was a problem hiding this comment.
iiuc this parses every tool as its own user message. i think anthropic requires multiple tool results to be part of one consecutive user turn (https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview#handling-tool-use-and-tool-result-content-blocks)
| if response.headers: | ||
| provider_metadata["response_headers"] = dict(response.headers) | ||
| if thinking_blocks: | ||
| provider_metadata["thinking_blocks"] = thinking_blocks |
There was a problem hiding this comment.
if this is a multi-turn scenario, i think this would raise a 40x error on the Anthropic side. iiuc, Anthropic uses signatures in thinking blocks to keep track of multi-turn messages.
this line adds the signed thinking blocks to provider_metadata which the ChatMessage conversion drops so it never is passed onto the next prompt
There was a problem hiding this comment.
i would keep the signed blocks: LLMResponse.reasoning = thinking_blocks
| continue | ||
|
|
||
| if delta_type == "thinking_delta": | ||
| yield LLMResponseChunk(delta_reasoning=delta.get("thinking")) |
There was a problem hiding this comment.
we're also dropping signatures here
perhaps we can update this line to include content_block_start + thinking_delta + signature_delta
Description
This adds a native Anthropic client similar to the existing
openai_chat.py, which allows for native support ofv1/messagesAPIs for both inference and guardrail models.Changes:
Note: this depends on PR #2282 - only the second commit in this PR is net-new
Related Issue(s)
#2226
Verification
AI Assistance
Checklist