anthropic

package
v0.22.1 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: Apache-2.0 Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package anthropic is the ai.Provider on the official Anthropic SDK. It runs one streamed Messages request per turn, stores the response content blocks verbatim as the session's native history, and enables server-side compaction so the harness never has to rewrite earlier turns.

Index

Constants

View Source
const (
	// DefaultModel is used when the credential names none.
	DefaultModel = "claude-opus-5-5"
	// DefaultMaxTokens is the output cap when neither the options nor the
	// credential set one.
	DefaultMaxTokens = 16000
	// DefaultEffort is the reasoning effort when neither the options nor
	// the credential set one.
	DefaultEffort = "medium"
	// MemoryToolName is the tool name sent as the native memory tool.
	MemoryToolName = "memory"
)

Variables

This section is empty.

Functions

func Factory

func Factory(opts Options) ai.ProviderFactory

Factory returns an ai.ProviderFactory that builds providers with opts.

Types

type Options

type Options struct {
	// Effort is the reasoning effort (low, medium, high, xhigh, max). It
	// overrides the credential's ai_effort tag; empty means that tag or
	// DefaultEffort.
	Effort string
	// MaxTokens caps output tokens per turn; zero means the credential's
	// ai_max_output tag or DefaultMaxTokens.
	MaxTokens int
	// Fallbacks enables server-side refusal fallbacks (fallbacks: "default").
	Fallbacks bool
	// DisableCompaction turns off server-side compaction, which is on by
	// default. Without it a long session eventually overflows the window.
	DisableCompaction bool
	// HTTPClient replaces the SDK's default transport, for tests and proxies.
	HTTPClient *http.Client
	// Logger receives debug lines; nil is silent.
	Logger *logger.Logger
}

Options tunes the provider. The zero value is the recommended setup: medium effort, 16000 output tokens, compaction on, fallbacks off.

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

Provider is an ai.Provider for one credential.

func New

func New(cred ai.Credential, opts Options) (*Provider, error)

New builds a provider from a resolved model credential. The credential's Bearer is the API key, Endpoint (when set) the base URL, and Model the model id.

func (*Provider) Check

func (p *Provider) Check(ctx context.Context) (ai.CheckResult, error)

Check verifies the key, the endpoint, and the model by reading the model from the Models API. It sends no message, so it spends no tokens.

func (*Provider) Model

func (p *Provider) Model() string

Model returns the model id in use.

func (*Provider) Name

func (p *Provider) Name() string

Name returns "anthropic".

func (*Provider) ToolResultMessage

func (p *Provider) ToolResultMessage(results []ai.ToolResult) ai.Message

ToolResultMessage builds the user message carrying one tool_result block per result, in order. A denied or failed call is marked is_error so the model treats the text as a failure to recover from.

func (*Provider) Turn

func (p *Provider) Turn(ctx context.Context, in ai.TurnInput, emit func(ai.Event)) (*ai.Turn, error)

Turn streams one Messages request, emitting text, thinking, and compaction events as they arrive, and returns the accumulated assistant message with its content blocks stored verbatim.

func (*Provider) UserMessage

func (p *Provider) UserMessage(text string) ai.Message

UserMessage builds a user message holding one text block.

Jump to

Keyboard shortcuts

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