Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.xpander.ai/llms.txt

Use this file to discover all available pages before exploring further.

The Tasks module manages the full lifecycle of task executions: the unit of work an agent does in response to a prompt. List existing tasks, load a specific one, create new ones, patch their state, or terminate them.
from xpander_sdk import Tasks, AgentExecutionStatus

tasks = Tasks()

# List
items = await tasks.alist(agent_id="agent-123")

# Load
task = await tasks.aget(task_id="task_xyz")

# Create
task = await tasks.acreate(agent_id="agent-123", prompt="Hello!")

# Update
await tasks.aupdate(task_id=task.id, status=AgentExecutionStatus.Completed, result="done")

# Stop
await tasks.astop(task_id=task.id)

Constructor

Tasks(configuration: Optional[Configuration] = None)
ParameterTypeDefaultDescription
configurationConfigurationNoneSDK configuration. Falls back to env vars.

Module methods

MethodReturnsWhat it does
alist / listlist[TasksListItem]Tasks for a given agent, optionally filtered.
alist_user_tasks / list_user_taskslist[TasksListItem]Tasks for a given end-user across all agents.
aget / getTaskLoad a full task by id.
acreate / createTaskCreate a new task. (Same as Agent.acreate_task, but accepts agent_id directly.)
aupdate / updateTaskPatch task fields (status, result, payload extension).
astop / stopTaskTerminate a running task.

Task instance methods

The Task object returned by these calls has its own set of methods for runtime control:
MethodWhat it does
asave / savePersist local mutations back to the platform.
aset_status / set_statusSet status (and optionally result) and save in one call.
astop / stopTerminate this task.
areload / reloadRe-fetch the latest task state from the platform.
aevents / eventsStream TaskUpdateEvents via SSE.
aget_activity_log / get_activity_logFull message / tool-call / reasoning thread.
areport_metrics / report_metricsPush token counts and other metrics back to the platform.
get_files / get_images / get_human_readable_files / to_messageConvenience helpers for Agno integration.
For the full attribute list, see the Task class reference.

Lifecycle

Pending  →  Executing  →  Completed
                ↓             ↓
              Paused        Failed
                ↓             ↓
              Error         Stopped
StatusMeaning
PendingCreated but not yet picked up by a worker.
ExecutingWorker is running the task.
PausedWorker paused (HITL approval, deep-planning question).
CompletedFinished successfully.
ErrorWorker raised an exception.
FailedTask didn’t complete successfully (lower-level than Error).
StoppedManually terminated.
The AgentExecutionStatus enum (used everywhere status appears) has these values: Pending, Executing, Paused, Error, Failed, Completed, Stopped. String values are lowercase.

Class-level method

Task.areport_external_task(...) is a @classmethod that records an externally-executed run without going through Backend. It mirrors Backend.areport_external_task and exists for cases where you don’t have a Backend instance handy. See report_external_task.