Skip to main content

Module classifier

Module classifier 

Source
Expand description

Classifier (SPEC.md §8B) — the contract for a JUDGMENT, as Tool is the contract for an ACTION. A System One model takes a state plus pre-declared, typed questions and returns calibrated answers with no free text. It has no messages, no tool calling and no streaming, so it never enters the client loop.

A classifier INTERPRETS; it never AUTHORISES. Schema validity is not correctness: a decision can be confidently wrong. Numeric limits, permission checks and allowlists stay in code. Nothing here is a security control. Ported from golang/classifier.go.

Structs§

ChoiceAnswer
One option from the offered set, with a probability for every offered option.
ChoiceQuestion
One option from a named set (1..255). criteria[id] must say what picking it would MEAN — the encoding obligation is the caller’s (ADR 0021).
Classifier
The whole seam: one verb. Cheap to clone.
ClassifierError
A classifier failure. The text is the shared cross-port message.
ClassifierOptions
Classifier options (§8B); mirrors §8 ClientOptions wherever it makes sense.
ClassifierUsage
The wire’s usage block. cost: None means the backend did not say — NOT zero.
Decision
One answer per question, keyed by the caller’s keys.
EvalContext
What a call carries besides state and questions: cancellation, and the call name a Tape records under.
NoulAnswer
The probability that a statement holds. No confidence: the number is the answer.
NoulCriteria
Labels the true and false cases of a noul question. None criteria is ABSENT on the wire; Some(default) is {"false":"","true":""}.
NoulQuestion
The probability that a statement holds (0..1).
RecordedDecision
One entry of the static corpus, keyed on the canonical request AND the state.
ScoreAnswer
A rating against the ordered rubric; may fall between levels.
ScoreQuestion
A rating against an ORDERED rubric of 2..10 levels (never sorted).

Enums§

ClassifierBackend
Whose endpoint answers: sets base URL + model + key env AS A UNIT.
ClassifierStyle
Selects the backend (§8B Backends).
DecisionAnswer
One typed answer, discriminated by the wire’s type.
Question
One pre-declared question. The set is closed.

Constants§

DEFAULT_CLASSIFIER_API_KEY_ENV
The NAME of the env var holding the credential.
DEFAULT_CLASSIFIER_BASE_URL
The System One endpoint base.
DEFAULT_CLASSIFIER_BATCH_CONCURRENCY
How many states evaluate_batch has in flight at once.
DEFAULT_CLASSIFIER_MODEL
The floating alias. Pin it once thresholds are tuned.
DEFAULT_CLASSIFIER_TIMEOUT_MS
Bounds one request in ms (a classifier has no loop to bound).
MAX_CHOICE_OPTIONS
Client-side cap on a choice’s named options.
MAX_SCORE_LEVELS
METRIC_CLASSIFIER_EVALUATE
MetricEvent event values this module emits into the §8 on_metric sink.
METRIC_CLASSIFIER_WARNING
MIN_SCORE_LEVELS
Bounds of a score rubric.
NEAR_UNIFORM_TOLERANCE
ABSOLUTE tolerance on max|p - 1/n|, compared INCLUSIVELY.
OPENROUTER_CLASSIFIER_API_KEY_ENV
OPENROUTER_CLASSIFIER_BASE_URL
The OpenRouter pairing. The model id differs from TypeSafe’s own spelling.
OPENROUTER_CLASSIFIER_MODEL

Functions§

canonical_json
Canonical JSON in Go encoding/json form (SetEscapeHTML(false)): keys sorted bytewise, compact, Go string escaping and Go float formatting.
canonical_request
The bytes the byte-identity claim covers: model + questions, keys sorted recursively, arrays never reordered, compact, <>&'" and non-ASCII raw. state is deliberately NOT here (numbers do not canonicalise).
choice_over
Build a choice from any (name, description) pairs — tools, skills, agents.
create_classifier
Build a classifier, applying the §8B defaults and rejecting a style whose required option is missing before any call is made.
degenerate_criteria
The §8B degenerate predicate: every value empty, every value its own key, or every value identical (n >= 2). A single-option choice never is.
near_uniform
max_i |p_i - 1/n| <= 0.05 over the map AS RETURNED; n == 1 is uniform, an empty map is not a distribution (false).
with_call_name
Name the next evaluation for a tape ("triage", "plan").

Type Aliases§

EvaluateFn
The host’s own evaluation (style: Custom).
Questions
Questions keyed by the CALLER’s keys (never transmitted as content).