adk_llm_anthropic_content (erlang_adk v0.8.0)

View Source

Checked translation between provider-neutral ADK content/history and Anthropic Messages API content blocks.

Anthropic tool results refer to a previous tool call by tool_use_id. The provider-neutral function response therefore must carry its original id; refusing an id-less replay is safer than manufacturing an uncorrelated id.

Summary

Functions

Decode an API error without retaining the remote message. Validation errors can quote request values, so only status, bounded type and request id cross this boundary.

Decode a successful Messages response. Generation accounting is kept in the ordinary checked provider-result envelope; prompt/response content is never copied into metadata.

Return the top-level system prompt (or undefined) and chronological Anthropic user/assistant messages. Consecutive ADK tool messages are grouped into one Anthropic user turn containing only tool_result blocks.

Project bounded non-content response metadata.

Functions

decode(Blocks, LimitOverrides)

-spec decode(term(), map()) -> {ok, adk_content:content()} | {error, term()}.

decode_error(Response)

-spec decode_error(binary() | map()) -> {error, term()}.

decode_error(Status, Body)

-spec decode_error(undefined | non_neg_integer(), binary() | map()) -> {error, term()}.

Decode an API error without retaining the remote message. Validation errors can quote request values, so only status, bounded type and request id cross this boundary.

decode_response(Body, LimitOverrides)

-spec decode_response(binary() | map(), map()) -> term().

Decode a successful Messages response. Generation accounting is kept in the ordinary checked provider-result envelope; prompt/response content is never copied into metadata.

encode(Role, Content, LimitOverrides)

-spec encode(user | assistant | tool, term(), map()) -> {ok, [map()]} | {error, term()}.

encode_history(History, LimitOverrides)

-spec encode_history(term(), map()) -> {ok, undefined | binary(), [map()]} | {error, term()}.

Return the top-level system prompt (or undefined) and chronological Anthropic user/assistant messages. Consecutive ADK tool messages are grouped into one Anthropic user turn containing only tool_result blocks.

metadata(Response)

-spec metadata(map()) -> {ok, map()} | {error, term()}.

Project bounded non-content response metadata.

outcome(Content)

-spec outcome(adk_content:content()) ->
                 {ok, binary() | adk_content:content()} | {tool_calls, list()} | {error, term()}.

part_types(Content)

-spec part_types(adk_content:content()) -> [binary()].

text_parts(Content)

-spec text_parts(adk_content:content()) -> [binary()].

tool_calls(Content)

-spec tool_calls(adk_content:content()) -> list().