Help us shape the future of Go! Take the 2026 Go Developer Survey

anthropic

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 29, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

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 New

func New(apiKey string, opts ...Option) *Model

New constructs an Anthropic model adapter. apiKey is your Anthropic API key.

func (*Model) Stream

func (m *Model) Stream(ctx context.Context, req agent.Request) (*agent.Stream, error)

Stream implements agent.Model.

type Option

type Option func(*Model)

func WithBaseURL

func WithBaseURL(u string) Option

func WithHTTPClient

func WithHTTPClient(c *http.Client) Option

func WithMaxTokens

func WithMaxTokens(n int) Option

func WithModel

func WithModel(id string) Option

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 agent.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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL