judge

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package judge is the decision adapter's one interface (itd-2609221009495079, spc-2609221011151661 scope 1): a typed judgement, (state, question) → (value, probability), with three question kinds — choose one of N, score on a scale, yes or no. The host's own judgement implements it (Host, at probability 1), and so does the decision model reached through the OpenAI-compatible API adapter (Adapter), so the two are compared like for like and a judgement type is switched between them by configuration alone (router.go), never by its caller.

It sits apart from internal/core/decide, the ADR verb's package: the name is shared, the concern is not.

Like the rest of the core it never prints. It writes only through the recorder its Router is given, which is the lab's pairs file in the machine-scoped store (internal/core/lab), never the repository.

Index

Constants

View Source
const (
	RouteHost    = "host"
	RouteAdapter = "adapter"
)

The routes a receipt names.

View Source
const DefaultWindow = 32 << 10

DefaultWindow is the decision model's context, in tokens: the first candidate's 32K (itd-2609221009495079 scope condition 1).

Variables

View Source
var ErrHostPending = errors.New("judge: the host's answer is awaited")

ErrHostPending is a host judgement asked out of band: the caller has written the host's request (the drain's request file) and the answer comes back in a later move. A Router passes it through, with its receipt.

Functions

This section is empty.

Types

type Adapter

type Adapter struct {
	Calls   Caller
	Creds   credential.Source
	Target  oracle.Target
	Options []openaiapi.Option
}

Adapter is the decision model through the one interface: the question is rendered as the host's is, sent to Target through Calls, and the answer is read as a value and a probability. The model cannot abstain, so an answer outside the question's choices, or a probability outside 0 to 1, is no answer at all.

func (Adapter) Judge

func (a Adapter) Judge(ctx context.Context, s State, q Question) (Answer, error)

Judge sends the question through the API adapter and parses the answer.

type Answer

type Answer struct {
	Value       string
	Probability float64
	Model       string
}

Answer is a judgement's answer: one of the question's choices, the probability the answering side gives it, and, from the adapter, the model the provider reported.

type Caller

type Caller interface {
	Call(ctx context.Context, creds credential.Source, req oracle.CallRequest, opts ...openaiapi.Option) ([]byte, oracle.CallRecord, error)
}

Caller is one call through the OpenAI-compatible API adapter; *oracle.APIConfig implements it. Its Call admits the target against the allowlist and oracle.denylist again and resolves the key by name, so a target built anywhere is held to adr-2609221009491186 before any call.

type Host

type Host struct {
	Ask func(ctx context.Context, prompt string) (string, error)
}

Host is the host's own judgement through the one interface (adr-25): Ask is shown the rendered prompt, the same text the adapter is sent, and returns the host's answer, which is parsed against the question's choices at probability 1. A caller whose host has already answered uses Answered.

func Answered

func Answered(text string) Host

Answered is a Host whose answer is already in hand: the drain's host has written its answer file, or a page's host has handed its judgement back.

func Pending

func Pending() Host

Pending is a Host asked out of band: its Judge returns ErrHostPending.

func (Host) Judge

func (h Host) Judge(ctx context.Context, s State, q Question) (Answer, error)

Judge asks the host and parses its answer at probability 1.

type Judge

type Judge interface {
	Judge(ctx context.Context, s State, q Question) (Answer, error)
}

Judge is the one interface: the host and the adapter both implement it.

type Kind

type Kind string

Kind is a question's kind.

const (
	// KindChoose asks for one of the question's options.
	KindChoose Kind = "choose"
	// KindScore asks for an integer on the question's scale, Min to Max.
	KindScore Kind = "score"
	// KindYesNo asks yes or no.
	KindYesNo Kind = "yes-no"
)

The three question kinds.

type LogprobAdapter

type LogprobAdapter struct {
	Calls   Caller
	Creds   credential.Source
	Target  oracle.Target
	Options []openaiapi.Option
}

LogprobAdapter is the second candidate through the one interface.

func (LogprobAdapter) Judge

func (a LogprobAdapter) Judge(ctx context.Context, s State, q Question) (Answer, error)

Judge asks the question for a one-token answer with its alternatives' log-probabilities, and answers the most probable option with its probability normalised over the options.

type Question

type Question struct {
	Type Type
	Kind Kind
	// Ask is the question in words.
	Ask string
	// Options are a choose question's options.
	Options []string
	// Min and Max are a score question's scale, inclusive.
	Min, Max int
}

