Deciding
decide.decide()
Ask every question about state in one request, asynchronously; decide_sync documents the contract.
Usage
decide.decide(
state, questions, *, provider=JEV, timeout=DEFAULT_TIMEOUT, api_key=None
)The call runs decide_sync on a worker thread, so it shares the process’s keep-alive client and holds no connection to the event loop.
Example
>>> decision = await decide({"title": "Revert the release"}, {
... "kind": Label("What does the title ask for?", {"other": None, "rollback": None}),
... }, provider=OPENAI)decide.decide_sync()
Ask every question about state in one request and return the typed answers.
Usage
decide.decide_sync(
state, questions, *, provider=JEV, timeout=DEFAULT_TIMEOUT, api_key=None
)Keep each question to one observable fact and combine the answers in code; put counting, dates, and arithmetic in code too. Retries 408, 429, 5xx, 529, and a lost connection with backoff from 0.5s doubling to 5s, honoring retry-after, and only while the retry still fits inside timeout. The Keychain read counts against timeout too, and an answer that arrives after it raises TimeoutError rather than returning late.
Parameters
state: str | Mapping[str, Any] | Sequence[Any]-
The text to judge, or JSON data; Jev reads structure natively and OpenAI receives it as compact JSON text.
questions: Mapping[str, Question]-
Each question id mapped to its question, in the order to ask them.
provider: Provider = JEV-
JEVorOPENAI, or a Provider pinning another model. timeout: float = DEFAULT_TIMEOUT-
Seconds for the whole call, retries included.
api_key: str | None = None-
The provider key;
Nonereads it through api_key.
Returns
Raises
TimeoutError-
When no answer arrives within
timeout. DecideError-
When the provider rejects the request.
DecideKeyMissing-
When no key is passed or found.
ValueError- When the question set breaks a limit both providers share, such as a label with fewer than 2 options or a score with more than 10 levels.
Example
>>> decision = decide_sync("Please roll back last night's release.", {
... "rollback": Binary("Does the message ask to roll back a release?"),
... })
>>> decision.answers["rollback"].p_yes > 0.5True
Binary
A yes/no question; its answer is the probability of yes.
Usage
Binary(instructions, yes=None, no=None)Attributes
instructions: str-
The question, about one observable fact.
yes: str | None-
What a yes means, when the question alone leaves it open.
no: str | None- What a no means, when the question alone leaves it open.
Example
>>> Binary("Does the message ask to roll back a release?")Label
Pick one option from 2 to 255; put the fail-safe option first, since Jev leans toward it.
Usage
Label(instructions, options)Attributes
instructions: str-
What to decide.
options: Mapping[str, str | None]-
Each option value mapped to its description, or
None, in declared order.
Example
>>> Label("Which release action does the message ask for?", {"none": None, "rollback": "Undo a release"})Score
Rate along 2 to 10 ordered levels, lowest first; the score is the probability-weighted level index.
Usage
Score(instructions, levels)Attributes
instructions: str-
What to rate.
levels: Mapping[str, str | None]-
Each level label mapped to its description, or
None, lowest first.
Example
>>> Score("How urgent is the message?", {"Not urgent": None, "Somewhat urgent": None, "Blocking": None})Decision
One provider response: an answer per question id, in the order asked.
Usage
Decision(answers, model, input_tokens, latency_ms)Attributes
answers: Mapping[str, Answer]-
Each question id mapped to its answer.
model: str-
The model that answered, as the provider reports it.
input_tokens: int-
Billed input tokens.
latency_ms: float- Wall time of the attempt that answered, request to parsed response.
BinaryAnswer
The answer to a Binary question.
Usage
BinaryAnswer(p_yes, confidence)Attributes
p_yes: float-
Probability the answer is yes.
confidence: float-
abs(2 * p_yes - 1), 0 at a coin flip and 1 at certainty.
LabelAnswer
The answer to a Label question.
Usage
LabelAnswer(choice, probabilities, confidence)Attributes
choice: str-
The most likely option value.
probabilities: Mapping[str, float]-
Every option value mapped to its probability, in declared order.
confidence: float- How far the distribution sits from uniform, 0 to 1.
ScoreAnswer
The answer to a Score question.
Usage
ScoreAnswer(score, probabilities, confidence)Attributes
score: float-
The probability-weighted level index; it can land between levels.
probabilities: Mapping[str, float]-
Every level label mapped to its probability, lowest first.
confidence: float- How concentrated the distribution is around its top level, 0 to 1.
Refused
A question the provider declined to answer while it answered the others.
Usage
Refused()Provider
A decision provider and the model it runs.
Usage
Provider(name, model)Attributes
name: TDecideProvider-
jevposts to TypeSafe’s System One endpoint,openaito OpenAI’s/v1/decisions. model: str- The literal model id sent with every request; pin a versioned id once a threshold is tuned against it.
Example
>>> Provider("jev", "jev-1.13.0")DecideError
The provider rejected a decision request, or answered one with a body that matches no question.
Usage
DecideError(status, message)Attributes
status-
The HTTP status of the failed response.
message- The provider’s error body, or what about its answer failed to match.
DecideKeyMissing
No API key for the provider: none was passed, its variable is unset, and the Keychain holds none.
Usage
DecideKeyMissing()decide.api_key()
Return the provider’s API key from its environment variable, else from the macOS Keychain.
Usage
decide.api_key(provider, *, timeout=DEFAULT_TIMEOUT)Jev reads TYPESAFE_API_KEY and OpenAI reads OPENAI_API_KEY; on macOS an unset variable falls through to the Keychain item store_key wrote, read when the call is made.
Raises
DecideKeyMissing-
When neither source holds a key.
TimeoutError-
When the Keychain read outlasts
timeout.
decide.store_key()
Store key as the provider’s macOS Keychain item, replacing any earlier one.
Usage
decide.store_key(provider, key)The key reaches security over stdin, never its argv, so no process listing shows it.
Raises
ValueError-
When the key holds characters outside
[A-Za-z0-9._-]. subprocess.CalledProcessError-
When
securityrefuses the write.