anthropicmessages

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Overview

Package anthropicmessages provides shared Anthropic Messages protocol execution.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoCacheEvidence = errors.New("anthropic: cache residency is not proven")
	ErrTargetNotFound  = errors.New("anthropic: cache target not found")
)

Functions

func ModelCapabilities

func ModelCapabilities(model string) lipapi.BackendCaps

ModelCapabilities returns negotiated backend caps for a resolved Anthropic model id. Rules are intentionally small; expand as catalog data grows.

func NewBackend

func NewBackend(cfg Config) execbackend.Backend

func ParamsForCall

func ParamsForCall(call *lipapi.Call, cand routing.AttemptCandidate) (anthropic.MessageNewParams, error)

ParamsForCall builds an Anthropic message create payload from a canonical call using the default Anthropic behavior (no role normalization, no model normalization). It is retained for callers and tests that exercise the shared protocol directly; the runtime path uses paramsForCall.

func ReplaySupport

func ReplaySupport() lipapi.ReasoningReplaySupport

ReplaySupport is the static historical-reasoning dialect profile for Anthropic Messages.

Types

type CacheController

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

func NewCacheController

func NewCacheController(cfg CacheControllerConfig) (*CacheController, error)

func (*CacheController) IssueTarget

func (c *CacheController) IssueTarget(target CacheTarget, observedAt time.Time) (promptcache.Observation, error)

func (*CacheController) Release

func (*CacheController) Renew

func (*CacheController) TargetCount

func (c *CacheController) TargetCount() int

type CacheControllerConfig

type CacheControllerConfig struct {
	BaseURL        string
	APIKey         string
	HTTPClient     *http.Client
	ResolveAPIKey  func(context.Context, CacheTarget) (string, error)
	MaxTargetBytes int
}

type CacheObservation

type CacheObservation struct {
	Lineage      promptcache.ObservationLineage
	Model        string
	TTL          string
	Renewal      RenewalSnapshot
	Evidence     promptcache.CacheEvidence
	ObservedAt   time.Time
	CredentialID string
}

CacheObservation is the provider-neutral stream-side data handed to the owning plugin's observation hook on a committed successful turn. Renewal is the exact cacheable prefix (including the cache breakpoint) that created/read the provider cache entry, so the renewal request can reproduce it byte-for-byte.

type CacheObservationHook

type CacheObservationHook func(context.Context, CacheObservation) (promptcache.Observation, error)

CacheObservationHook, when non-nil, issues a renewable target from committed foreground cache evidence. It is supplied by the owning plugin only when automatic enrollment is enabled; nil keeps observation emission off.

type CacheTarget

type CacheTarget struct {
	ALegID            string
	BLegID            string
	BackendInstanceID string
	TargetID          promptcache.TargetID
	GenerationID      promptcache.GenerationID
	Model             string
	Renewal           RenewalSnapshot
	AccountID         string
	WorkspaceID       string
	TTL               string
	Evidence          promptcache.CacheEvidence
}

type Config

type Config struct {
	BackendID          string
	BaseURL            string
	APIKey             string
	APIKeys            []string
	Credentials        []credpool.Credential
	HTTPClient         *http.Client
	SDKMaxRetries      *int
	RateLimitFallback  time.Duration
	ModelInventory     modelinventory.Provider
	ProviderCounter    accountingapp.ProviderCounter
	NormalizeRoles     bool
	NormalizeModel     func(string) string
	ThinkingFromEffort bool
	OmitToolChoice     bool
	// CompatibleModeAuth enables optional credentials for built-in compatible
	// modes: empty resolved keys omit x-api-key. Native Anthropic must leave false.
	CompatibleModeAuth bool
	CacheEnrollment    string
	CacheTTL           string
	// CacheObservation, when non-nil, issues a renewable target from committed
	// foreground cache evidence on successful terminals. It is supplied by the
	// owning plugin only for automatic enrollment; nil keeps emission off.
	CacheObservation CacheObservationHook
}

type RenewalCacheControl

type RenewalCacheControl struct {
	Type string `json:"type"`
	TTL  string `json:"ttl,omitempty"`
}

type RenewalMessage

type RenewalMessage struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

type RenewalSnapshot

type RenewalSnapshot struct {
	Model      string
	System     []RenewalSystemBlock
	Messages   []RenewalMessage
	RawRequest json.RawMessage `json:"-"`
}

RenewalSnapshot is the minimal request shape used by zero-output residency maintenance. RawRequest, when non-empty, is the exact wire body for the renewal, sanitized only for controls that cannot be used with max_tokens=0. Compatible tools and tool-choice settings remain intact so the provider sees the same cache-affecting request shape. RawRequest takes precedence over the typed System/Messages fields and guarantees byte-for-byte prefix reproduction.

type RenewalSystemBlock

type RenewalSystemBlock struct {
	Type         string               `json:"type,omitempty"`
	Text         string               `json:"text,omitempty"`
	CacheControl *RenewalCacheControl `json:"cache_control,omitempty"`
}

Jump to

Keyboard shortcuts

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