> For the complete documentation index, see [llms.txt](https://docs.unitlab.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.unitlab.ai/api-sdk-cli/ko/sdks/workflow-stages-and-tasks.md).

# 워크플로 단계와 작업

Python SDK로 워크플로 단계를 읽고 작업 목록을 조회하며, 작업을 claim, submit, approve, reject, move하는 방법을 설명합니다. 필요한 권한과 Consensus 작업도 다룹니다.

모든 프로젝트에는 워크플로가 있습니다. 워크플로는 Annotate, Review, Complete 같은 단계로 이루어진 그래프입니다. 각 항목에는 단계를 거쳐 이동하는 작업이 하나 있습니다.

```python
workflow = project.workflow
for stage in workflow.stages:
    print(stage.name, stage.type, stage.task_count)

annotate = workflow.get_stage(name="Annotate")
for task in annotate.get_tasks():
    print(task.id, task.name, task.status, task.assigned_to_id)
```

## 단계 찾기 <a href="#find-a-stage" id="find-a-stage"></a>

`workflow.get_stage()`는 `stage_id`, `name`, `stage_type` 중 정확히 하나를 받습니다. 일치하는 단계가 없거나 둘 이상이면 `ValidationError`가 발생합니다.

| `stage_type` | 단계           |
| ------------ | ------------ |
| `dataset`    | 새 항목이 들어오는 곳 |
| `annotate`   | 라벨링          |
| `review`     | 승인 또는 반려     |
| `complete`   | 완료된 작업       |

워크플로에는 앱에서 구성하는 Agent, Model, Consensus, Quality Gate 단계도 있을 수 있습니다.

`stage.get_tasks(include_unavailable=True)`는 다른 사람이 claim한 작업처럼 지금 처리할 수 없는 작업도 함께 나열합니다.

## 작업 동작 <a href="#task-actions" id="task-actions"></a>

| 호출                                   | 효과                                        |
| ------------------------------------ | ----------------------------------------- |
| `task.claim()`                       | 작업 맡기                                     |
| `task.assign(user_id)`               | 멤버에게 할당                                   |
| `task.release()`                     | 대기열에 되돌리기                                 |
| `task.set_priority(n)`               | 숫자가 클수록 먼저 배정됩니다                          |
| `task.submit()`                      | annotate 작업을 다음 단계로 보내기                   |
| `task.approve()`                     | review 작업 승인                              |
| `task.reject(reason="", comment="")` | review 작업을 되돌려 보내기. reason은 어노테이터에게 표시됩니다 |
| `task.skip()`                        | 작업 건너뛰기                                   |
| `task.move(stage, reason="")`        | 워크플로의 연결을 무시하고 직접 이동                      |
| `task.get_timeline()`                | 작업 이력                                     |

각 동작은 갱신된 작업을 반환합니다. `task.available_actions`와 `task.move_targets`에서 현재 허용되는 동작을 확인할 수 있으며, 허용되지 않는 동작은 `ValidationError`를 발생시킵니다.

작업 하나는 어디서든 `client.get_workflow_task(task_id)` 또는 `workflow.get_task(task_id)`로 읽을 수 있습니다.

## 권한 <a href="#permissions" id="permissions"></a>

| 호출                                                                  | 키에 필요한 권한                                       |
| ------------------------------------------------------------------- | ----------------------------------------------- |
| 단계, 작업 목록, `assign`, `release`, `set_priority`, `move`, 일괄 호출       | **Assign project members** 또는 **Manage data**   |
| `claim`                                                             | **View labeling interface** 및 **Create labels** |
| `submit`, `approve`, `reject`, `skip`, `get_timeline`, consensus 호출 | **Create labels** 및 **Manage data**             |

`claim`은 키를 생성한 멤버의 이름으로 작업을 가져갑니다.

## 작업 필드 <a href="#task-fields" id="task-fields"></a>

`id`, `name`, `stage_id`, `stage_type`, `status`, `task_status`, `priority`, `assigned_to_id`, `datasource_id`, `data_group_id`, `data_type`, `available_actions`, `move_targets`, `task_kind`, `parent_item_id`, `assignment_id`, `consensus_summary`.

## Consensus 작업 <a href="#consensus-tasks" id="consensus-tasks"></a>

`task.get_consensus_comparison()`은 어노테이터들의 버전을 나란히 반환합니다. `task.copy_consensus_component(...)`는 한 어노테이터 버전의 객체 하나를 결과로 복사합니다.

## 관련 문서 <a href="#related" id="related"></a>

[워크플로 일괄 작업](https://docs.unitlab.ai/api-sdk-cli/ko/sdks/bulk-workflow-operations.md) · [작업 어노테이션과 Agent 웹훅](https://docs.unitlab.ai/api-sdk-cli/ko/sdks/task-annotations-and-agent-webhooks.md) · [CLI: 워크플로](https://docs.unitlab.ai/api-sdk-cli/ko/clis/cli-workflow-tasks.md)
