delegation-mode

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Delegation 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
.agents/plans/
, 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.
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将自己的结果直接写入
.agents/plans/
目录,后续会话会重新运行同一计划,并跳过已完成的任务ID。可复用的运行器会验证结果文件(而非仅Worker的响应),之后才会确认任务完成。
此模式适用于以下场景:任务规模大、多步骤、可并行化,可能超出单个上下文窗口的生命周期,或是作为下一个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 plan
Copy
scripts/delegation-plan.template.js
to the first path and fill in the project context and task definitions. The script must contain:
  • a stable run date and slug;
  • a stable, unique ID for every task;
  • an exact output path for every task;
  • MODE = "sequential"
    or
    MODE = "parallel"
    ;
  • DONE_IDS
    , initially empty and updated when resuming;
  • an optional final aggregation task controlled by
    FINAL_DONE
    .
Keep the plan script in
.agents/plans/
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
DATE
,
SLUG
, task IDs, and output paths are part of its identity; create a new slug when the scope changes.
The reusable template loads
scripts/plan-validation-core.js
, which is the single source for plan identity checks, safe output paths,
DONE_IDS
, 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.
每次运行使用一个计划脚本:
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
    控制的可选最终聚合任务。
将计划脚本保存在
.agents/plans/
目录中,以便其他会话无需从聊天记录重建调度逻辑即可执行同一文件。运行前请填写所有占位符。计划的
DATE
SLUG
、任务ID和输出路径是其标识的一部分;当范围变更时,请创建新的slug。
可复用模板会加载
scripts/plan-validation-core.js
,该文件是计划身份校验、安全输出路径、
DONE_IDS
、Markdown前置元数据、完成标记和持久化文件验证的唯一数据源。加载器会检查可发布的源码树和已安装的skill树,以便复制的计划在安装后仍可使用。

Worker contract

Worker契约

Every delegated worker must:
  1. Read the complete task prompt and relevant source files.
  2. Stay within its assigned scope and avoid editing application source unless the plan explicitly assigns implementation ownership.
  3. Write its complete result directly to the exact output path in the prompt.
  4. Use Markdown plan frontmatter with
    kind: plan
    , a meaningful
    id
    , and a truthful
    status
    . A completed result uses
    status: done
    ; a blocked or incomplete result must not claim completion.
  5. Include actionable findings, decisions, blockers, or delivered changes.
  6. Include the exact
    FILE_WRITTEN:
    line 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.
  7. 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必须:
  1. 读取完整的任务提示和相关源文件。
  2. 保持在分配的范围内,除非计划明确赋予实现所有权,否则避免编辑应用源码。
  3. 将完整结果直接写入提示中指定的精确输出路径。
  4. 使用带有
    kind: plan
    、有意义的
    id
    和真实
    status
    的Markdown计划前置元数据。完成的结果使用
    status: done
    ;受阻或未完成的结果不得声称已完成。
  5. 包含可执行的发现、决策、障碍或已交付的变更。
  6. 在结果文件的最后一个非空行以及响应中包含精确的
    FILE_WRITTEN:
    行。这样,即使调度器在Worker写入文件但返回响应之前被终止,结果仍可被审计。
  7. 响应必须以以下内容结尾:
    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
Promise.allSettled
, 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
dependsOn
, it must run after those task IDs are confirmed; parallel mode is valid only when the dependency graph permits independent dispatch.
Every 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";
并行任务必须是对应用源码只读的,写入不同的输出文件,且不依赖于其他任务的结果。运行器使用
Promise.allSettled
,因此一个Worker失败不会隐藏其他Worker的结果。只有当所有任务都有经过验证的结果文件后,聚合任务才会执行。如果任务声明了
dependsOn
,则必须在这些任务ID被确认后才能运行;仅当依赖图允许独立调度时,并行模式才有效。
每个可写入的委托任务使用:
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:
  1. Inspect the plan's output files.
  2. Confirm each candidate result is complete, has truthful plan frontmatter, and contains its exact
    FILE_WRITTEN:
    marker as the final non-empty line; use the worker response as additional confirmation when it is available.
  3. Put only confirmed task IDs in
    DONE_IDS
    . The runner rejects unknown, duplicate, or stale IDs and revalidates every listed output file.
  4. Rerun the complete
    .js
    plan.
  5. The runner skips
    DONE_IDS
    and dispatches only missing or unresolved tasks.
  6. 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
