defineTask
Purpose and behavior
Section titled “Purpose and behavior”Declare a workflow node from its key, after dependencies and perform callback, with optional condition, retry, timeoutMs, cache, gate or interaction. It allocates no sandbox, and nothing runs until Workflow.start(). Throws on a key outside [A-Za-z0-9][A-Za-z0-9._-]*, invalid retry or cache settings, or a cache combined with a gate or interaction. Named inputs add dependency edges and supply inferred values to perform through context.inputs. They combine with after without duplicate edges; the mapping is copied at declaration.
Complete example and detailed rules.
Parameters and properties
Section titled “Parameters and properties”Variant 1 — TaskInputsOptions<T, Inputs>
Section titled “Variant 1 — TaskInputsOptions<T, Inputs>”optionsRequiredTaskInputsOptions<T, Inputs>Task key, dependencies and perform callback, with optional condition, retry, timeout, cache, gate or interaction.options.cacheOptionalTaskCacheOptions | undefinedResult 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.retryOptionalRetry | undefinedRetry policy for failed attempts; without it the task runs once. A retried attempt repeats its side effects.options.gateOptionalWorkflowGate | undefinedPersisted approval or pause definition; execution requires a checkpoint and a matching trusted decision.options.keyRequiredstringUnique key in the workflow, matching [A-Za-z0-9][A-Za-z0-9._-]*. Records, events and checkpoints identify the task by it.options.afterOptionalreadonly Task<unknown>[] | undefinedTasks that must be done before this one starts, default none; only these can be read with context.value().options.interactionOptionalTaskInteraction | undefinedOpt-in durable human-input contract; requires checkpointed scheduling and cannot be combined with a gate.options.conditionOptional((context: TaskContext) => boolean | Promise<boolean>) | undefinedEvaluated 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.timeoutMsOptionalnumber | undefinedDeadline in milliseconds for each attempt, a positive integer up to 2147483647. Expiry aborts context.signal and fails the attempt, which retry may repeat.options.inputsRequiredInputsNamed task dependencies whose typed outputs are passed to perform as context.inputs. Combined with after without duplicate edges.options.performRequired(context: TaskContext & { readonly inputs: TaskInputValues<Inputs>; }) => T | Promise<T>Run the task with its named dependency outputs and ordinary task context.
Variant 2 — TaskOptions<T>
Section titled “Variant 2 — TaskOptions<T>”optionsRequiredTaskOptions<T>Task key, dependencies and perform callback, with optional condition, retry, timeout, cache, gate or interaction.options.cacheOptionalTaskCacheOptions | undefinedResult 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.retryOptionalRetry | undefinedRetry policy for failed attempts; without it the task runs once. A retried attempt repeats its side effects.options.gateOptionalWorkflowGate | undefinedPersisted approval or pause definition; execution requires a checkpoint and a matching trusted decision.options.keyRequiredstringUnique key in the workflow, matching [A-Za-z0-9][A-Za-z0-9._-]*. Records, events and checkpoints identify the task by it.options.interactionOptionalTaskInteraction | undefinedOpt-in durable human-input contract; requires checkpointed scheduling and cannot be combined with a gate.options.performRequired(context: TaskContext) => T | Promise<T>Runs each attempt and returns the task output; with a checkpoint, the output must be lossless JSON or undefined. Stop work when context.signal aborts.options.conditionOptional((context: TaskContext) => boolean | Promise<boolean>) | undefinedEvaluated 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.timeoutMsOptionalnumber | undefinedDeadline in milliseconds for each attempt, a positive integer up to 2147483647. Expiry aborts context.signal and fails the attempt, which retry may repeat.options.afterOptionalreadonly Task<unknown>[] | undefinedTasks that must be done before this one starts, default none; only these can be read with context.value().

