Background Tasks

Spawn, monitor, and cancel long-running agent tasks.

Overview

Background tasks let you spawn long-running agent operations that execute asynchronously. Instead of waiting for a streaming response, you can create a task, check its status, and retrieve results when ready. Tasks are useful for batch operations, scheduled synthesis, or any workflow where you don't need real-time streaming.

For live progress on a running task (phase changes, progress %, messages), subscribe to GET /api/tasks/{task_id}/progress — see the Task Progress (SSE) page. The spawn/list/get/cancel routes on this page are the transactional control plane; the SSE endpoint is the streaming telemetry.


Spawn Task

POST /api/tasks/spawn

Create and start a new background agent task.

Request Body

NameTypeRequiredDescription
workspace_idUUIDYesWorkspace ID
conversation_idUUIDYesConversation to log the task in
task_typestringYesType of task (e.g., synthesis, recommendation, drafting)
promptstringYesInstructions for the agent
target_document_idUUIDNoDocument to target (for drafting/block tasks)

Response (201 Created)

{
  "id": "b2c3d4e5-...",
  "workspace_id": "550e8400-...",
  "conversation_id": "a7b8c9d0-...",
  "task_type": "synthesis",
  "prompt": "Synthesize all interview sources from Q1",
  "status": "pending",
  "result_summary": null,
  "result_data": null,
  "error": null,
  "created_at": "2026-03-27T14:00:00Z",
  "started_at": null,
  "completed_at": null
}

List Tasks

GET /api/tasks

List background tasks for a workspace.

Query Parameters

NameTypeRequiredDescription
workspace_idUUIDYesWorkspace ID
statusstringNoFilter by status: pending, running, completed, failed, cancelled
limitintegerNoMax results (default: 20, max: 100)
offsetintegerNoPagination offset (default: 0)

Response (200 OK)

{
  "tasks": [ ... ],
  "total": 5
}

Get Task

GET /api/tasks/{task_id}

Get a single task with its current status and results.

Response (200 OK)

{
  "id": "b2c3d4e5-...",
  "workspace_id": "550e8400-...",
  "task_type": "synthesis",
  "prompt": "Synthesize all interview sources from Q1",
  "status": "completed",
  "result_summary": "Extracted 12 insights across 5 themes",
  "result_data": {
    "insight_ids": ["uuid-1", "uuid-2"],
    "summary": "Key themes include..."
  },
  "error": null,
  "created_at": "2026-03-27T14:00:00Z",
  "started_at": "2026-03-27T14:00:02Z",
  "completed_at": "2026-03-27T14:00:45Z"
}

Cancel Task

POST /api/tasks/{task_id}/cancel

Cancel a pending or running task. Completed or failed tasks cannot be cancelled.

Response (200 OK)

Returns the task with status: "cancelled".


Task Status Flow

pending → running → completed
                  → failed
pending → cancelled
running → cancelled
StatusDescription
pendingTask created, waiting to start
runningAgent is actively executing
completedFinished successfully — check result_summary and result_data
failedExecution failed — check error field
cancelledCancelled by user

Was this helpful?