Documentation
¶
Overview ¶
Package provider defines RiskKernel's LLM provider abstraction. A Provider is the only place in the codebase (besides internal/otel) permitted to make outbound network calls. Each Chat call returns token Usage so the deterministic governor and cost ledger can attribute spend to a run.
v0.1 implements Anthropic natively; OpenAI, Bedrock, and Ollama are stubs that return ErrNotImplemented. The interface is intentionally provider-neutral so the gateway and governor never special-case a vendor.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotImplemented = errors.New("provider: not implemented in v0.1")
ErrNotImplemented is returned by stub providers that are not yet wired up.
Functions ¶
This section is empty.
Types ¶
type Anthropic ¶
type Anthropic struct {
// contains filtered or unexported fields
}
Anthropic implements Provider against the Anthropic Messages API. It is the native v0.1 provider (the founder builds on Claude).
func NewAnthropic ¶
NewAnthropic constructs an Anthropic provider. apiKey must be non-empty.
type Bedrock ¶
type Bedrock struct{}
Bedrock is a stub. Native implementation is planned post-v0.1.
func NewBedrock ¶
func NewBedrock() *Bedrock
type Ollama ¶
type Ollama struct {
// contains filtered or unexported fields
}
Ollama is a stub for local models. Native implementation is planned post-v0.1.
type OpenAI ¶
type OpenAI struct {
// contains filtered or unexported fields
}
OpenAI implements Provider against the OpenAI Chat Completions API.
type Provider ¶
type Provider interface {
// Name is the stable provider identifier used in config, routing, and the
// OTel gen_ai.system attribute (e.g. "anthropic").
Name() string
// Chat performs one chat completion. It must honor ctx for cancellation and
// deadlines — this is how the governor's kill switch and time budget reach an
// in-flight call. It must always populate Usage on success.
Chat(ctx context.Context, req Request) (*Response, error)
}
Provider is an LLM backend. Implementations must be safe for concurrent use.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry holds the configured providers, keyed by Name(). It is read-only after construction and safe for concurrent use.
func NewRegistry ¶
NewRegistry builds a registry from the given providers. defaultName selects the provider used when a request does not specify one; it must be present.
type Request ¶
type Request struct {
// Model is the provider-specific model identifier (e.g. "claude-sonnet-4-5").
Model string `json:"model"`
// System is an optional system prompt, kept separate from Messages because
// some providers (Anthropic) take it as a distinct field.
System string `json:"system,omitempty"`
// Messages is the ordered conversation, excluding the system prompt.
Messages []Message `json:"messages"`
// MaxTokens caps the completion length. Required by some providers
// (Anthropic); a provider may supply a sane default when zero.
MaxTokens int `json:"max_tokens,omitempty"`
// Temperature is optional; nil means "use the provider default".
Temperature *float64 `json:"temperature,omitempty"`
}
Request is a provider-neutral chat completion request.
type Response ¶
type Response struct {
// ID is the provider's response identifier, for the OTel span and audit log.
ID string `json:"id"`
// Model is the model that actually served the request.
Model string `json:"model"`
// Content is the assistant's text output (concatenated across content blocks).
Content string `json:"content"`
// FinishReason is the provider's stop reason, normalized loosely
// ("stop", "length", "tool_use", ...).
FinishReason string `json:"finish_reason"`
// Usage is the token accounting for this call.
Usage Usage `json:"usage"`
}
Response is a provider-neutral chat completion result.