
大规模任务并行执行
当任务多到一定程度——一个文件夹里躺着十几个待办——逐个让代理做太慢。把任务放进一个文件夹,对 Peri 说一句「执行这个文件夹里所有任务」,Peri 会把所有任务编排成一条流水线:能并行的阶段全部并行,需要全局视野的阶段收窄,最后汇总成一份报告。
整个编排呈菱形:窄入口(读取任务文件夹)→ 扇出变宽(多路探索并行)→ 收窄(全局规划)→ 再扇出最宽(每个任务一条流水线:实现 → 评审 → 验证,各自独立工作区)→ 收窄汇聚(汇总报告)。
图例:绿色加粗=扇出,蓝色加粗=汇聚;绿节点=低成本模型档位,蓝节点=高档位;红边节点=写阶段。
flowchart TB
ARGS["args = { taskDir, maxConcurrency }"]
subgraph P_INTK["phase('Intake')"]
I1["agent('读取 task 文件夹 · 列出 tasks[]', { model: 'haiku' })"]
end
subgraph P_EXP["phase('Explore')"]
PAR_E["parallel([() => agent('探索', { model: 'haiku' }), ...])"]
E1["agent('探索 · 区域 X', { model: 'haiku' })"]
E2["agent('探索 · 区域 Y', { model: 'haiku' })"]
E3["agent('探索 · 区域 N', { model: 'haiku' })"]
end
subgraph P_PLN["phase('Plan')"]
PLAN["agent('规划 · 逐 task 制定方案', { model: 'sonnet' })"]
end
PAR_S["parallel([() => pipeline(task, [code, review, verify]), ...])"]
subgraph PIP1["phase('Pipeline') · pipeline('task-1', [code, review, verify])"]
direction TB
C1["agent('实现', { model: 'sonnet' })"]
R1["agent('评审', { model: 'sonnet' })"]
V1["agent('验证', { model: 'sonnet' })"]
end
subgraph PIP2["phase('Pipeline') · pipeline('task-2', [code, review, verify])"]
direction TB
C2["agent('实现', { model: 'sonnet' })"]
R2["agent('评审', { model: 'sonnet' })"]
V2["agent('验证', { model: 'sonnet' })"]
end
subgraph PIPN["phase('Pipeline') · pipeline('task-N', [code, review, verify])"]
direction TB
CN["agent('实现', { model: 'sonnet' })"]
RN["agent('评审', { model: 'sonnet' })"]
VN["agent('验证', { model: 'sonnet' })"]
end
subgraph P_RPT["phase('Report')"]
RPT["agent('汇总 N 份产出', { model: 'sonnet' })"]
end
DONE["最终交付"]
ARGS --> I1
I1 --> PAR_E
PAR_E --> E1
PAR_E --> E2
PAR_E --> E3
E1 --> PLAN
E2 --> PLAN
E3 --> PLAN
PLAN --> PAR_S
PAR_S --> C1
PAR_S --> C2
PAR_S --> CN
C1 --> R1
R1 --> V1
C2 --> R2
R2 --> V2
CN --> RN
RN --> VN
V1 --> RPT
V2 --> RPT
VN --> RPT
RPT --> DONE
linkStyle 2,3,4 stroke:#2e7d32,stroke-width:2px
linkStyle 9,10,11 stroke:#2e7d32,stroke-width:2px
linkStyle 5,6,7 stroke:#1565c0,stroke-width:2px
linkStyle 18,19,20 stroke:#1565c0,stroke-width:2px
classDef haiku fill:#e8f5e9,stroke:#2e7d32
classDef sonnet fill:#e3f2fd,stroke:#1565c0
classDef prim fill:#fff3e0,stroke:#e65100
classDef write fill:#ffebee,stroke:#c62828
class I1,E1,E2,E3 haiku
class PLAN,R1,R2,RN,V1,V2,VN,RPT sonnet
class PAR_E,PAR_S prim
class C1,C2,CN write
style P_INTK fill:#fafafa,stroke:#bdbdbd
style P_EXP fill:#fafafa,stroke:#bdbdbd
style P_PLN fill:#fafafa,stroke:#bdbdbd
style PIP1 fill:#fffbe6,stroke:#d4a017
style PIP2 fill:#fffbe6,stroke:#d4a017
style PIPN fill:#fffbe6,stroke:#d4a017
style P_RPT fill:#fafafa,stroke:#bdbdbd
编排结构与并行方式
Section titled “编排结构与并行方式”| 阶段 | 形状 | 并行方式 | 模型档位 |
|---|---|---|---|
| Intake | 窄(1 节点) | 读取任务文件夹,列出全部任务(一个不漏) | haiku |
| Explore | 宽(×R 扇出) | 多路探索者分区域并行 | haiku |
| Plan | 窄(1 节点) | 需要全局视野,汇聚探索结果后统一规划 | sonnet |
| Pipeline | 最宽(×N 扇出) | 每个任务一条流水线:实现 → 评审 → 验证,各自独立工作区 | sonnet |
| Report | 窄(1 节点) | 汇聚全部产出,输出一份总报告 | sonnet |
- 任务互不干扰:每个任务在独立工作区执行,写阶段只写自己的工作区。
- 同一代码库不会被并发写坏:并行写限定在各任务自己的工作区,不在同一份代码上打架。
- 单个任务失败不影响整体:失败的任务被隔离,其余任务照常推进。
- 并发度有上限:受
maxConcurrency限制,不会耗尽资源。