anthropic

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package anthropic provides a model.Client implementation backed by the Anthropic Claude Messages API. It translates loom-mcp requests into anthropic.Message calls using github.com/anthropics/anthropic-sdk-go and maps responses (text, tools, thinking, usage) back into the generic planner structures.

Package anthropic wires Anthropic Claude model clients into loom-mcp planners.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client implements model.Client on top of Anthropic Claude Messages.

func New

func New(msg MessagesClient, opts Options) (*Client, error)

New builds an Anthropic-backed model client from the provided Anthropic Messages client and configuration options.

func NewFromAPIKey

func NewFromAPIKey(apiKey, defaultModel string) (*Client, error)

NewFromAPIKey constructs a client using the default Anthropic HTTP client. It reads ANTHROPIC_API_KEY and related defaults from the environment via sdk.DefaultClientOptions.

func (*Client) Complete

func (c *Client) Complete(ctx context.Context, req *model.Request) (*model.Response, error)

Complete issues a non-streaming Messages.New request and translates the response into planner-friendly structures (assistant messages + tool calls).

func (*Client) Stream

func (c *Client) Stream(ctx context.Context, req *model.Request) (model.Streamer, error)

Stream invokes Messages.NewStreaming and adapts incremental events into model.Chunks so planners can surface partial responses.

type MessagesClient

type MessagesClient interface {
	New(ctx context.Context, body sdk.MessageNewParams, opts ...option.RequestOption) (*sdk.Message, error)
	NewStreaming(ctx context.Context, body sdk.MessageNewParams, opts ...option.RequestOption) *ssestream.Stream[sdk.MessageStreamEventUnion]
}

MessagesClient captures the subset of the Anthropic SDK client used by the adapter. It is satisfied by *sdk.MessageService so callers can pass either a real client or a mock in tests.

type Options

type Options struct {
	// DefaultModel is the default Claude model identifier used when
	// model.Request.Model is empty. Use the typed model constants from
	// github.com/anthropics/anthropic-sdk-go (for example,
	// string(sdk.ModelClaudeSonnet4_5_20250929)) or the identifiers listed in
	// the Anthropic model reference in their docs/console.
	DefaultModel string

	// HighModel is the high-reasoning model identifier used when
	// model.Request.ModelClass is ModelClassHighReasoning and Model is empty.
	// As with DefaultModel, prefer the anthropic-sdk-go Model constants or the
	// IDs from Anthropic's model catalogue.
	HighModel string

	// SmallModel is the small/cheap model identifier used when
	// model.Request.ModelClass is ModelClassSmall and Model is empty. Source
	// identifiers from the anthropic-sdk-go Model constants or Anthropic's
	// model documentation.
	SmallModel string

	// MaxTokens sets the default completion cap when a request does not specify
	// MaxTokens. When zero or negative, the client requires callers to set
	// Request.MaxTokens explicitly.
	MaxTokens int

	// Temperature is used when a request does not specify Temperature.
	Temperature float64

	// ThinkingBudget defines the default thinking token budget when thinking is
	// enabled. When zero or negative, callers must supply
	// Request.Thinking.BudgetTokens explicitly.
	ThinkingBudget int64
}

Options configures optional Anthropic adapter behavior.

Jump to

Keyboard shortcuts

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