Question is one typed question.

func (Question) Check

func (q Question) Check() error

Check refuses a question that does not hold together: a type outside the registry, an unknown kind, no words, or options or a scale out of shape.

func (Question) Choices

func (q Question) Choices() []string

Choices are the answers the question admits, as an answer spells them.

type Receipt

type Receipt struct {
	Type          Type    `json:"type"`
	Mode          string  `json:"mode"`
	Route         string  `json:"route"`
	Target        string  `json:"target,omitempty"`
	ModelReported string  `json:"model_reported,omitempty"`
	Probability   float64 `json:"probability"`
	StateSHA256   string  `json:"state_sha256"`
	StateTokens   int     `json:"state_tokens"`
	Fallback      string  `json:"fallback,omitempty"`
	Pair          string  `json:"pair,omitempty"`
	PairSkipped   string  `json:"pair_skipped,omitempty"`
	Note          string  `json:"note,omitempty"`
}

Receipt is what a judgement's run record carries: the type and its mode, the route that decided, the adapter's target and the model it reported, the probability the deciding side gave, the state's hash and size, why a type turned on fell back to the host, and where a shadow pair went or why it was not kept.

type Recorder

type Recorder func(lab.Pair) (labID, where string, err error)

Recorder keeps a shadow pair and returns the lab and the file it went to.

type Router

type Router struct {

	// Window is the adapter's window in tokens; DefaultWindow when zero.
	Window int
	// Diagnostics are the configuration's non-fatal reports, for a front
	// door to print: the oracle reader's, and a route naming a type outside
	// the registry.
	Diagnostics []string
	// contains filtered or unexported fields
}

Router routes each judgement type to the host, to the host with the adapter in shadow, or to the adapter.

func Load

func Load(roots layered.Roots, repoRoot string) (*Router, error)

Load reads oracle.judgements.<type> through the oracle reader, which refuses a model not on its provider's allowlist (or one oracle.denylist matches) before any call, and returns the Router the repository at repoRoot judges with: the adapter is the API adapter with the key resolved by name from the account's credential store (scored by log-probability where the provider's block marks the model so, candidate), and shadow pairs go to the newest lab minted for the repository. A route to a type outside the registry is a diagnostic.

func NewForTest

func NewForTest(routes map[Type]oracle.Target, adapter func(oracle.Target) Judge, record Recorder) *Router

NewForTest is newRouter, the seam a caller's tests route a type with through a fake adapter and recorder.

func (*Router) Decide

func (r *Router) Decide(ctx context.Context, s State, q Question, host Judge) (Answer, Receipt, error)

Decide answers q over s on the route t's configuration names, with host as the host's judgement. Its error is the host's (ErrHostPending among them) or the question's refusal; an adapter's failure is never an error: in shadow it is recorded in the pair, and turned on it is a fallback to host.

func (*Router) Mode

func (r *Router) Mode(t Type) string

Mode is how t is routed: oracle.JudgementHost, JudgementShadow or JudgementOn.

func (*Router) Target

func (r *Router) Target(t Type) string

Target is the adapter t is routed to, as <provider>/<model>; "" when t is on the host.

type State

type State struct {
	Text string
}

State is what a judgement is made over, after retrieval: the text both implementations are shown.

func (State) SHA256

func (s State) SHA256() string

SHA256 is the state's hash, the identity a pair records instead of the text.

type Type

type Type string

Type is a judgement type: one judgement-shaped step abcd may route through the adapter. The registry is closed: a type outside it is refused.

const (
	RemedyRead           Type = "remedy-read"
	DuplicateMatch       Type = "duplicate-match"
	UnmeetableCriteria   Type = "unmeetable-criteria"
	EligibilityResidual  Type = "eligibility-residual"
	SourceClassification Type = "source-classification"
	SourceSelection      Type = "source-selection"
	MemoryCheck          Type = "memory-check"
	LedgerCategory       Type = "ledger-category"
	LedgerSeverity       Type = "ledger-severity"
	PrepassOverlap       Type = "prepass-overlap"
	PresentTense         Type = "present-tense-advisory"
	EmbarkLessonRanking  Type = "embark-lesson-ranking"
)

The judgement types the intent's scope lists. Two steps call the router today: the drain's eligibility-residual, and embark's lesson ranking, one score question per lesson that the host answers with a scores file (dcn-2610300523005947, iss-2610262033055327). Every other type is decided by the host until its step calls the router.

Jump to

Keyboard shortcuts

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