Task Queue

The tasks the agent has lined up (running, waiting, done, failed) in run order, with reorder, pause, cancel and approve.

Pattern

≈ 1,087 tokens per use (tool 553 · guidance 278 · typical payload 256)How token costs are estimated

Example: Task Queue

What have you got lined up for this afternoon?

Queued for this afternoon

00123456789 done
Working nowSummarise the Q3 support tickets212 of 340 tickets read

Up next

  1. 1 of 4: Draft renewal emails for Orchard accounts~4 min · 9 accounts
  2. 2 of 4: Update the board deck with October numbers~6 min · 12 slides
  3. 3 of 4: Check the help centre for broken links~3 min · 180 pages
  4. 4 of 4: Match September invoices to payments~5 min · 64 invoices
  • Failed: Export the survey resultsSurvey tool asked to sign in again.

Runs one task at a time.

When to use

  • The agent has several separate tasks lined up to run one after another, and the user may want a say in the order.
  • The user asks what the agent is working on next, or to change the order, pause or drop something it queued.

When not to use

How the agent should use it

  • Pass every task from the runtime with its real state (running, waiting, done, failed), and keep ids stable as states change.
  • List waiting tasks in run order. Give each a short detail such as "~4 min · 9 accounts".
  • Add progress (0–1) to a running task that can measure it, and a plain error to a failed one.
  • Turn off what the runtime can't do with canReorder, canPause or canCancel: false.
  • Treat every result as a command: act on it, then send updated props. The component never assumes a command was applied.
  • On approve, run the waiting tasks in exactly the returned order. After pause, show the task as waiting again.

Interaction

  • Working now shows the running task with a spinner, its progress and Pause and Cancel buttons.
  • Up next is a numbered list. Each row has Move up, Move down and Cancel buttons (44px targets, labelled with the task and its position); focus stays on the moved task and each move is announced.
  • Approve order sends the order the user settled on; Reset order appears once it differs from the agent's. After approving, the order locks and a record takes focus.
  • Pause and cancel mark the task "Pausing…" or "Cancelling…" until the host sends its new state. A task being cancelled is left out of an approved order.
  • Failed tasks stay in view with their error; finished ones fold under Finished. While streaming, tasks arrive one by one and controls are disabled.

Installation

npx shadcn@latest add https://your-site.com/r/task-queue.json

Usage

app/api/chat/route.ts
import { tool } from "ai"
import { taskQueueTool } from "@/components/genui/task-queue.schema"

const tools = {
  [taskQueueTool.name]: tool({
    description: taskQueueTool.description,
    inputSchema: taskQueueTool.inputSchema,
  }),
}
components/message.tsx
import { TaskQueue } from "@/components/genui/task-queue"

function ToolPart({ part, addToolResult }) {
  if (part.type !== "tool-show_queue") return null

  return (
    <TaskQueue
      {...part.input}
      status={part.state === "input-streaming" ? "streaming" : undefined}
      result={part.state === "output-available" ? part.output : undefined}
      onResult={(result) =>
        addToolResult({
          tool: "show_queue",
          toolCallId: part.toolCallId,
          output: result,
        })
      }
    />
  )
}

The result is one command:

{ action: "approve", order: ["deck", "renewals", "links", "invoices"] }
{ action: "pause", taskId: "tickets" }
{ action: "cancel", taskId: "links" }

Schema

PropTypeNotes
titlestringThe queue's name
tasks{ id, title, detail?, state, progress?, error? }[]1–20. Data-bound. Waiting tasks in run order
notestring?One quiet line under the list
canReorder, canPause, canCancelboolean?Default true
approveLabelstring?Default Approve order

Host props: status (streaming, ready), onResult, result and className.

Source

On this page