Skip to content
Français

defineAgentTask

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

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.

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>”
  • optionsRequired
    Omit<TaskOptions<Output>, "cache" | "perform"> & FileAgentTaskOptions<T> & TaskResultSelection<FileDispatchResult<T>, Output>
    Task scheduling settings, existing sandbox and dispatch-request factory.
  • options.retryOptional
    Retry | undefined
    Retry policy for failed attempts; without it the task runs once. A retried attempt repeats its side effects.
  • options.gateOptional
    WorkflowGate | undefined
    Persisted approval or pause definition; execution requires a checkpoint and a matching trusted decision.
  • 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.interactionOptional
    TaskInteraction | undefined
    Opt-in durable human-input contract; requires checkpointed scheduling and cannot be combined with a gate.
  • 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.quotaResumeOptional
    QuotaResumePolicy | undefined
    Opt-in native conversation continuation after quota pause, without consuming a task retry.
  • options.sandboxRequired
    FileSandbox
    Sandbox 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>”
  • optionsRequired
    Omit<TaskOptions<Output>, "cache" | "perform"> & AgentTaskOptions<T> & TaskResultSelection<DispatchResult<T>, Output>
    Task scheduling settings, existing sandbox and dispatch-request factory.
  • options.retryOptional
    Retry | undefined
    Retry policy for failed attempts; without it the task runs once. A retried attempt repeats its side effects.
  • options.gateOptional
    WorkflowGate | undefined
    Persisted approval or pause definition; execution requires a checkpoint and a matching trusted decision.
  • 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.interactionOptional
    TaskInteraction | undefined
    Opt-in durable human-input contract; requires checkpointed scheduling and cannot be combined with a gate.
  • 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.sandboxRequired
    Sandbox
    Existing 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.quotaResumeOptional
    QuotaResumePolicy | undefined
    After 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>”
  • optionsRequired
    Omit<TaskOptions<Output>, "cache" | "perform"> & MixedAgentTaskOptions<T> & TaskResultSelection<DispatchResult<T> | FileDispatchResult<T>, Output>
    Task scheduling settings, existing sandbox and dispatch-request factory.
  • options.retryOptional
    Retry | undefined
    Retry policy for failed attempts; without it the task runs once. A retried attempt repeats its side effects.
  • options.gateOptional
    WorkflowGate | undefined
    Persisted approval or pause definition; execution requires a checkpoint and a matching trusted decision.
  • 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.interactionOptional
    TaskInteraction | undefined
    Opt-in durable human-input contract; requires checkpointed scheduling and cannot be combined with a gate.
  • 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.sandboxRequired
    FileSandbox | Sandbox
    Sandbox 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.quotaResumeOptional
    QuotaResumePolicy | undefined
    Opt-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>”
  • optionsRequired
    Omit<TaskOptions<FileDispatchResult<T>>, "cache" | "perform"> & FileAgentTaskOptions<T>
    Task scheduling settings, existing sandbox and dispatch-request factory.
  • options.retryOptional
    Retry | undefined
    Retry policy for failed attempts; without it the task runs once. A retried attempt repeats its side effects.
  • options.gateOptional
    WorkflowGate | undefined
    Persisted approval or pause definition; execution requires a checkpoint and a matching trusted decision.
  • 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.interactionOptional
    TaskInteraction | undefined
    Opt-in durable human-input contract; requires checkpointed scheduling and cannot be combined with a gate.
  • 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.quotaResumeOptional
    QuotaResumePolicy | undefined
    Opt-in native conversation continuation after quota pause, without consuming a task retry.
  • options.sandboxRequired
    FileSandbox
    Sandbox 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>”
  • optionsRequired
    Omit<TaskOptions<DispatchResult<T>>, "cache" | "perform"> & AgentTaskOptions<T>
    Task scheduling settings, existing sandbox and dispatch-request factory.
  • options.retryOptional
    Retry | undefined
    Retry policy for failed attempts; without it the task runs once. A retried attempt repeats its side effects.
  • options.gateOptional
    WorkflowGate | undefined
    Persisted approval or pause definition; execution requires a checkpoint and a matching trusted decision.
  • 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.interactionOptional
    TaskInteraction | undefined
    Opt-in durable human-input contract; requires checkpointed scheduling and cannot be combined with a gate.
  • 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.sandboxRequired
    Sandbox
    Existing 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.quotaResumeOptional
    QuotaResumePolicy | undefined
    After 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>”
  • optionsRequired
    Omit<TaskOptions<DispatchResult<T> | FileDispatchResult<T>>, "cache" | "perform"> & MixedAgentTaskOptions<T>
    Task scheduling settings, existing sandbox and dispatch-request factory.
  • options.retryOptional
    Retry | undefined
    Retry policy for failed attempts; without it the task runs once. A retried attempt repeats its side effects.
  • options.gateOptional
    WorkflowGate | undefined
    Persisted approval or pause definition; execution requires a checkpoint and a matching trusted decision.
  • 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.interactionOptional
    TaskInteraction | undefined
    Opt-in durable human-input contract; requires checkpointed scheduling and cannot be combined with a gate.
  • 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.sandboxRequired
    FileSandbox | Sandbox
    Sandbox 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.quotaResumeOptional
    QuotaResumePolicy | undefined
    Opt-in native conversation continuation after quota pause, without consuming a task retry.

Task<Output> · Task<FileDispatchResult<T>> · Task<DispatchResult<T>> · Task<DispatchResult<T> | FileDispatchResult<T>>

export declare function defineAgentTask<T, Output>(
  options: Omit<TaskOptions<Output>, "perform" | "cache"> &
    FileAgentTaskOptions<T> &
    TaskResultSelection<FileDispatchResult<T>, Output>,
): Task<Output>;

export declare function defineAgentTask<T, Output>(
  options: Omit<TaskOptions<Output>, "perform" | "cache"> &
    AgentTaskOptions<T> &
    TaskResultSelection<DispatchResult<T>, Output>,
): Task<Output>;

export declare function defineAgentTask<T, Output>(
  options: Omit<TaskOptions<Output>, "perform" | "cache"> &
    MixedAgentTaskOptions<T> &
    TaskResultSelection<DispatchResult<T> | FileDispatchResult<T>, Output>,
): Task<Output>;

export declare function defineAgentTask<T>(
  options: Omit<TaskOptions<FileDispatchResult<T>>, "perform" | "cache"> &
    FileAgentTaskOptions<T>,
): Task<FileDispatchResult<T>>;

export declare function defineAgentTask<T>(
  options: Omit<TaskOptions<DispatchResult<T>>, "perform" | "cache"> &
    AgentTaskOptions<T>,
): Task<DispatchResult<T>>;

export declare function defineAgentTask<T>(
  options: Omit<
    TaskOptions<DispatchResult<T> | FileDispatchResult<T>>,
    "perform" | "cache"
  > &
    MixedAgentTaskOptions<T>,
): Task<DispatchResult<T> | FileDispatchResult<T>>;