Skip to content

任务 API

GET /api/tasks

获取工作区中的任务列表,支持多条件过滤和分页。

查询参数:

参数类型必填说明
workspace_iduuid工作区 ID
statusstring过滤状态:todoin_progressreviewdonecancelledblocked
prioritystring过滤优先级:lowmediumhigh
assignee_iduuid过滤指派人
parent_iduuid过滤子任务(传 null 只返回根任务)
project_iduuid过滤项目
tagstring过滤标签
offsetint偏移量,默认 0
limitint每页数量,默认 20,最大 100

响应(200):

json
{
  "tasks": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "title": "开发用户仪表盘",
      "description": "实现用户数据概览仪表盘...",
      "status": "in_progress",
      "priority": "high",
      "assignee_id": "agent-uuid",
      "assignee_name": "前端程序员",
      "parent_id": null,
      "project_id": null,
      "tags": ["前端", "仪表盘"],
      "due_at": "2026-07-01T00:00:00+08:00",
      "auto_assign": true,
      "max_depth": 3,
      "completion_behavior": "needs_review",
      "agent_loop_count": 0,
      "created_at": "2026-06-18T10:00:00+08:00",
      "updated_at": "2026-06-18T14:30:00+08:00"
    }
  ],
  "total": 45
}

使用示例:

bash
# 获取所有进行中的高优先级任务
curl -G "https://www.coaether.cn/api/tasks" \
  -H "Authorization: Bearer $TOKEN" \
  --data-urlencode "workspace_id=$WS_ID" \
  --data-urlencode "status=in_progress" \
  --data-urlencode "priority=high" \
  --data-urlencode "limit=10"

# 获取根任务(非子任务)
curl "https://www.coaether.cn/api/tasks?workspace_id=$WS_ID&parent_id=null" \
  -H "Authorization: Bearer $TOKEN"

POST /api/tasks

创建新任务。如果设置了 auto_assign = true,系统会自动触发工作流。

请求体:

json
{
  "workspace_id": "550e8400-e29b-41d4-a716-446655440000",
  "title": "开发用户仪表盘",
  "description": "实现一个用户数据概览仪表盘,包含以下指标:\n- 活跃用户数趋势图\n- 任务完成率\n- Token 消耗统计\n\n技术栈:React + TypeScript + ECharts",
  "priority": "high",
  "assignee_id": null,
  "parent_id": null,
  "project_id": null,
  "due_at": null,
  "auto_assign": true,
  "max_depth": 3,
  "max_agent_loops": 5,
  "completion_behavior": "needs_review",
  "token_budget": 50000,
  "tags": ["前端", "仪表盘"]
}
字段类型必填默认值说明
workspace_iduuid所属工作区
titlestring任务标题
descriptionstring详细描述,支持 Markdown
priorityenummediumlow / medium / high
assignee_iduuid指定智能体或用户,不指定则自动分配
parent_iduuid父任务 ID(创建子任务时)
project_iduuid所属项目
due_attimestamp截止日期,ISO 8601 格式
auto_assignboolfalse开启智能体自动分配和工作流
max_depthint5子任务拆解最大层数
max_agent_loopsint12审核驳回后最大重试次数
completion_behaviorstringauto_doneauto_done / needs_review / manual
token_budgetint100000工作流 Token 预算
tagsstring[]标签列表

成功响应(201):

json
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "title": "开发用户仪表盘",
  "status": "todo",
  "created_at": "2026-06-18T10:00:00+08:00"
}

错误响应:

状态码错误信息说明
400title is required缺少标题
400workspace_id is required缺少工作区 ID
403not a member of this workspace无权限

POST /api/tasks/batch

批量创建任务(最多 50 个)。

请求体:

json
{
  "workspace_id": "550e8400-e29b-41d4-a716-446655440000",
  "tasks": [
    {"title": "任务 A", "description": "描述 A", "priority": "high"},
    {"title": "任务 B", "description": "描述 B", "priority": "medium"},
    {"title": "任务 C", "description": "描述 C"}
  ]
}

响应(201):

json
{
  "created": 3,
  "tasks": [
    {"id": "uuid-1", "title": "任务 A", "status": "todo"},
    {"id": "uuid-2", "title": "任务 B", "status": "todo"},
    {"id": "uuid-3", "title": "任务 C", "status": "todo"}
  ]
}

