Using Tasks — Agentuity Documentation

Using Tasks

Track work items with lifecycle management via ctx.task

Create and manage structured work items (bugs, features, epics, tasks) with built-in status tracking, comments, tags, and file attachments. The task service is available via ctx.task in agents and c.var.task in routes.

For concepts, hierarchical task patterns, and when-to-use guidance, see Tasks.

Task Lifecycle

Tasks follow a defined status lifecycle:

StatusDescription
'open'Created, not yet started
'in_progress'Actively being worked on
'done'Work completed
'cancelled'Abandoned

The aliases 'started', 'completed', and 'closed' are normalized automatically to 'in_progress' or 'done'.

create(params)

Create a new task.

ParamTypeRequiredDescription
paramsCreateTaskParamsyesTask creation parameters (see below)

CreateTaskParams fields:

FieldTypeRequiredDescription
titlestringyesTask title (max 1024 chars)
typeTaskTypeyes'epic', 'feature', 'enhancement', 'bug', or 'task'
created_idstringyesID of the creator
descriptionstringnoDetailed description (max 65,536 chars)
metadataRecord<string, unknown>noArbitrary key-value metadata
priorityTaskPriorityno'high', 'medium', 'low', or 'none' (default 'none')
statusTaskStatusnoInitial status (default 'open')
parent_idstringnoParent task ID for hierarchical organization
assigned_idstringnoID of the assigned user
creatorUserEntityRefnoCreator reference (id, name, optional type)
assigneeUserEntityRefnoAssignee reference
projectEntityRefnoProject reference (id, name)
tag_idsstring[]noTag IDs to associate at creation

Returns: Promise<Task>

Example

const task = await ctx.task.create({
  title: 'Investigate slow API response times',
  type: 'bug',
  priority: 'high',
  created_id: 'user-001',
  creator: { id: 'user-001', name: 'Monitor Agent', type: 'agent' },
  description: 'P95 latency exceeded 500ms on /api/search',
  metadata: { endpoint: '/api/search', p95ms: 520 },
});
 
ctx.logger.info('Created task %s: %s', task.id, task.title);

get(id)

Get a task by its ID.

ParamTypeRequiredDescription
idstringyesThe unique task identifier

Returns: Promise<Task | null> -- null if the task does not exist.

Example

const task = await ctx.task.get('tsk_abc123');
if (task) {
  ctx.logger.info('Task %s is %s (priority: %s)', task.id, task.status, task.priority);
}

list(params?)

List tasks with optional filtering and pagination.

ParamTypeRequiredDescription
paramsListTasksParamsnoOptional filter and pagination parameters

ListTasksParams fields (all optional):

FieldTypeDescription
statusTaskStatusFilter by status
typeTaskTypeFilter by type
priorityTaskPriorityFilter by priority
assigned_idstringFilter by assignee
created_idstringFilter by creator
parent_idstringFilter by parent task (get subtasks)
project_idstringFilter by project
tag_idstringFilter by tag
deletedbooleanInclude soft-deleted tasks (default false)
sortstringSort field, prefix with - for descending (e.g., '-created_at')
order'asc' | 'desc'Sort direction
limitnumberMax results to return
offsetnumberResults to skip for pagination

Returns: Promise<ListTasksResult>

interface ListTasksResult {
  tasks: Task[];   // Matching tasks
  total: number;   // Total count before pagination
  limit: number;   // Applied limit
  offset: number;  // Applied offset
}

Example

// List open bugs assigned to an agent
const result = await ctx.task.list({
  status: 'open',
  type: 'bug',
  assigned_id: 'agent-001',
  sort: '-priority',
  limit: 20,
});
 
ctx.logger.info('Found %d of %d bugs', result.tasks.length, result.total);

update(id, params)

Partially update an existing task. Only provided fields are changed.

ParamTypeRequiredDescription
idstringyesThe task ID
paramsUpdateTaskParamsyesFields to update (all optional)

Returns: Promise<Task>

Example

const updated = await ctx.task.update('tsk_abc123', {
  status: 'in_progress',
  assignee: { id: 'agent-002', name: 'Fix Bot', type: 'agent' },
  priority: 'high',
});
 
ctx.logger.info('Task updated, status: %s', updated.status);

close(id)

Close a task by setting its status to 'done' and recording the closed date.

ParamTypeRequiredDescription
idstringyesThe task ID

Returns: Promise<Task>

Example

const closed = await ctx.task.close('tsk_abc123');
ctx.logger.info('Task closed at %s', closed.closed_date);

softDelete(id)

Soft-delete a task, marking it as deleted without permanent removal.

