anthropic

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package anthropic is the provider-native Anthropic model adapter: the anti-corruption layer that is the ONLY package allowed to import github.com/anthropics/anthropic-sdk-go. It translates that SDK to and from agentcore types, so consumers (gyr, johnny, ...) never see a vendor type.

The adapter satisfies the llm.LLM port, so it plugs straight into jess.WithModel. It uses adaptive thinking + effort, and never sends temperature / top_p / top_k.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

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

Adapter wraps the Anthropic SDK client as an agentcore.ChatModel.

func New

func New(cfg Config) (*Adapter, error)

New builds an Adapter from config. It returns an error when the model id is empty (Anthropic requires it on every request).

func (*Adapter) Generate

func (a *Adapter) Generate(ctx context.Context, messages []agentcore.Message, tools []agentcore.ToolSpec, opts ...agentcore.CallOption) (*agentcore.LLMResponse, error)

Generate produces a synchronous response.

func (*Adapter) GenerateStream

func (a *Adapter) GenerateStream(ctx context.Context, messages []agentcore.Message, tools []agentcore.ToolSpec, opts ...agentcore.CallOption) (<-chan agentcore.StreamEvent, error)

GenerateStream produces a streaming response, emitting the agentcore StreamEvent sequence the agent loop expects: text/thinking start-delta-end, tool-call start/delta/end with the completed call, a terminal done event carrying the fully assembled message + stop reason, and an error event on provider failure.

The Anthropic Go stream has no GetFinalMessage; the message is reconstructed with Message.Accumulate. The fully assembled message is converted once at the end (via convertResponse), guaranteeing every tool_use block becomes an agentcore tool call in the done event — the load-bearing invariant.

func (*Adapter) ProviderName

func (a *Adapter) ProviderName() string

ProviderName implements agentcore.ProviderNamer.

func (*Adapter) SupportsTools

func (a *Adapter) SupportsTools() bool

SupportsTools reports that this provider supports tool calling.

type Config

type Config struct {
	APIKey  string
	Model   string
	BaseURL string
	// Meter, if set, receives token/latency Usage for every call.
	Meter llm.Meter
}

Config configures the adapter. APIKey and Model are required; BaseURL is optional (e.g. for a gateway).

Jump to

Keyboard shortcuts

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