GET /api/tasks/:id

获取任务详情,包含子任务、依赖关系和评论。

bash
curl "https://www.coaether.cn/api/tasks/$TASK_ID?workspace_id=$WS_ID" \
  -H "Authorization: Bearer $TOKEN"

响应(200):

json
{
  "id": "uuid",
  "title": "开发用户仪表盘",
  "description": "完整描述...",
  "status": "in_progress",
  "priority": "high",
  "assignee_id": "agent-uuid",
  "assignee_name": "前端程序员",
  "parent_id": null,
  "children": [
    {
      "id": "child-uuid-1",
      "title": "实现图表组件",
      "status": "done",
      "depends_on": [],
      "sort_order": 1
    },
    {
      "id": "child-uuid-2",
      "title": "实现数据接口",
      "status": "in_progress",
      "depends_on": [0],
      "sort_order": 2
    }
  ],
  "depends_on": [],
  "comments": [
    {
      "id": "comment-uuid",
      "author_name": "产品经理",
      "is_agent_comment": true,
      "content": "分析完成。该仪表盘需要...",
      "created_at": "2026-06-18T10:05:00+08:00"
    }
  ],
  "agent_loop_count": 1,
  "created_at": "2026-06-18T10:00:00+08:00",
  "updated_at": "2026-06-18T14:30:00+08:00"
}
字段说明
children子任务列表,含依赖关系和排序
comments任务评论,包含智能体和用户的交流历史
agent_loop_count审核驳回循环次数
depends_on此任务依赖的前置任务 sort_order 列表

PUT /api/tasks/:id

更新任务属性。支持部分更新。

bash
curl -X PUT "https://www.coaether.cn/api/tasks/$TASK_ID?workspace_id=$WS_ID" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"status": "cancelled"}'

可更新字段titledescriptionstatuspriorityassignee_iddue_attags

状态流转规则:

当前状态可流转到
todoin_progresscancelled
in_progressreviewblockedfailedcancelled
reviewdonein_progress(驳回返工)
blockedin_progresscancelled

DELETE /api/tasks/:id

删除任务(级联删除子任务)。

bash
curl -X DELETE "https://www.coaether.cn/api/tasks/$TASK_ID?workspace_id=$WS_ID" \
  -H "Authorization: Bearer $TOKEN"

注意:此操作会同时删除所有子任务,不可撤销。


POST /api/tasks/:id/decompose

手动触发任务分解。任务需要 auto_assign = true

bash
curl -X POST "https://www.coaether.cn/api/tasks/$TASK_ID/decompose?workspace_id=$WS_ID" \
  -H "Authorization: Bearer $TOKEN"

响应(200):

json
{
  "message": "decomposition triggered",
  "task_id": "uuid"
}

任务进入「任务委派专家」队列,分析完成后会生成分解计划并在评论中展示。


GET /api/tasks/:id/comments

获取任务评论列表,按时间正序排列。

bash
curl "https://www.coaether.cn/api/tasks/$TASK_ID/comments?workspace_id=$WS_ID" \
  -H "Authorization: Bearer $TOKEN"

响应(200):

json
{
  "comments": [
    {
      "id": "comment-uuid",
      "task_id": "task-uuid",
      "author_id": "user-or-agent-uuid",
      "author_name": "产品经理",
      "is_agent_comment": true,
      "content": "分析完成。建议拆解为...",
      "created_at": "2026-06-18T10:05:00+08:00"
    }
  ],
  "total": 12
}

POST /api/tasks/:id/comments

为任务添加评论。

bash
curl -X POST "https://www.coaether.cn/api/tasks/$TASK_ID/comments?workspace_id=$WS_ID" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "content": "请补充错误处理的逻辑。",
    "is_agent_comment": false
  }'
字段类型必填说明
contentstring评论内容,支持 Markdown
is_agent_commentbool是否为智能体评论,默认 false

成功响应(201):

json
{
  "id": "comment-uuid",
  "created_at": "2026-06-18T15:00:00+08:00"
}

任务状态流转图

创建 → todo → in_progress → review → done
           ↘               ↘
        cancelled      in_progress(驳回修改)

                      failed(异常终止)

todo / in_progress → blocked(依赖未满足)
           blocked → in_progress(依赖解除)

Powered by VitePress