Documentation
¶
Overview ¶
Package anthropic adapts Anthropic's Messages API to agent.Model. It translates the provider-neutral []agent.Message/Part model to Anthropic content blocks (text, thinking+signature, tool_use, tool_result), declares tools, opens the SSE stream, and normalizes Anthropic's event types into agent's Event taxonomy. Zero external deps — net/http + stdlib.
Native Anthropic is exactly what Google ADK Go still lacks (#225/#1097); this is a wedge. Streaming tool-call args arrive as input_json_delta fragments — the canonical case the agent core's finalize() json.Valid gate handles.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
Model is an Anthropic Messages API adapter implementing agent.Model.
func (*Model) Describe ¶ added in v0.8.0
Describe reports the adapter's identity: provider "anthropic", the configured model ID, and no JSON-schema response format (a request that sets one fails with agent.ErrConfig).
func (Model) Format ¶ added in v0.7.0
Format writes String for every verb, so no fmt verb (%v, %+v, %#v, %s, %x, ...) prints the key.
type Option ¶
type Option func(*Model)
func WithBaseURL ¶
func WithHTTPClient ¶
func WithMaxResponseBytes ¶ added in v0.8.0
WithMaxResponseBytes caps how many bytes of one streamed reply the adapter reads: a reply that runs longer fails with agent.ErrResponseTooLarge, which middleware.Retryable does not retry. The default is provider.DefaultMaxResponseBytes (32 MiB); n <= 0 keeps it. Raise it for replies that legitimately run longer, such as large inline images.
func WithMaxTokens ¶
func WithPromptCache ¶
func WithPromptCache() Option
WithPromptCache turns on Anthropic prompt caching: cache_control breakpoints are placed on the system prompt and the tool definitions — the large, constant prefix an agent loop resends every turn — so repeat turns are billed at the cache-read rate. Cache hits/writes surface in agent.Usage (CacheReadTokens / CacheWriteTokens).
func WithToolResultCodec ¶ added in v0.2.0
func WithToolResultCodec(c provider.ToolResultCodec) Option
WithToolResultCodec encodes tool results sent to the model with c instead of raw JSON (for example GCF, to cut tokens on structured output). The journal keeps the JSON form; only what the model reads changes. Default is JSON.