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
- func Factory(opts Options) ai.ProviderFactory
- type Options
- type Provider
- func (p *Provider) Check(ctx context.Context) (ai.CheckResult, error)
- func (p *Provider) Model() string
- func (p *Provider) Name() string
- func (p *Provider) ToolResultMessage(results []ai.ToolResult) ai.Message
- func (p *Provider) Turn(ctx context.Context, in ai.TurnInput, emit func(ai.Event)) (*ai.Turn, error)
- func (p *Provider) UserMessage(text string) ai.Message
Constants ¶
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 ¶
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) 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.