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.
func (*Model) RequiresToolsForRequired ¶ added in v0.10.0
RequiresToolsForRequired implements agent.ToolRules: Anthropic refuses tool choice "required" with no tools declared.
func (Model) String ¶ added in v0.7.0
String describes the adapter by its model id. It never includes the API key (or the base URL, which can carry credentials of its own), so a config that holds a *Model can be logged.
func (*Model) ToolNameRule ¶ added in v0.10.0
ToolNameRule implements agent.ToolRules: the tool names Anthropic accepts, `^[a-zA-Z0-9_-]{1,64}$`, so agent.New refuses any other name when the agent is built.
type Option ¶
type Option func(*Model)
Option configures a Model in New.
func WithBaseURL ¶
WithBaseURL sets the API host, for a proxy or a compatible endpoint; /v1/messages is appended to it. The default is "https://api.anthropic.com".
func WithHTTPClient ¶
WithHTTPClient sets the HTTP client requests are sent with. The default is http.DefaultClient.
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 ¶
WithMaxTokens sets the default limit on tokens in a reply; a request's Sampling.MaxTokens overrides it. The default is 4096 (Anthropic requires a limit on every request).
func WithModel ¶
WithModel sets the model ID sent with every request. The default is "claude-sonnet-4-6".
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.