Skip to content
Get started

Council, cascade and race

Use with an AI tool

One request can use several models. Pick a plan by what you want to optimise.

Plan Models are asked Good for Answers get
Fallback chain one at a time, until one answers surviving outages and rate limits -
Council all at once, blended fewer confident mistakes agreement
Cascade cheapest first, escalating only unsure questions cost answered_by
Race all at once, first valid answer wins latency -

Four ways to use several models. A fallback chain asks one model at a time until one answers. A council asks all models at once and blends them by geometric mean. A cascade asks the cheapest model first and escalates only unsure questions. A race asks all models at once and the first valid answer wins.

client.decide(state, questions, model=["model-a", "model-b"])

If a model returns 429 or a server error, the next one takes over. The response’s model says which one answered.

A chain can still run out: every model failed or timed out, the rate limit held after the retries, or the server can’t be reached. Give decide a fallback, one safe answer per question, and it returns those instead of raising:

d = client.decide(ticket, questions, fallback={"team": "human_review", "refund": False})
if d.fallback: # no model answered; d.error says why
queue_for_a_person(ticket)

Every fallback answer has fallback=True, abstain=True and confidence 0, so code that already sends unsure answers to a person treats it the same way. A fallback must name every question with a value that question could give (an option key, True/False, a list of option keys, a level index, a number, a string or None); anything else is a ValueError before any request. A mistake in the request itself (400, 401, 404, 422) is still raised, never hidden.

A question one of your rules answered keeps the rule’s answer (or stays skipped), since it needed no model: only the questions sent to the model get their fallback.

d = client.decide(state, questions, council=["model-a", "model-b", "model-c"])
d["team"].agreement # share of members whose top answer matches the council's

2 to 5 models answer concurrently, and their probabilities are blended by geometric mean. Where members disagree, confidence drops, which is exactly what you want: disagreement is a signal to look closer. A member that fails is left out.

HTTP: "model": {"council": ["model-a", "model-b"]}.

d = client.decide(state, questions, cascade=["free-model", "strong-model"], escalate_below=0.8)
d["team"].answered_by # the model that gave the final answer

The cheapest model answers first. Only the questions whose confidence is below escalate_below (default 0.8) go to the next model, and so does an answer that changed when the options were asked in the other order (unstable); confident, steady answers stand. If the stronger model fails, the cheaper answers are kept. When the cheap model is sure, the strong model is never called.

HTTP: "model": {"cascade": ["free-model", "strong-model"], "escalate_below": 0.8}.

client.decide(state, questions, race=["model-a", "model-b"])

All models are asked at once, the first valid answer wins, and the others are cancelled. This cuts slow outliers on shared providers, at the cost of one call per model.

HTTP: "model": {"race": ["model-a", "model-b"]}.

client.decide(state, questions, hedge=["fast-model", "backup-model"], hedge_after_ms=150)

The first model is asked alone. Only if it has not answered after hedge_after_ms (default 150) is the next one asked too; the first valid answer wins and the other is cancelled. A model that fails outright hands over at once. You get close to a race’s protection against a slow model while paying for the backup only when it was needed. The answer’s latency_ms includes the wait.

HTTP: "model": {"hedge": ["fast-model", "backup-model"], "after_ms": 150}.

client.decide(state, questions, auto=["model-a", "model-b", "model-c"])

You list the models; Curva decides the order and the wait. It keeps track of how fast each model has been answering on this server, asks the fastest first, and brings in the next one after one and a half times the leader’s usual time. A model that stops answering in time falls back by itself, and a model not measured in the last five minutes is tried first once, so a model that recovered is noticed. What it learnt is kept in memory and starts again when the server restarts.

It orders by speed only. It does not yet look at which model is right more often.

HTTP: "model": {"auto": ["model-a", "model-b", "model-c"]}.

curva bench and curva map take the same plans:

Terminal window
curva bench --council model-a,model-b
curva map in.jsonl -q questions.json -o out.jsonl --cascade free-model,strong-model --escalate-below 0.8
curva bench --race model-a,model-b

Use only one of council, cascade, race, hedge or auto per request.