Skip to content
Français

defineInteractiveAgentTask

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

Declare an agent dialogue that asks humans questions between turns. Each turn runs in a new sandbox on a retained named branch and continues the captured conversation; a question leaves the task waiting-input until start() receives an answer. Requires a checkpointed run and throws with code configuration for an agent without portable capture and resume.

Complete example and detailed rules.

  • optionsRequired
    InteractiveAgentTaskOptions
    Agent, repository, authorized respondents and bounded dialogue settings.
  • options.keyRequired
    string
    Stable workflow task key; also participates in the retained branch identity.
  • options.afterOptional
    readonly Task<unknown>[] | undefined
    Dependencies that must finish successfully before the first turn.
  • options.repositoryRequired
    string
    Host Git checkout containing the retained worktree and default conversation storage; must remain accessible on resume.
  • options.agentRequired
    Agent
    Agent with portable conversation capture and resume; otherwise defineInteractiveAgentTask() throws with code configuration.
  • options.briefRequired
    string
    Literal initial instructions; human replies are supplied separately on subsequent turns. Exact injected text and customization limits.
  • options.actorsRequired
    readonly string[]
    Nonempty unique identifiers allowed to answer; the application must authenticate their users.
  • options.sandboxProviderOptional
    SandboxProvider | undefined
    Provider that allocates a new sandbox for each turn, default createDockerSandboxProvider().
  • options.bootstrapOptional
    boolean | undefined
    Whether each turn’s sandbox may install a missing CLI agent, default true.
  • options.conversationHomeOptional
    string | undefined
    Host home used to locate captured native conversations across turns.
  • options.maxTurnsOptional
    number | undefined
    Maximum completed agent turns, including the final result; defaults to 12. A question at the last turn fails instead of waiting indefinitely.
  • options.timeoutMsOptional
    number | undefined
    Cooperative deadline for each executing task attempt, excluding time waiting for a human answer.

Variant 2 — FileInteractiveAgentTaskOptions

Section titled “Variant 2 — FileInteractiveAgentTaskOptions”
  • optionsRequired
    FileInteractiveAgentTaskOptions
    Agent, repository, authorized respondents and bounded dialogue settings.
  • options.workspaceSourceRequired
    FileWorkspaceSource
    Declared source for an owned resource; mutually exclusive with borrowing an open workspace.
  • options.sandboxProviderRequired
    SandboxProvider
    Execution provider with the required file binding capability; legacy providers remain usable for Git.
  • options.agentRequired
    Agent
    Agent with portable conversation capture and resume; otherwise defineInteractiveAgentTask() throws with code configuration.
  • options.keyRequired
    string
    Stable workflow task key; also participates in the retained branch identity.
  • options.afterOptional
    readonly Task<unknown>[] | undefined
    Dependencies that must finish successfully before the first turn.
  • options.timeoutMsOptional
    number | undefined
    Cooperative deadline for each executing task attempt, excluding time waiting for a human answer.
  • options.briefRequired
    string
    Literal initial instructions; human replies are supplied separately on subsequent turns. Exact injected text and customization limits.
  • options.actorsRequired
    readonly string[]
    Nonempty unique identifiers allowed to answer; the application must authenticate their users.
  • options.maxTurnsOptional
    number | undefined
    Maximum completed agent turns, including the final result; defaults to 12. A question at the last turn fails instead of waiting indefinitely.
  • options.signalOptional
    AbortSignal | undefined
    Cancellation signal propagated to the operation and its process group; reusable sandboxes remain usable.
  • options.hooksOptional
    LifecycleHooks | undefined
    Declared workspaceReady, hostReady and sandboxReady preparation commands.
  • options.recoveryOptional
    FileWorkspaceRecoveryAuthorization | undefined
    Explicit stopped-process recovery authorization; interrupted replay remains a separate workflow decision.
  • options.storageQuotaOptional
    Omit<StorageReservationOptions, "signal"> | undefined
    Admission reservation through Transport; coordinates cooperating writers without enforcing a physical disk quota.
  • options.inputsOptional
    readonly WorkspaceInput[] | undefined
    Explicit file inputs; JSON workflow parameters are never implicitly written to disk.
  • options.runtimeOptional
    WorkspaceRuntimeOptions | undefined
    Control directory and logical namespace, separate from the workspace files.
  • options.pathsOptional
    readonly string[] | undefined
    Explicit relative path selection; copy selection does not implicitly apply .gitignore.
  • options.retentionOptional
    WorkspaceRetention | undefined
    run cleans successful owned work, local retains it, portable additionally requires an explicit Transport and namespace.

Templates below preserve the English text sent to the model. ${…} marks runtime substitutions, not brief template syntax.

Every Git or file workspace dialogue turn appends this protocol after the initial brief, the latest human answer or the quota-resume instruction:

This is a durable interactive task. End each turn with exactly one JSON response inside <interaction> and </interaction>.
When human input is needed, return {"kind":"question","question":"Your question","choices":["Optional choice"],"allowFreeText":true}. Omit choices for free text. Set allowFreeText to false only when choices are supplied and the user must choose one.
When the entire task is complete, return {"kind":"completed","output":<your JSON result>}.
Ask one focused question at a time and adapt subsequent questions to the answers in this conversation. Do not invent a human answer. Do not wait for terminal input.
The sandbox is recreated between turns. Keep required project files in the repository. Do not switch branches, integrate or push changes. The workflow will retain the workspace.

After a human answer, the input preceding the protocol is:

Human answer (JSON): ${answerJSON}

answerJSON is JSON.stringify(interaction.answer.value). After a quota interruption, the fixed quota-resume instruction replaces this input.

Dispatch also appends the final-answer format instructions, using tag: "interaction", format: "json" and the following input schema. The internal response contract allows one repair attempt.

{
  "anyOf": [
    {
      "type": "object",
      "properties": {
        "kind": {
          "const": "question"
        },
        "question": {
          "type": "string",
          "pattern": "\\S"
        },
        "choices": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "\\S"
          },
          "minItems": 1,
          "uniqueItems": true
        },
        "allowFreeText": {
          "type": "boolean"
        }
      },
      "required": ["kind", "question"],
      "if": {
        "properties": {
          "allowFreeText": {
            "const": false
          }
        },
        "required": ["allowFreeText"]
      },
      "then": {
        "required": ["choices"]
      }
    },
    {
      "type": "object",
      "properties": {
        "kind": {
          "const": "completed"
        },
        "output": {}
      },
      "required": ["kind", "output"]
    }
  ]
}

The protocol, answer prefix, schema and repair count are fixed. brief supplies the task goal; it does not replace the protocol. There is no dedicated override for these instructions.

Implementation: interactive-task.constants.ts · interactive-task-execution.ts · file-interactive-task.ts.

Task<InteractiveAgentResult> · Task<FileInteractiveAgentResult>

export declare function defineInteractiveAgentTask(
  options: InteractiveAgentTaskOptions,
): Task<InteractiveAgentResult>;

export declare function defineInteractiveAgentTask(
  options: FileInteractiveAgentTaskOptions,
): Task<FileInteractiveAgentResult>;