defineAgentTask
Purpose and behavior
Section titled “Purpose and behavior”Declare a task that runs sandbox.dispatch() in a borrowed sandbox; request builds dispatch options at each attempt. By default it returns the full dispatch result. select optionally projects the result after usage accounting and may be asynchronous; return lossless JSON for checkpoints. The sandbox remains caller-owned and cache stays rejected, including with select. Selector failures follow the task’s configured retry policy.
Complete example and detailed rules.
Parameters and properties
Section titled “Parameters and properties”Variant 1 — Omit<TaskOptions<Output>, "cache" | "perform"> & FileAgentTaskOptions<T> & TaskResultSelection<FileDispatchResult<T>, Output>
Section titled “Variant 1 — Omit<TaskOptions<Output>, "cache" | "perform"> & FileAgentTaskOptions<T> & TaskResultSelection<FileDispatchResult<T>, Output>”optionsRequiredOmit<TaskOptions<Output>, "cache" | "perform"> & FileAgentTaskOptions<T> & TaskResultSelection<FileDispatchResult<T>, Output>Task scheduling settings, existing sandbox and dispatch-request factory.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.quotaResumeOptionalQuotaResumePolicy | undefinedOpt-in native conversation continuation after quota pause, without consuming a task retry.options.sandboxRequiredFileSandboxSandbox bound to this workspace; closing it leaves a borrowed workspace open.options.requestRequired(context: TaskContext) => DispatchOptions<T>Build the declared command or agent request from the current task context before acquisition.options.selectRequired(result: FileDispatchResult<T>) => Output | Promise<Output>Project the completed dispatch result into the task output after usage accounting. Return lossless JSON for checkpointed workflows. This does not enable caching or change sandbox ownership.
Variant 2 — Omit<TaskOptions<Output>, "cache" | "perform"> & AgentTaskOptions<T> & TaskResultSelection<DispatchResult<T>, Output>
Section titled “Variant 2 — Omit<TaskOptions<Output>, "cache" | "perform"> & AgentTaskOptions<T> & TaskResultSelection<DispatchResult<T>, Output>”optionsRequiredOmit<TaskOptions<Output>, "cache" | "perform"> & AgentTaskOptions<T> & TaskResultSelection<DispatchResult<T>, Output>Task scheduling settings, existing sandbox and dispatch-request factory.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.sandboxRequiredSandboxExisting caller-owned sandbox reused by the task; the task does not close it.options.requestRequired(context: TaskContext) => DispatchOptions<T>Build dispatch options from task dependencies for the existing sandbox.options.quotaResumeOptionalQuotaResumePolicy | undefinedAfter a quota pause, continue the captured conversation with a resume instruction (continue, default) or send the original request again (restart). The original request is sent when the agent cannot resume or is a fallback agent, or when the request sets continuation or several passes.options.selectRequired(result: DispatchResult<T>) => Output | Promise<Output>Project the completed dispatch result into the task output after usage accounting. Return lossless JSON for checkpointed workflows. This does not enable caching or change sandbox ownership.
Variant 3 — Omit<TaskOptions<Output>, "cache" | "perform"> & MixedAgentTaskOptions<T> & TaskResultSelection<DispatchResult<T> | FileDispatchResult<...>, Output>
Section titled “Variant 3 — Omit<TaskOptions<Output>, "cache" | "perform"> & MixedAgentTaskOptions<T> & TaskResultSelection<DispatchResult<T> | FileDispatchResult<...>, Output>”optionsRequiredOmit<TaskOptions<Output>, "cache" | "perform"> & MixedAgentTaskOptions<T> & TaskResultSelection<DispatchResult<T> | FileDispatchResult<T>, Output>Task scheduling settings, existing sandbox and dispatch-request factory.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.sandboxRequiredFileSandbox | SandboxSandbox bound to this workspace; closing it leaves a borrowed workspace open.options.requestRequired(context: TaskContext) => DispatchOptions<T>Build the declared command or agent request from the current task context before acquisition.options.quotaResumeOptionalQuotaResumePolicy | undefinedOpt-in native conversation continuation after quota pause, without consuming a task retry.options.selectRequired(result: DispatchResult<T> | FileDispatchResult<T>) => Output | Promise<Output>Project the completed dispatch result into the task output after usage accounting. Return lossless JSON for checkpointed workflows. This does not enable caching or change sandbox ownership.
Variant 4 — Omit<TaskOptions<FileDispatchResult<T>>, "cache" | "perform"> & FileAgentTaskOptions<T>
Section titled “Variant 4 — Omit<TaskOptions<FileDispatchResult<T>>, "cache" | "perform"> & FileAgentTaskOptions<T>”optionsRequiredOmit<TaskOptions<FileDispatchResult<T>>, "cache" | "perform"> & FileAgentTaskOptions<T>Task scheduling settings, existing sandbox and dispatch-request factory.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.quotaResumeOptionalQuotaResumePolicy | undefinedOpt-in native conversation continuation after quota pause, without consuming a task retry.options.sandboxRequiredFileSandboxSandbox bound to this workspace; closing it leaves a borrowed workspace open.options.requestRequired(context: TaskContext) => DispatchOptions<T>Build the declared command or agent request from the current task context before acquisition.
Variant 5 — Omit<TaskOptions<DispatchResult<T>>, "cache" | "perform"> & AgentTaskOptions<T>
Section titled “Variant 5 — Omit<TaskOptions<DispatchResult<T>>, "cache" | "perform"> & AgentTaskOptions<T>”optionsRequiredOmit<TaskOptions<DispatchResult<T>>, "cache" | "perform"> & AgentTaskOptions<T>Task scheduling settings, existing sandbox and dispatch-request factory.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.sandboxRequiredSandboxExisting caller-owned sandbox reused by the task; the task does not close it.options.requestRequired(context: TaskContext) => DispatchOptions<T>Build dispatch options from task dependencies for the existing sandbox.options.quotaResumeOptionalQuotaResumePolicy | undefinedAfter a quota pause, continue the captured conversation with a resume instruction (continue, default) or send the original request again (restart). The original request is sent when the agent cannot resume or is a fallback agent, or when the request sets continuation or several passes.
Variant 6 — Omit<TaskOptions<DispatchResult<T> | FileDispatchResult<T>>, "cache" | "perform"> & MixedAgentTaskOptions<T>
Section titled “Variant 6 — Omit<TaskOptions<DispatchResult<T> | FileDispatchResult<T>>, "cache" | "perform"> & MixedAgentTaskOptions<T>”optionsRequiredOmit<TaskOptions<DispatchResult<T> | FileDispatchResult<T>>, "cache" | "perform"> & MixedAgentTaskOptions<T>Task scheduling settings, existing sandbox and dispatch-request factory.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.sandboxRequiredFileSandbox | SandboxSandbox bound to this workspace; closing it leaves a borrowed workspace open.options.requestRequired(context: TaskContext) => DispatchOptions<T>Build the declared command or agent request from the current task context before acquisition.options.quotaResumeOptionalQuotaResumePolicy | undefinedOpt-in native conversation continuation after quota pause, without consuming a task retry.
Returns
Section titled “Returns”Task<Output> · Task<FileDispatchResult<T>> · Task<DispatchResult<T>> · Task<DispatchResult<T> | FileDispatchResult<T>>