DONE_IDS
and rerun that task. If the review scope changes, create a new slug instead of reusing old results.
DONE_IDS
is intentionally explicit rather than inferred by an in-script filesystem scan. This makes the resume decision auditable and prevents a truncated or stale file from being treated as complete.
被终止的Code Execution运行不会使Worker已写入的文件失效。请从计划(而非聊天记录)恢复:
  1. 检查计划的输出文件。
  2. 确认每个候选结果已完成,具有真实的计划前置元数据,且最后一个非空行包含精确的
    FILE_WRITTEN:
    标记;当Worker响应可用时,可将其作为额外确认。
  3. 仅将已确认的任务ID放入
    DONE_IDS
    。运行器会拒绝未知、重复或过时的ID,并重新验证每个列出的输出文件。
  4. 重新运行完整的
    .js
    计划。
  5. 运行器会跳过
    DONE_IDS
    中的任务,仅调度缺失或未解决的任务。
  6. 仅当所有任务ID都被确认后,才运行最终聚合任务。
请勿从Worker的沉默、部分文件或旧聊天消息推断任务已完成。如果结果文件存在但缺少完成标记或所需内容,请将该ID排除在
DONE_IDS
之外,并重新运行该任务。如果审查范围变更,请创建新的slug,而非复用旧结果。
DONE_IDS
被设计为显式配置,而非通过脚本内的文件系统扫描推断。这使得恢复决策可被审计,并防止截断或过时的文件被视为已完成。

Composition 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
    .agents/plans/
    file per axis;
  • 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:
StateMeaning
pending
Task has not been dispatched.
running
Work is in progress; partial progress is recorded when useful.
blocked
A specific missing decision, input, or environment condition prevents safe progress.
done
The task output is complete and verified.
Never mark a task
done
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.
结果文件是持久化记录。请在其前置元数据或正文中使用以下状态含义:
状态含义
pending
任务尚未调度。
running
任务正在进行中;如有必要,可记录部分进度。
blocked
特定的缺失决策、输入或环境条件阻碍了安全推进。
done
任务输出已完成并经过验证。
绝不能仅因为任务大部分完成就标记为
done
。当任何任务抛出异常或缺少标记时,计划脚本应报告未解决的任务并跳过最终聚合。

Final validation

最终验证

Before reporting a delegated run complete:
  1. Confirm every expected task result exists, is inside
    .agents/plans/
    , and follows its required schema.
  2. Confirm every task ID is represented in
    DONE_IDS
    or was completed in the current run.
  3. Confirm the final aggregation file exists when the plan defines one, and revalidate it before setting
    FINAL_DONE = true
    .
  4. Check links, frontmatter, and
    git diff --check
    .
  5. Run relevant tests, lint, type checks, or builds for implementation work.
  6. Record verification and remaining risks in the final plan.
Do not claim approval while unresolved critical blockers remain.
在报告委托运行完成前:
  1. 确认所有预期的任务结果都存在,位于
    .agents/plans/
    目录内,并遵循其要求的schema。
  2. 确认每个任务ID都已包含在
    DONE_IDS
    中,或在当前运行中已完成。
  3. 当计划定义了最终聚合文件时,确认该文件存在,并在设置
    FINAL_DONE = true
    前重新验证它。
  4. 检查链接、前置元数据和
    git diff --check
  5. 对实现类任务运行相关测试、代码检查、类型检查或构建。
  6. 在最终计划中记录验证情况和剩余风险。
如果仍存在未解决的关键障碍,请勿声称已批准。

Included resources

包含的资源

  • scripts/delegation-plan.template.js
    — generic resumable dispatcher.
  • references/delegation-modes.md
    — mode selection and resume checklist.
  • scripts/delegation-plan.template.js
    — 通用可恢复调度器。
  • references/delegation-modes.md
    — 模式选择与恢复检查清单。