rea-analysis-optimization
MOmorluto/rea485k9,215 new stars in the last 7 days
What a decision model is in this repo, the contract one implements, the System One protocol most vendors here speak, and how to add a vendor or a model to the decision_model router. Read before adding a decision model, a decision model vendor or a guardrail backend.
A decision model answers named questions about a piece of state with typed values and the probabilities behind them. It writes no prose. What used to be called an LCM (large classifier model) here is this; the industry settled on "decision model", and so did we.
The per-modality half of router-interface:
| What | Where |
|---|---|
| The contract | internal/decisionmodel |
| The wire protocol | internal/decisionmodel/systemone |
| One package per vendor | internal/decisionmodel/<vendor>/ |
| The router | internal/decisionrouter |
| The models | the decision_model section of router.yaml |
| The modality | routing.DecisionModel, "decision_model" in the API and in stats |
| Callers | /v1/classify, type: decision_model guardrails, prompt injection screening |
Something is a decision model here when all four hold. If one does not, it belongs somewhere else.
violates: 0.93 is something a threshold acts on. A chat
model's "Yes, this violates the policy" is something a parser acts on, and a parser that fails
has no number to fall back to.search, not like llm, and why
failover happens at start only. The caller is mid-turn, and a second provider's latency on
top of the first one's failure is a longer silence than saying the judgement did not arrive.A chat model with a JSON schema or logprobs passes the first test and fails the third. It
stays in llmrouter. The two run side by side: internal/guardrail has a decision model
backend and an LLM-judge backend, and the policy file picks one.
| Constructor | Asks | Answer lands in |
|---|---|---|
Noul(instructions, yes, no) | yes or no | Answer.Yes, a probability from 0 to 1 |
Choice(instructions, options) | which of these | Answer.Chosen, plus Probabilities and Confidence |
Score(instructions, levels) | where on this ordered scale | Answer.Level, which can fall between two levels, plus Legend, Probabilities and Confidence |
These three are what every vendor below takes. Do not add a fourth unless every vendor's API
has it: a question type that only one provider supports can't be routed. A hazard battery
is several Nouls in one request, not a new type. OpenAI's own API calls the noul a
predicate and Vercel's AI SDK calls it boolean; translate that at the edge, never in the
contract.
Getting the most out of them:
Choice keeps an option whose description is
empty (it goes on the wire as null), because the name can be all an option needs.Score for a spectrum. A noul at 0.5 means an even split between yes and no, not
"medium".Confidence says how peaked a distribution is, not whether acting on it is safe. A
guardrail should threshold on the probability it cares about, not on confidence.decisionmodel.Provider is Classify, Start, Close, Provider and Model. The rules:
Request.Validate() before anything reaches the wire. A question with
no instructions, or a type nobody knows, is refused locally rather than spending a round trip
to come back as a 422.violates read as 0.0
is a guardrail that allows everything, and nothing about the turn would say so.Result.Model is the version that answered, not the alias that was asked. Aliases move
when a release ships, and a threshold tuned against one version needs to know.acceleration/prices/vendor.json, then the database) turns them into cost; never
compute cost in the provider.ErrRateLimited. An
overloaded service (503, 529) or a network failure wraps ErrUnavailable. Anything else is
the request's own fault. /v1/classify turns those into its status codes.options.Classifier.Terms() returns nothing, and that is not a gap to
close later. Everything a caller asks for travels in the questions, so there is no parameter
for a provider to accept and quietly drop. A provider that cannot express a question should
fail the request rather than answer a different one. The caller cannot tell from a
probability that it was answered about something else.TypeSafe published System One for Jev. OpenRouter, Perplexity, Alibaba Model Studio and AnyRouter adopted it unchanged:
{"model": "...", "state": "text, or a JSON object whose parts a question names in backticks",
"questions": {
"is_bug": {"type": "noul", "instructions": "...", "criteria": {"true": "...", "false": "..."}},
"team": {"type": "choice", "instructions": "...", "criteria": {"payments": "...", "none": null}},
"urgency": {"type": "score", "instructions": "...", "criteria": ["lowest level", "...", "highest"]}}}
The answers come back keyed the same way, as {"type", "noul" | "choice" | "score", "probabilities", "confidence", "legend"}, beside model and usage.input_tokens and usage.output_tokens.
systemone.Client speaks this and nothing else. Perplexity refuses any field it does not
know, so the request carries model, state and questions and nothing more.
Google's Decisions API is the one vendor here off System One, in
internal/decisionmodel/gemini.
Its answers use System One's fields, but the state is input (a state with parts goes as
its JSON text), a noul's criteria are true_description and false_description, the key is
x-goog-api-key, usage is total_input_tokens, and the answer names no model. A yes or
no probability is never below 0.01 or above 0.99, so a threshold outside that range never
fires.
OpenAI's own Decisions API (POST /v1/decisions, limited preview) is another shape that
differs: input instead of state, questions and answers as arrays carrying name,
predicate with probability, and choices and levels as objects. Reach GPT-6 Luna
Decisions through OpenRouter, which translates it into System One. Write an openai vendor
only when there is a reason to skip OpenRouter, and do the translation inside that package.
| Vendor | Endpoint | Key | Models declared |
|---|---|---|---|
typesafe | api.typesafe.ai/v1/systemone | TYPESAFE_API_KEY | jev-latest (the default route's pin) |
openrouter | openrouter.ai/api/alpha/decisions | OPENROUTER_API_KEY | typesafe/jev-1.13, openai/gpt-6-luna-decisions, cloudflare/clef-flash, cloudflare/clef, respan/span-01-lite, liquid/d1, jaredpalmer/kev-4b, perplexity/pplx-decider-v1.1-27b, inception/mercury-decide, inception/mercury-decide:free |
perplexity | api.perplexity.ai/v1/decisions | PERPLEXITY_API_KEY | pplx-decider-v1.1-27b, pplx-decider-v1-27b |
gemini | generativelanguage.googleapis.com/v1beta/decisions (not System One) | GOOGLE_API_KEY | gemini-decision-1 |
To see what OpenRouter currently serves, run
curl "https://openrouter.ai/api/v1/models?output_modalities=decisions". A model can be listed
there with no endpoint behind it, which is why Decider V1 goes to Perplexity directly.
How they are routed:
classify-fast is what a guardrail or prompt injection screening gets when it names
nothing. It prefers typesafe/jev-latest, because every threshold in use was tuned against
Jev. Without the pin, health ranking would hand guardrails to whichever of the ten answered
fastest last.high-quality model, so it is what the two *-high-accuracy shortcuts
resolve to.:free) are capped at a few requests a minute and a few dozen a day. They
are declared realtime: false, so a live route never lands on one, and they are priced with
free: true in prices/vendor.json rather than no price. TestEveryRoutedModelIsPriced
still catches a price that was forgotten.On a vendor that already exists, it is a router.yaml entry and its price:
provider, model (exactly the vendor's model id), a one-sentence description,
languages, realtime and tier to router.yaml, and its input_tokens rate to
acceleration/prices/vendor.json, read from the vendor's price list and dated in the
router.yaml comment.low-latency is for the live path. high-quality is a slower
model that is more accurate.On System One, a vendor is an Endpoint and nothing else:
internal/decisionmodel/<vendor>/<vendor>.go with ProviderName, an Endpoint
(key and base-URL env vars, base URL, path, default model) and
New(systemone.Options) (*systemone.Client, error). Copy perplexity as the template.registry.go,
and add a row to TestEachVendorIsAskedAtItsOwnEndpointWithItsOwnKey and a key to the
keys map in integration_test.go.router.yaml. TestTheDefaultRegistryHasEveryProviderTheConfigDeclares
fails until step 2 is done, which is the point.pricing skill from this repo on how to do this.Off System One, the package implements decisionmodel.Provider itself. It translates the
neutral request into the vendor's wire shape and back inside that package, and follows every
rule under "The contract". The contract carries no vendor's JSON tags, and keeping it that
way is what makes the next vendor cheap.
systemone_test.go, against an httptest server with a made-up endpoint.integration_test.go in decisionrouter (//go:build integration) asks every model
declared in router.yaml an obvious yes and an obvious no, and skips a vendor whose key is not
set. Run it with
go test -tags integration ./internal/decisionrouter/ -run DecisionModelIntegration.
An OpenRouter account with no credits answers 402 on every paid model, while the
:free one still works.MOmorluto/rea485k9,215 new stars in the last 7 days
MAmattpocock/skills336k5,004 new stars in the last 7 days
Diagnose hard bugs and performance regressions by building a feedback loop with tests or scripts.
MAmattpocock/skills336k5,004 new stars in the last 7 days
MAmattpocock/skills336k5,004 new stars in the last 7 days
MAmattpocock/skills336k5,004 new stars in the last 7 days
MAmattpocock/skills336k5,004 new stars in the last 7 days