ParamTypeRequiredDescription
idstringyesThe task ID

Returns: Promise<Task>

batchDelete(params)

Batch soft-delete tasks matching the given filters. At least one filter must be provided.

ParamTypeRequiredDescription
paramsBatchDeleteTasksParamsyesFilters selecting which tasks to delete

BatchDeleteTasksParams fields (all optional, but at least one required):

FieldTypeDescription
statusTaskStatusFilter by status
typeTaskTypeFilter by type
priorityTaskPriorityFilter by priority
parent_idstringFilter by parent task
created_idstringFilter by creator
older_thanstringDuration string (e.g., '30m', '24h', '7d', '2w')
limitnumberMax tasks to delete (default 50, max 200)

Returns: Promise<BatchDeleteTasksResult>

interface BatchDeleteTasksResult {
  deleted: { id: string; title: string }[];
  count: number;
}

Example

const result = await ctx.task.batchDelete({
  status: 'cancelled',
  older_than: '4w',
  limit: 100,
});
 
ctx.logger.info('Deleted %d cancelled tasks', result.count);

Comments

createComment(taskId, body, userId, author?)

Add a comment to a task.

ParamTypeRequiredDescription
taskIdstringyesThe task ID
bodystringyesComment text
userIdstringyesAuthor's user ID
authorEntityRefnoAuthor display reference (id, name)

Returns: Promise<Comment>

Example

const comment = await ctx.task.createComment(
  'tsk_abc123',
  'Root cause identified: missing index on search_queries table',
  'agent-001',
  { id: 'agent-001', name: 'Debug Agent' }
);

listComments(taskId, params?)

List comments on a task with optional pagination.

Returns: Promise<ListCommentsResult> with comments, total, limit, offset.

getComment(commentId)

Get a comment by its ID. Returns: Promise<Comment>

updateComment(commentId, body)

Update a comment's text. Returns: Promise<Comment>

deleteComment(commentId)

Delete a comment. Returns: Promise<void>

Tags

createTag(name, color?)

Create a new tag for categorizing tasks.

ParamTypeRequiredDescription
namestringyesTag display name
colorstringnoHex color code (e.g., '#ff0000')

Returns: Promise<Tag>

listTags()

List all tags in the organization. Returns: Promise<ListTagsResult> with a tags array.

addTagToTask(taskId, tagId)

Associate a tag with a task. Returns: Promise<void>

removeTagFromTask(taskId, tagId)

Remove a tag from a task. Returns: Promise<void>

listTagsForTask(taskId)

List all tags on a specific task. Returns: Promise<Tag[]>

getTag(tagId) / updateTag(tagId, name, color?) / deleteTag(tagId)

CRUD operations on individual tags.

Attachments

uploadAttachment(taskId, params)

Initiate a file upload. Returns a presigned S3 URL for direct upload.

ParamTypeRequiredDescription
taskIdstringyesThe task ID
paramsCreateAttachmentParamsyesFile metadata

CreateAttachmentParams fields:

FieldTypeRequiredDescription
filenamestringyesFilename for the attachment
content_typestringnoMIME type
sizenumbernoFile size in bytes

Returns: Promise<PresignUploadResponse>

interface PresignUploadResponse {
  attachment: Attachment;    // The created attachment record
  presigned_url: string;     // PUT this URL to upload the file
  expiry_seconds: number;    // Seconds until the URL expires
}

confirmAttachment(attachmentId)

Confirm that a file upload completed successfully. Returns: Promise<Attachment>

downloadAttachment(attachmentId)

Get a presigned download URL. Returns: Promise<PresignDownloadResponse>

listAttachments(taskId)

List all attachments on a task. Returns: Promise<ListAttachmentsResult>

deleteAttachment(attachmentId)

Delete an attachment. Returns: Promise<void>

Changelog and Activity

changelog(id, params?)

Get the audit trail for a task, showing field-level changes.

Returns: Promise<TaskChangelogResult> with changelog entries, total, limit, offset.

getActivity(params?)

Get task activity time-series data showing daily status counts.

ParamTypeRequiredDescription
paramsTaskActivityParamsno{ days?: number } (min 7, max 365, default 90)

Returns: Promise<TaskActivityResult> with daily data points containing open, inProgress, done, and cancelled counts.

Entity Management

createUser(params) / getUser(userId) / deleteUser(userId)

Manage user entities (human or agent) that can be assigned to tasks.

createProject(params) / getProject(projectId) / deleteProject(projectId)

Manage project entities for organizing tasks.

listUsers() / listProjects()

List all user and project entities referenced in tasks.