provider

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package provider is the one place the environment is mapped onto an LLM backend. Both `whetstone` (authoring, on a developer's machine) and `skael-worker` (scoring, on a server) resolve their gateway here, so a misconfiguration is diagnosed with the same words wherever it is met.

Four provider modes, and no variable outside this file selects one:

  1. Anthropic direct ANTHROPIC_API_KEY
  2. Compatible gateway ANTHROPIC_BASE_URL + ANTHROPIC_API_KEY or ANTHROPIC_AUTH_TOKEN
  3. Subscription CLI nothing set, and an agent CLI on PATH
  4. Split mode 2, plus CLAUDE_CODE_OAUTH_TOKEN

The judge and the eval panel share ANTHROPIC_BASE_URL. Mode 4 is the one case where they separate: the panel bills to a subscription, the judge keeps the gateway. Turning it on changes model_panel, which splits a skill's score trend at the changeover. See Resolve, PanelModels and PanelExcludeEnv.

Index

Constants

View Source
const (
	APIKeyEnv    = "ANTHROPIC_API_KEY"
	AuthTokenEnv = "ANTHROPIC_AUTH_TOKEN"
	BaseURLEnv   = "ANTHROPIC_BASE_URL"
	// ModelEnv is a comma-separated list, most capable first. The first entry
	// serves every judge call and the panel's primary member; the rest are the
	// panel's floor members, which only the deep tier runs. It replaces the
	// former LLM_STRONG_MODEL/LLM_FAST_MODEL pair, whose two names could be
	// half-set — a panel with one working member and one that 404s is not an
	// error but a complete run that scores and can never release anything.
	ModelEnv = "LLM_MODEL"
	// OAuthTokenEnv is Claude Code's own subscription credential. It is read
	// here only to select mode 4 — this package never authenticates a judge
	// call with it, because a subscription is neither metered nor pinned to a
	// model, and a released version's score must be both.
	OAuthTokenEnv = "CLAUDE_CODE_OAUTH_TOKEN"
)

The environment this package reads. These are the Anthropic SDK's and the Claude Code CLI's own names rather than Skael-specific ones, so a machine already set up for either needs no further configuration — and so the panel, which is a Claude Code CLI running inside a sandbox, reads the same values the worker resolved.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Kind Kind
	// Detail explains the choice in one clause, including why it is none.
	Detail string
	// Binary is the agent CLI backing a subscription provider.
	Binary string
	// BaseURL is ANTHROPIC_BASE_URL, empty for Anthropic's own API. It is the
	// panel's gateway as much as the judge's.
	BaseURL string
	// Key is whichever credential authenticates the API provider.
	Key string
	// AuthStyle is inferred from which credential was set rather than
	// configured: a bearer token is only ever presented as a bearer token.
	AuthStyle api.AuthStyle
	// Models is ModelEnv, split and trimmed. Empty means the shipped defaults.
	Models []string
	// PanelSubscription reports mode 4: the judge dials BaseURL, and the eval
	// panel authenticates with OAuthTokenEnv instead. It changes what the
	// panel asks for (PanelModels) and what the sandbox is allowed to see
	// (PanelExcludeEnv); both are required, because either one alone leaves
	// the panel on the gateway.
	PanelSubscription bool
}

Config is the resolved provider. It is data only: nothing here dials anything until Gateway is called.

func APIFromEnv

func APIFromEnv() Config

APIFromEnv is FromEnv with subscription detection off, for a caller whose backend must be metered and reproducible — `skael-worker`, whose judge output releases versions. A CLI on the worker's host is then not a provider at all rather than a provider it must refuse, so an operator who has both a key and a CLI installed is served by the key.

func FromEnv

func FromEnv() Config

FromEnv resolves the provider from this process's environment, including a subscription CLI on PATH.

func Resolve

func Resolve(env Getenv, detect Detector) Config

Resolve picks a provider.

Explicit gateway configuration beats autodetection: setting a base URL or a bearer token is an unambiguous statement that a particular gateway is intended, and silently preferring a subscription CLI that happens to be on PATH would bill the wrong account and evaluate against a different model than the one configured.

APIKeyEnv alone stays *below* the CLI. It is present on plenty of developer machines that also have the CLI installed, and treating it as an override would move those machines onto metered billing without anyone asking for it.

func (Config) Gateway

func (c Config) Gateway(o Options) (llm.Gateway, error)

Gateway builds the resolved backend.

func (Config) PanelExcludeEnv

func (c Config) PanelExcludeEnv() []string

PanelExcludeEnv names the credential variables a sandbox must NOT be given, even though the agent adapter declares them. It is empty in every mode but the split.

This is the half that actually moves the panel. The claude-code adapter forwards each name it declares that is set, so a worker whose own environment names a gateway hands that gateway to every panel member. PanelModels alone does not help: the member would ask a subscription for the alias it serves and still be pointed at the gateway to ask.

The API key is withheld with the gateway's own two names. It is not the judge's credential in this mode, and forwarding it leaves the sandbox holding two competing credentials, which is the ambiguity this mode exists to remove.

func (Config) PanelModels

func (c Config) PanelModels() []string

PanelModels is the model ids the eval panel should ask for, empty when the shipped default is right.

Gated on BaseURL, not on ModelEnv alone: an operator who named a model to pick a cheaper judge against Anthropic's own API must keep the panel they had, since a changed panel is recorded in model_panel and splits the score trend. A custom gateway is the case where the shipped aliases cannot work. A panel on the subscription is the other empty case: a subscription serves Anthropic's own aliases, so handing it the gateway's namespaced ids fails every member's health probe — a complete run that scores nothing and can never release the version it was meant to clear.

func (Config) Validate

func (c Config) Validate() error

Validate reports a configuration that cannot serve a call. It is the shared half of `whetstone doctor` and the worker's startup probe: both report what this returns, so the same mistake reads the same way in both.

func (Config) Warnings

func (c Config) Warnings() []string

Warnings reports configurations that work often enough not to refuse, and break confusingly when they do break. One place, so `whetstone doctor` and the worker's startup say the same thing.

type Detector

type Detector func() (string, error)

Detector reports the agent CLI serving a subscription provider.

type Getenv

type Getenv func(string) string

Getenv is os.Getenv, injectable so resolution is testable without touching the process environment.

type Kind

type Kind string

Kind names the backend serving model calls.

const (
	// KindSubscription is an agent CLI on PATH, billed to a subscription.
	KindSubscription Kind = "subscription"
	// KindAPI is a direct HTTP gateway: Anthropic's own, or a compatible one.
	KindAPI Kind = "api"
	// KindNone is no usable backend.
	KindNone Kind = "none"
)

type Options

type Options struct {
	Cache      llm.Cache
	Timeout    time.Duration
	MaxRetries int
}

Options are the per-caller gateway settings that are not provider choices: whetstone allows a long interactive timeout and shares its workspace completion cache, the worker does neither.

Jump to

Keyboard shortcuts

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