Skip to main content
Tasks are the gateway’s durable automation layer. A task can run immediately, wait for a schedule, repeat on an interval or cron expression, depend on another task, or be triggered manually or externally. With the agent executor, it can create a subagent thread with its own prompt, model, context policy, tool policy, result contract, and review policy. Clients use the Tasks API for two different experiences: user-facing automation UI and internal agent orchestration. In both cases the gateway owns task state, run state, retries, write locks, delivery state, and the lineage between parent work and subagent threads. Collaborative Composer submissions are also represented by the task runtime. They are not a third client method: the normal turn submission creates detached task work with a frozen TaskComposerWork launch record, a child conversation, and a delivery back to the originating thread. Use the explicit Tasks API when you need to create or inspect a durable task contract; use the Threads and Turns APIs to render the conversation and the task card created by a Composer request.

Methods

crates/protocol also defines TaskUpdateParams, TaskUpdateResponse, and a task/update method constant for task-service update contracts. The current gateway JSON-RPC dispatcher does not expose task/update as a client-callable method. Task updates can still happen through the model-facing task_update tool and task service, and clients observe them through task/updated plus task/tree/changed.

Creating an agent task

task/create uses mostly camelCase payload fields. The gateway creates the task, stores the trigger, and may also create a run immediately depending on the trigger.
Important create fields: Response:
TaskStatus values serialize as snake_case: draft, scheduled, queued, running, waiting, completed, failed, cancelled. Many task payloads use camelCase field names while enum values use snake_case, so clients should follow the generated schema rather than guessing casing.

Trigger specs

The trigger.spec object is tagged by kind. Example cron trigger:
Dependency trigger policy uses mode values all_succeeded, any_succeeded, or all_terminal and a dependsOnTaskIds list.

Subagents

agentSpec tells the gateway to create a child thread and run it with bounded context and tools. The UI is only one way to request this work. Context policy modes are inherit_parent, last_n_turns, summary_only, empty, and custom. Write modes are read_only, workspace_write, scoped_write, and full_access. Result formats are text, markdown, json, and artifact. Callers usually omit reviewPolicy. The gateway applies the default parent-agent review policy to immediate attached agent tasks. Direct reviewPolicy overrides in task/create require gateway.tasks.review.allow_task_create_review_policy = true. When a task creates a child thread, task events include child thread lineage. The child thread is hidden from the normal sidebar, but clients can show the subagent’s work in the parent task tree and can load the child conversation through Threads API and Turns API.

Result review

Agent tasks can require review before a child result becomes the final run result. For attached subagent work, the default review mode is parent-agent review with explicit acceptance and five revision rounds. Review policy fields: When a child turn finishes, the gateway creates a TaskResultCandidate. If review is required, the candidate status is pending_review, the run/execution waits for review, and task/wait can return it under reviewRequired. The parent accepts a candidate with task/accept:
Accepting creates a TaskResultReviewEvent with decision = accept, marks the candidate accepted, stores the accepted result on the run, and completes the task when its lifecycle policy allows it. The parent requests changes with task/revise:
Revising creates a review event with decision = request_changes, marks the current candidate rejected, creates a new TaskRunTurn with kind = revision, and dispatches the same child thread again with the feedback. The next child turn produces a new candidate. TaskResultReviewEvent is an audit log rather than a snapshot of the latest state. It records reviewer kind (parent_agent, review_agent, user, runtime_auto, or system), event kind (advisory, decision, override, or system_auto), decision, feedback, optional reviewer thread/turn/user/agent ids, and the next revision turn when one is created.

Policies

Lifecycle policy controls what happens to child tasks when parent work ends:
Delivery policy controls where task results go:
Retry, timeout, and concurrency policies are optional, but they are what turn tasks from “run this once” into reliable automation:
Write locks are produced by the task runtime when a task needs exclusive write access to a workspace or path. Clients normally display them in diagnostics rather than creating them directly.

Reading tasks

Use task/get for a detail view:
Use task/list for a workspace list:
task/tree returns a root TaskTree with nested children. Use it when showing a delegated workflow, because a parent task can fan out into child tasks and each child can have its own run, agent spec, dependencies, write locks, and child thread lineage.

Events

task/events returns durable task events with monotonically increasing sequence.
Each event has eventType, payload, createdAt, optional runId, optional threadId, and optional turnId. The payload is tagged by kind, with variants for task creation, trigger creation, task updates, run start/completion/failure, retries, cancellation, delivery, child thread linking, depth limits, and write-lock state. Use afterSequence for incremental polling after reconnect. Live clients should also listen to task notifications.

Waiting

task/wait is useful for automation clients and for a parent agent waiting on delegated work.
Response groups terminal and pending work:
Wait modes are all_terminal, any_terminal, all_terminal_or_review_required, and any_terminal_or_review_required. A timed-out wait does not cancel the task; it only returns control to the caller. Parent-agent orchestration normally uses a review-aware wait mode. When a candidate needs a decision, reviewRequired contains the task/run item, the candidate, the review policy, revision limits, and allowed actions:
If remainingRevisionRounds is 0, allowedActions omits task_revise and revisionBlockedReason explains why. The parent should then accept, cancel, or create a separate follow-up task.

Cancelling and lifecycle changes

Cancel scope controls how far cancellation propagates:
Use task/pause and task/resume for scheduled or recurring tasks. Use task/reschedule to replace the trigger. Use task/detach when a child task should keep running independently of its parent.

Agenda

task/agenda is optimized for “what is coming up” and “what recently ran” screens.
Agenda items include the task, trigger, latest run, latest delivery, goal preview, next/last fire timestamps, recurring flag, delivery mode, and result/error previews.

Deliveries

Delivery records track result handoff after a run: owner thread posts, target thread posts, user notifications, and webhook attempts.
The response contains deliveries and attempts. Use it for a delivery/debug panel and for retry/error visibility in scheduled automation.

Notifications

Task notifications use the same event names as durable task events: Notification params include a context object with workspaceId, taskId, optional runId, optional parent/root ids, optional thread/turn ids, eventId, and sequence. Treat notifications as streaming state changes and use read methods to rebuild exact state when needed.

How tasks relate to turns

Agent turns can create tasks, tasks can create child threads, and child turns can report results back to parent tasks. For rendering a conversation that includes delegated work, combine Threads API thread/timeline/page, Turns API turn/work/page, task/tree, and task/events. For a task automation screen, use task/agenda, task/list, task/get, and task/deliveries. For an agent orchestration screen, use task/tree, task/events, and child thread links.