> 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/zh/sdks/bulk-workflow-operations.md).

# 批量工作流操作

使用 Unitlab Python SDK 一次调用批量分配或移动多达 500 个工作流任务，并在移动前用 dry run 预览影响。

```python
workflow = project.workflow
annotate = workflow.get_stage(name="Annotate")
task_ids = [task.id for task in annotate.get_tasks()][:200]

workflow.assign_tasks(task_ids, user_id="USER_ID")

review = workflow.get_stage(stage_type="review")
plan = workflow.move_tasks(task_ids, destination_stage=review.id, reason="Spot check", dry_run=True)
print(plan)
workflow.move_tasks(task_ids, destination_stage=review.id, reason="Spot check")
```

| 调用                                                                               | 上限      | 说明                                        |
| -------------------------------------------------------------------------------- | ------- | ----------------------------------------- |
| `workflow.assign_tasks(task_ids, user_id=...)`                                   | 500 个任务 | 将所有任务分配给同一个成员                             |
| `workflow.move_tasks(task_ids, destination_stage=..., reason="", dry_run=False)` | 500 个任务 | 忽略工作流连线。`dry_run=True` 仅报告将被移动的内容，不做任何修改。 |

更长的列表请拆分为每组 500 个。`destination_stage` 接受阶段句柄或 ID。

移入 Model 或 Agent 阶段会为每个任务启动一次运行，可能消耗模型配额。请先运行 dry run。

密钥需要 **Assign project members** 或 **Manage data** 权限。

## 相关内容 <a href="#related" id="related"></a>

[工作流阶段与任务](https://docs.unitlab.ai/api-sdk-cli/zh/sdks/workflow-stages-and-tasks.md) · [CLI：工作流](https://docs.unitlab.ai/api-sdk-cli/zh/clis/cli-workflow-tasks.md)
