delegation-mode
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDelegation Mode
委托模式
Delegation mode makes the filesystem the source of truth for delegated work.
The chat transcript is useful for progress updates, but it is never the only
handoff. A coordinator creates an executable plan, each worker writes its own
result directly to , and a later session reruns the same plan
with completed task IDs skipped. The reusable runner validates the result file,
not just the worker's response, before it confirms a task.
.agents/plans/Use this mode for work that is large, multi-step, parallelizable, likely to
outlive one context window, or valuable as a durable plan for the next agent.
Do not use it for a small interactive answer that has no durable output.
委托模式将文件系统作为委托任务的可信数据源。聊天记录可用于进度更新,但绝不会是唯一的交接方式。协调者创建一个可执行计划,每个Worker将自己的结果直接写入目录,后续会话会重新运行同一计划,并跳过已完成的任务ID。可复用的运行器会验证结果文件(而非仅Worker的响应),之后才会确认任务完成。
.agents/plans/此模式适用于以下场景:任务规模大、多步骤、可并行化,可能超出单个上下文窗口的生命周期,或是作为下一个Agent的持久化计划具有价值。请勿将其用于无持久化输出的小型交互式问答。
Source of truth
可信数据源
Use one plan script per run:
text
.agents/plans/
├── YYYY-MM-DD-<slug>.js # executable dispatcher and resume state
├── YYYY-MM-DD-<slug>-<task-id>.md # one durable result per task
└── YYYY-MM-DD-<slug>-FINAL.md # optional aggregation planCopy to the first path and fill in the
project context and task definitions. The script must contain:
scripts/delegation-plan.template.js- a stable run date and slug;
- a stable, unique ID for every task;
- an exact output path for every task;
- or
MODE = "sequential";MODE = "parallel" - , initially empty and updated when resuming;
DONE_IDS - an optional final aggregation task controlled by .
FINAL_DONE
Keep the plan script in so another session can execute the
same file without reconstructing the dispatch logic from chat. Fill in every
placeholder before running it. The plan's , , task IDs, and output
paths are part of its identity; create a new slug when the scope changes.
.agents/plans/DATESLUGThe reusable template loads , which is the
single source for plan identity checks, safe output paths, , Markdown
frontmatter, completion markers, and durable-file validation. The loader checks
the publishable source tree and installed skill tree so a copied plan remains
usable after installation.
scripts/plan-validation-core.jsDONE_IDS每次运行使用一个计划脚本:
text
.agents/plans/
├── YYYY-MM-DD-<slug>.js # 可执行调度器与恢复状态
├── YYYY-MM-DD-<slug>-<task-id>.md # 每个任务对应一个持久化结果
└── YYYY-MM-DD-<slug>-FINAL.md # 可选的聚合计划将复制到第一个路径,并填写项目上下文和任务定义。脚本必须包含:
scripts/delegation-plan.template.js- 稳定的运行日期和slug;
- 每个任务的稳定、唯一ID;
- 每个任务的精确输出路径;
- 或
MODE = "sequential";MODE = "parallel" - ,初始为空,恢复时更新;
DONE_IDS - 由控制的可选最终聚合任务。
FINAL_DONE
将计划脚本保存在目录中,以便其他会话无需从聊天记录重建调度逻辑即可执行同一文件。运行前请填写所有占位符。计划的、、任务ID和输出路径是其标识的一部分;当范围变更时,请创建新的slug。
.agents/plans/DATESLUG可复用模板会加载,该文件是计划身份校验、安全输出路径、、Markdown前置元数据、完成标记和持久化文件验证的唯一数据源。加载器会检查可发布的源码树和已安装的skill树,以便复制的计划在安装后仍可使用。
scripts/plan-validation-core.jsDONE_IDSWorker contract
Worker契约
Every delegated worker must:
-
Read the complete task prompt and relevant source files.
-
Stay within its assigned scope and avoid editing application source unless the plan explicitly assigns implementation ownership.
-
Write its complete result directly to the exact output path in the prompt.
-
Use Markdown plan frontmatter with, a meaningful
kind: plan, and a truthfulid. A completed result usesstatus; a blocked or incomplete result must not claim completion.status: done -
Include actionable findings, decisions, blockers, or delivered changes.
-
Include the exactline as the final non-empty line in the result file as well as in the response. This makes a result auditable if the dispatcher is killed after the worker writes but before its response is returned.
FILE_WRITTEN: -
End its response with exactly:text
FILE_WRITTEN: <exact-output-path>The response marker is valid only after the file exists and passes the result-file checks. The response marker is a useful liveness signal; the file marker is the durable completion signal.
For implementation tasks, the result plan should record what changed, files
affected, verification performed, remaining risks, and the next action. For
analysis tasks, it should record scope, evidence, conclusions, and recommended
work. Empty results are valid when the worker explicitly records that it
checked the scope and found nothing.
每个委托的Worker必须:
-
读取完整的任务提示和相关源文件。
-
保持在分配的范围内,除非计划明确赋予实现所有权,否则避免编辑应用源码。
-
将完整结果直接写入提示中指定的精确输出路径。
-
使用带有、有意义的
kind: plan和真实id的Markdown计划前置元数据。完成的结果使用status;受阻或未完成的结果不得声称已完成。status: done -
包含可执行的发现、决策、障碍或已交付的变更。
-
在结果文件的最后一个非空行以及响应中包含精确的行。这样,即使调度器在Worker写入文件但返回响应之前被终止,结果仍可被审计。
FILE_WRITTEN: -
响应必须以以下内容结尾:text
FILE_WRITTEN: <exact-output-path>只有当文件存在并通过结果文件检查后,响应标记才有效。响应标记是有用的存活信号;文件标记是持久化的完成信号。
对于实现任务,结果计划应记录变更内容、受影响的文件、执行的验证、剩余风险以及下一步操作。对于分析任务,应记录范围、证据、结论和推荐的工作内容。当Worker明确记录其检查了范围且未发现任何内容时,空结果是有效的。
Sequential and parallel dispatch
顺序与并行调度
The default is sequential:
js
const MODE = "sequential";The runner awaits each pending task before dispatching the next. Use it when:
- tasks may compete for shared resources;
- one task depends on another;
- workers may edit overlapping files;
- the repository or tool budget is constrained;
- predictable failure boundaries are more useful than wall-clock speed.
Use parallel only when all pending tasks are independent:
js
const MODE = "parallel";Parallel tasks must be read-only with respect to application source, write
different output files, and not depend on another task's result. The runner
uses , so one failed worker does not hide results from the
others. Aggregation is blocked until every task has a validated result file.
If a task declares , it must run after those task IDs are confirmed;
parallel mode is valid only when the dependency graph permits independent
dispatch.
Promise.allSettleddependsOnEvery writable delegated task uses:
js
config: { $kind: "general" }Do not use an explore-only worker for a task whose completion requires writing a
file. Use specialized worker kinds only when the composition skill explicitly
defines a compatible file-writing contract.
默认模式为顺序调度:
js
const MODE = "sequential";运行器会在调度下一个任务前等待每个待处理任务完成。适用于以下场景:
- 任务可能争夺共享资源;
- 一个任务依赖于另一个任务;
- Worker可能编辑重叠的文件;
- 仓库或工具预算受限;
- 可预测的故障边界比实际执行速度更重要。
仅当所有待处理任务相互独立时,才使用并行调度:
js
const MODE = "parallel";并行任务必须是对应用源码只读的,写入不同的输出文件,且不依赖于其他任务的结果。运行器使用,因此一个Worker失败不会隐藏其他Worker的结果。只有当所有任务都有经过验证的结果文件后,聚合任务才会执行。如果任务声明了,则必须在这些任务ID被确认后才能运行;仅当依赖图允许独立调度时,并行模式才有效。
Promise.allSettleddependsOn每个可写入的委托任务使用:
js
config: { $kind: "general" }对于完成需要写入文件的任务,请勿使用仅探索型Worker。仅当组合skill明确定义了兼容的文件写入契约时,才使用专用Worker类型。
Resume after interruption
中断后恢复
A killed Code Execution run does not invalidate files already written by
workers. Resume from the plan, not from the transcript:
- Inspect the plan's output files.
- Confirm each candidate result is complete, has truthful plan frontmatter,
and contains its exact marker as the final non-empty line; use the worker response as additional confirmation when it is available.
FILE_WRITTEN: - Put only confirmed task IDs in . The runner rejects unknown, duplicate, or stale IDs and revalidates every listed output file.
DONE_IDS - Rerun the complete plan.
.js - The runner skips and dispatches only missing or unresolved tasks.
DONE_IDS - Run final aggregation only after all task IDs are confirmed.
Do not infer completion from a worker's silence, a partial file, or an old chat
message. If a result file exists but its completion marker or required content
is missing, leave the ID out of and rerun that task. If the review
scope changes, create a new slug instead of reusing old results.
DONE_IDSDONE_IDS被终止的Code Execution运行不会使Worker已写入的文件失效。请从计划(而非聊天记录)恢复:
- 检查计划的输出文件。
- 确认每个候选结果已完成,具有真实的计划前置元数据,且最后一个非空行包含精确的标记;当Worker响应可用时,可将其作为额外确认。
FILE_WRITTEN: - 仅将已确认的任务ID放入。运行器会拒绝未知、重复或过时的ID,并重新验证每个列出的输出文件。
DONE_IDS - 重新运行完整的计划。
.js - 运行器会跳过中的任务,仅调度缺失或未解决的任务。
DONE_IDS - 仅当所有任务ID都被确认后,才运行最终聚合任务。
请勿从Worker的沉默、部分文件或旧聊天消息推断任务已完成。如果结果文件存在但缺少完成标记或所需内容,请将该ID排除在之外,并重新运行该任务。如果审查范围变更,请创建新的slug,而非复用旧结果。
DONE_IDSDONE_IDSComposition with larger skills
与大型Skill的组合
Delegation mode is an execution layer, not a review methodology. A larger
skill can define its own task list and result schema while using this contract.
For example, :
code-review-axes-and-quality- defines ten independent review axes;
- uses one stable task ID and one file per axis;
.agents/plans/ - supports sequential or parallel dispatch;
- runs a final deduplicating aggregation only after all ten axes confirm.
For hard tasks, decompose the work into tasks with explicit dependencies,
select sequential mode where needed, and make the final task read the earlier
plan files instead of depending on chat context.
委托模式是一个执行层,而非审查方法论。大型Skill可以在遵循此契约的同时,定义自己的任务列表和结果 schema。例如,:
code-review-axes-and-quality- 定义十个独立的审查维度;
- 每个维度使用一个稳定的任务ID和一个目录下的文件;
.agents/plans/ - 支持顺序或并行调度;
- 仅当十个维度都确认完成后,才运行最终的去重聚合任务。
对于难度较大的任务,将工作分解为具有明确依赖关系的任务,在需要时选择顺序模式,并让最终任务读取早期的计划文件,而非依赖聊天上下文。
Failure and terminal states
故障与终端状态
The result file is the durable record. Use these meanings in its frontmatter or
body:
| State | Meaning |
|---|---|
| Task has not been dispatched. |
| Work is in progress; partial progress is recorded when useful. |
| A specific missing decision, input, or environment condition prevents safe progress. |
| The task output is complete and verified. |
Never mark a task merely because most of it is complete. A plan script
should report unresolved tasks and skip final aggregation when any task throws
or lacks its marker.
done结果文件是持久化记录。请在其前置元数据或正文中使用以下状态含义:
| 状态 | 含义 |
|---|---|
| 任务尚未调度。 |
| 任务正在进行中;如有必要,可记录部分进度。 |
| 特定的缺失决策、输入或环境条件阻碍了安全推进。 |
| 任务输出已完成并经过验证。 |
绝不能仅因为任务大部分完成就标记为。当任何任务抛出异常或缺少标记时,计划脚本应报告未解决的任务并跳过最终聚合。
doneFinal validation
最终验证
Before reporting a delegated run complete:
- Confirm every expected task result exists, is inside , and follows its required schema.
.agents/plans/ - Confirm every task ID is represented in or was completed in the current run.
DONE_IDS - Confirm the final aggregation file exists when the plan defines one, and
revalidate it before setting .
FINAL_DONE = true - Check links, frontmatter, and .
git diff --check - Run relevant tests, lint, type checks, or builds for implementation work.
- Record verification and remaining risks in the final plan.
Do not claim approval while unresolved critical blockers remain.
在报告委托运行完成前:
- 确认所有预期的任务结果都存在,位于目录内,并遵循其要求的schema。
.agents/plans/ - 确认每个任务ID都已包含在中,或在当前运行中已完成。
DONE_IDS - 当计划定义了最终聚合文件时,确认该文件存在,并在设置前重新验证它。
FINAL_DONE = true - 检查链接、前置元数据和。
git diff --check - 对实现类任务运行相关测试、代码检查、类型检查或构建。
- 在最终计划中记录验证情况和剩余风险。
如果仍存在未解决的关键障碍,请勿声称已批准。
Included resources
包含的资源
- — generic resumable dispatcher.
scripts/delegation-plan.template.js - — mode selection and resume checklist.
references/delegation-modes.md
- — 通用可恢复调度器。
scripts/delegation-plan.template.js - — 模式选择与恢复检查清单。
references/delegation-modes.md