Skip to content
Français

defineDecisionTask

import { defineDecisionTask } from "@elie-laloum/outpost";

Declare a sandbox-free decision task using existing workflow dependencies, retries, deadlines, caches and checkpoints. Each executed attempt computes its state and reports usage synchronously, including valid receipts for rejected truncations.

Complete example and detailed rules.

  • optionsRequired
    DecisionTaskOptions<Q>
    Fixed decision configuration and existing workflow controls; state can be computed from dependencies.
  • options.retryOptional
    Retry | undefined
    Retry policy for failed attempts; without it the task runs once. A retried attempt repeats its side effects.
  • options.cacheOptional
    TaskCacheOptions | undefined
    Result cache: a hit restores the stored lossless JSON value with no attempt, usage or side effects. On a miss, a result that is not lossless JSON fails the task. Rejected on gates, interactions and dispatch-result tasks.
  • options.keyRequired
    string
    Unique key in the workflow, matching [A-Za-z0-9][A-Za-z0-9._-]*. Records, events and checkpoints identify the task by it.
  • options.afterOptional
    readonly Task<unknown>[] | undefined
    Tasks that must be done before this one starts, default none; only these can be read with context.value().
  • options.conditionOptional
    ((context: TaskContext) => boolean | Promise<boolean>) | undefined
    Evaluated with attempt 0 before the task runs, including when a later start() resumes it; false ends the task as skipped, which skips its dependents.
  • options.timeoutMsOptional
    number | undefined
    Deadline in milliseconds for each attempt, a positive integer up to 2147483647. Expiry aborts context.signal and fails the attempt, which retry may repeat.
  • options.decisionRequired
    Decision<Q>
    Frozen typed question declaration created with defineDecision.
  • options.modelRequired
    string
    Nonempty decision model name, without generation or reasoning settings.
  • options.providerRequired
    DecisionProvider
    Decision provider that performs this evaluation.
  • options.allowTruncatedOptional
    boolean | undefined
    False by default; true accepts a reported truncation while retaining its flag in the result.
  • options.stateRequired
    DecisionState | ((context: TaskContext) => DecisionState | Promise<DecisionState>)
    Static lossless JSON state or a synchronous/asynchronous TaskContext callback, resolved on each executed attempt.

Task<DecisionResult<Q>>

export declare function defineDecisionTask<const Q extends DecisionQuestions>(
  options: DecisionTaskOptions<Q>,
): Task<DecisionResult<Q>>;