Documentation
¶
Overview ¶
Package decide defines the contract for decision models: a request carries a shared state and a set of typed questions, evaluated in parallel and in isolation, and returns typed answers with calibrated probabilities. It is the decision-model counterpart of provider.Provider for chat.
The wire implementation lives in decide/openrouter. A caller may also supply its own Decider; Roles is the decorator that maps an application role such as "oracle" to a model id, a timeout, and an optional fallback.
Index ¶
Constants ¶
const ( // KindChoice picks one option from Criteria. KindChoice = "choice" // KindNoul reports the probability that a yes/no condition holds. KindNoul = "noul" // KindScore places the state on an ordered set of Levels. KindScore = "score" )
The question kinds the Decisions API documents. KindChoice is the default when Question.Kind is empty. An unknown kind is carried through unchanged, so a new wire kind does not need an API change here.
Variables ¶
This section is empty.
Functions ¶
func ValidateResponse ¶
ValidateResponse checks a response against the request that produced it. It rejects a value outside the question's option set or level range, a missing or unexpected answer, and a confidence or probability outside [0,1]. The wire client treats a failure as a malformed response and does not pass it through to the caller.
Types ¶
type Answer ¶
type Answer struct {
Kind string `json:"kind,omitempty"`
Choice string `json:"choice,omitempty"`
Noul float64 `json:"noul"`
Score float64 `json:"score"`
Legend map[string]string `json:"legend,omitempty"`
Probabilities map[string]float64 `json:"probabilities,omitempty"`
Confidence float64 `json:"confidence"`
}
Answer is one question's result. The fields that matter depend on the question kind: a choice answer names one option from Criteria, a noul answer is a probability, and a score answer is a position on Levels with an optional legend and per-level probabilities keyed by their index.
type Catalog ¶
Catalog reads a live decision-model roster. decide/openrouter's Client implements it, so a benchmark can accept a catalog without naming a vendor.
type Clock ¶
Clock is the time seam for a role's timeout. It is the shared roles.Clock, so a caller can inject one clock for every primitive.
type Decider ¶
Decider is a decision backend. Implementations must honor ctx cancellation and must return a non-nil error on failure.
type Question ¶
type Question struct {
Kind string `json:"kind,omitempty"`
Instructions any `json:"instructions,omitempty"`
Criteria map[string]string `json:"criteria,omitempty"`
Levels []string `json:"levels,omitempty"`
}
Question is one typed question. Kind defaults to KindChoice when empty.
A choice question uses Criteria, whose keys are the option set. A noul question may use Criteria with exactly the keys "true" and "false". A score question uses Levels, ordered lowest first; its wire criteria are that list. Instructions may be a string, or an object/array when the model accepts structured instructions.
type Request ¶
type Request struct {
// Model is a catalog id or a configured role name. Roles resolves a role;
// a direct id must contain a slash so an unknown role is never mistaken for
// a model id.
Model string `json:"model"`
// State is the shared evidence: a string, or []Source for a multi-source
// comparison.
State any `json:"state"`
// Questions are keyed by the caller's name for the answer. The map must not
// be empty.
Questions map[string]Question `json:"questions"`
}
Request is one decision call. Every question is evaluated in parallel and in isolation against the same State, so a caller should fan out questions in one request rather than making one call per question.
type Response ¶
type Response struct {
// Answers is keyed by the request's question name.
Answers map[string]Answer `json:"answers"`
// Usage is the call's token and cost accounting. The Decisions API reports
// one cost per call, not per question.
Usage provider.Usage `json:"usage"`
// Model is the build that actually answered, when the server reports it.
// An alias moves silently, so a caller that records a benchmark result
// should record this too.
Model string `json:"model,omitempty"`
}
Response is one decision call's result.
type Role ¶
Role maps one application role to a model id and its bounds. Timeout is per attempt; zero means only the caller's context bounds the call. Fallback is tried when the primary fails and the caller's context is still live.
type Roles ¶
type Roles struct {
// contains filtered or unexported fields
}
Roles resolves a role name to a model id and applies the role's timeout and fallback. A request whose Model contains a slash is treated as a direct model id and passes through; a bare unknown name is a configuration error naming the role, never a 400 from the wire. The resolver itself lives in roles, because every primitive that maps an application name to a model needs the same rules.
func NewRoles ¶
func NewRoles(cfg RolesConfig) *Roles
NewRoles builds the decorator. It does not validate the table, because a bad role is a configuration error the caller should see when it is used, not a crash at startup.
type RolesConfig ¶
type RolesConfig struct {
Decider Decider
// Roles maps an application role name to its model and bounds.
Roles map[string]Role
// Clock drives a role's timeout; nil means the wall clock.
Clock Clock
// AllowAliases permits ids that end in "-latest" or start with "~".
// False is the default: an alias moves without notice, so a decision that
// fires on every turn could change model and nobody would see it.
AllowAliases bool
}
RolesConfig builds a Roles decorator.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package openrouter implements decide.Decider over OpenRouter's decision surfaces.
|
Package openrouter implements decide.Decider over OpenRouter's decision surfaces. |