ReqLLM.Providers.Anthropic.AdapterHelpers (ReqLLM v1.14.0)

View Source

Shared helper functions for Anthropic model adapters (Bedrock, Vertex).

These functions are NOT used by the native Anthropic provider - they are specific to adapters that wrap Anthropic's API in other platforms.

Summary

Functions

Extract structured output from tool calls in response.

Extract stub tool definitions from messages when tools are needed but none provided.

Conditionally add a parameter to a map if the value is not nil.

Add extended thinking configuration to request body if enabled.

Prepare context and options for :object operations using structured output.

Functions

extract_and_set_object(response)

Extract structured output from tool calls in response.

Used for :object operations to get the final structured output.

extract_stub_tools_from_messages(body)

@spec extract_stub_tools_from_messages(map()) :: [map()]

Extract stub tool definitions from messages when tools are needed but none provided.

Bedrock and Azure are strict about tool validation in multi-turn conversations. If the conversation history contains tool_use or tool_result blocks, the API requires corresponding tool definitions. This function extracts tool names from the messages and creates minimal stub definitions.

maybe_add_param(body, key, value)

Conditionally add a parameter to a map if the value is not nil.

maybe_add_thinking(body, opts)

Add extended thinking configuration to request body if enabled.

Extended thinking doesn't work when tool_choice forces a specific tool. See: https://docs.claude.com/en/docs/build-with-claude/extended-thinking

prepare_structured_output_context(context, opts)

Prepare context and options for :object operations using structured output.

Creates a synthetic "structured_output" tool and forces tool choice to use it. This leverages Claude's tool-calling for structured JSON output.