Help us shape the future of Go! Take the 2026 Go Developer Survey

decide

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package decide asks typed questions about a run (2.0 W3, #175): yes/no, score and choice. Every Oracle answers the same questions; Guarded wraps a model-backed one so that any error, timeout or unanswered question falls back to the questions' own heuristics. Callers never see an error.

Index

Constants

View Source
const Timeout = 2500 * time.Millisecond

Timeout bounds a model-backed oracle's answer (spec §5 W3: 2.5 s, then the heuristic).

Variables

This section is empty.

Functions

func Record

func Record(use string, latency time.Duration, answered bool)

Record counts one model-backed call: how long it took and whether it answered (false: an error or timeout, so the heuristic answered).

func ResetStats

func ResetStats()

ResetStats clears the counters (tests).

func Snapshot

func Snapshot() map[string]any

Snapshot is the celeste_status "oracle" object (without "mode", which the server adds): totals over every use, then each use.

Types

type Answer

type Answer struct {
	P          float64            // YesNo: P(yes)
	Score      float64            // Score: 0-based level, probability-weighted
	Choice     string             // Choice: the most likely option
	Probs      map[string]float64 // Choice and Score: the distribution, when known
	Confidence float64            // Choice and Score: 0..1, when known
	Source     string             // "heuristic", "llm" or "jev"
}

Answer is one typed answer.

type CallView

type CallView struct {
	Tool    string `json:"tool"`
	Args    string `json:"args,omitempty"`
	Result  string `json:"result,omitempty"`
	IsError bool   `json:"is_error,omitempty"`
}

CallView is one tool call and, once it ran, its result.

type CompleteFunc

type CompleteFunc func(ctx context.Context, system, user string) (string, error)

CompleteFunc is one small-model call (compact.SummarizeFunc's shape).

type Heuristic

type Heuristic struct{}

Heuristic is the default Oracle: each question's Heuristic, no model.

func (Heuristic) Ask

func (Heuristic) Ask(_ context.Context, state string, qs []Question) (map[string]Answer, error)

type Jev

type Jev struct{ Client *jev.Client }

Jev is the TypeSafe System One oracle. The state goes to a third party: the client redacts it before it is sent.

func (Jev) Ask

func (j Jev) Ask(ctx context.Context, state string, qs []Question) (map[string]Answer, error)

type Kind

type Kind string

Kind is a question's type, named as TypeSafe names them.

const (
	YesNo  Kind = "noul"
	Score  Kind = "score"
	Choice Kind = "choice"
)

type LLM

type LLM struct {
	Complete  CompleteFunc
	Workspace string
}

LLM asks the small model and reads a JSON object back. No backend at 2.0 sets a provider JSON mode, so the JSON is required by the prompt and parsed leniently: the first {...} in the reply. The small model may be a remote provider, so the state is redacted first, as for Jev: secrets, and file paths (workspace-relative inside Workspace, <path> elsewhere).

func (LLM) Ask

func (o LLM) Ask(ctx context.Context, state string, qs []Question) (map[string]Answer, error)

type Oracle

type Oracle interface {
	Ask(ctx context.Context, state string, qs []Question) (map[string]Answer, error)
}

Oracle answers questions about state, a JSON document (State.String) or plain text. The map holds the questions it could answer.

func Guarded

func Guarded(primary Oracle, use string, logf func(string)) Oracle

Guarded asks primary under Timeout. On an error it answers from the questions' heuristics, and a question primary left unanswered gets its heuristic answer too. It never returns an error. use names the caller in the stats ("ballot", "gate", "route", "prune"); logf (nil: none) gets one line per failed call. A nil primary is the heuristic alone and is not counted in the stats.

func New

func New(mode string, complete CompleteFunc, use, workspace string, logf func(string)) Oracle

New returns the oracle the config's `oracle` key names, Guarded for use: "llm" asks the small model through complete, "jev" asks TypeSafe (key from TYPESAFE_API_KEY or ~/.celeste/typesafe.key), anything else is the heuristic. A missing key or small model logs once and gives the heuristic. workspace is the run's: paths inside it are sent workspace-relative, every other path as <path> (jev.RedactPaths). logf may be nil.

func NewJev

func NewJev(use, workspace string, logf func(string)) Oracle

NewJev is the Jev oracle, Guarded for use, whatever `oracle` says: jev_gate and jev_route always ask Jev. Without a key it is the heuristic.

type Question

type Question struct {
	ID   string
	Kind Kind
	Text string // what to decide; may name fields of the state in `backticks`
	// YesNo: optional criteria for yes and no.
	True, False string
	// Score: the ordered level descriptions, 2 to 10. Answer.Score is the
	// 0-based level.
	Levels []string
	// Choice: option → description ("" for none).
	Options map[string]string
	// Heuristic answers without a model. Nil, or ok == false, is no opinion.
	Heuristic func(State) (Answer, bool)
}

Question is one typed question.

type State

type State struct {
	Goal   string     `json:"goal,omitempty"`
	Latest string     `json:"latest_user_message,omitempty"`
	Turns  []TurnView `json:"recent_turns,omitempty"`
	Call   *CallView  `json:"pending_call,omitempty"`
	Text   string     `json:"text,omitempty"`
}

State is what the oracle sees: the goal, the latest user message, the recent turns, and free text for questions about one string (routing). Every string is redacted (jev.RedactAll: secrets and file paths) before it leaves the machine.

func ParseState

func ParseState(s string) State

ParseState reads a State back. Text that is not a JSON object becomes State.Text.

func (State) String

func (s State) String() string

String is the state as JSON, the form every Oracle takes.

type TurnView

type TurnView struct {
	Assistant string     `json:"assistant,omitempty"`
	Calls     []CallView `json:"calls,omitempty"`
}

TurnView is one model turn: what it said and the calls it made.

Jump to

Keyboard shortcuts

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