Skip to content

DecisionModel

Defined in: src/decisions/decision-model.ts:20

Abstract base for anything that can answer closed questions.

The public ask opens a decision span, validates the question map, delegates to the subclass _ask, records usage and the answer set as span attributes/events, and closes the span. Every implementation is traced identically. Given an invocationContext, ask also adds the reported usage to that request once _ask returns.

new DecisionModel(): DecisionModel;

DecisionModel

ask<Q>(
state,
questions,
options?
): Promise<DecisionResult<Q>>;

Defined in: src/decisions/decision-model.ts:34

Ask one or more closed questions over the given state.

Type Parameter
Q extends Record<string, Question<"boolean" | readonly string[]>>
ParameterTypeDescription
stateDecisionInputA plain string, a one-shot content list, or a message history.
questionsQMap of identifier → question. The returned answers object is keyed off this same map and statically narrowed per question.
options?AskOptionsPer-call options, such as the request to add the decision’s usage to.

Promise<DecisionResult<Q>>

A DecisionResult whose answers are statically narrowed from each question’s choices.

Error if questions is empty or contains an invalid question, choices, or uncertainty.

TypeError if options.invocationContext was not created by the SDK.


abstract protected _ask<Q>(state, questions): Promise<DecisionResult<Q>>;

Defined in: src/decisions/decision-model.ts:80

Implementation-specific decision logic. Must return a complete DecisionResult, including metadata.latencyMs sourced from the underlying model provider.

Type Parameter
Q extends Record<string, Question<"boolean" | readonly string[]>>
ParameterType
stateDecisionInput
questionsQ

Promise<DecisionResult<Q>>