サブタスクを子に渡し、停止を返す
読了まで約42 分分、7 節 節の 4 例 例。
この章を終えると、独自のステップ予算を持つ子ループにサブタスクを渡し、子の記録全体の代わりに、要約と停止理由を受け取れるようになる。また、停止が人に届くようにする。停止ルールによって行き詰まりとして終了した実行は親に渡され、親は、その停止が持つ問いを、issue を起票したメンテナに伝える。
事例のタスク T-02 を取り上げる。小さな単位ライブラリ unitcraft では、負の数量で桁区切り(千の位の区切り文字)が失われる。メンテナンス用エージェントはこれを修正しなければならない。実行は unitcraft/format.py を読み、そのファイルに 2 回の編集を加える。どちらの編集も失敗する。指定した古いテキストが、そのままの形ではファイルに存在しないためであり、テスト結果は変わらないままである。第2章は、ルールが進捗なしと判断した時点で、このような実行を終了させる。ハーネス v1 は、task-set の記録では T-02 をステップ上限まで実行した。第2章の 2 つの停止ルールを両方とも適用して再生すると、同じ応答がこの実行を no_progress at step 5 of 16 として終了させる。停止は役割を果たすが、メンテナの手元にはログだけが残り、エージェントが何を試みていたのかの説明は残らない。それを知るには、誰かがログを読まなければならない。
2 つ目の問題は規模である。丸め規則がどこにあるかを調べるには複数のファイルを読む必要があり、エージェントが読んだファイルはすべて、次のステップが持ち越すコンテキストに残る。このような副次的なタスクは、独自のコンテキストで行い、親に必要なものだけを返すほうがよい。Anthropic のサブエージェントのドキュメントは、自社製品についてこの分割を説明している。サブエージェントは独自のコンテキストで作業を行い、要約だけを返す。
この章では、この事例のための子を構築する。子とは、独自の予算を持つ同じループである。本書では、ハンドオフとは、実行が完了ではなく、人への問いを添えて終わることをいう。ハンドオフには 2 種類ある。モデル自身による ask_user 呼び出しと、停止後にハーネスが行う構造化されたハンドオフである。後者は、停止理由、実行が試みたこと、そして問いを伴う。子は自分のハンドオフを親に返す。ハンドオフには、どのように終了したか、何を試みたか、どのファイルを読み、どのファイルを変更したか、そして要約か、停止の原因となった問いのいずれかが含まれる。子が記録を返すことはない。子を終了させた停止は、問いとしてメンテナに届く。
この部分はまだ翻訳されていないため、英語で表示している。
A child is a loop with its own budget
A side task in the case, such as finding where a rounding rule lives, can take steps that the parent's budget should not pay for. A child is the loop from chapter 1, started by a parent in the middle of its own run. It has the same tools and the same stop rules, and it keeps a transcript of its own. What differs is the count. The child's budget counts the child's own model calls, from its first call, so the parent's steps don't pay for the child's work, and a child that loops runs out of its own budget. That is the count chapter 5 promised a child: its own steps, not the parent's. A child's run_tests goes through the same sandboxed test runner as its parent's, with the caps, clean environment and no conftest files that chapter 7 describes, because the child is given the same tool set. The path is run_tests in lib/tools.py, then run_pytest and run_command there, then run_sandboxed in lib/sandbox.py. No example runs a child's command any other way.
Give the child 4 steps and run it on T-01. The task-set recording's first steps, from the model of chapter 1, replay for it, so the child does what the recorded run did at the start.
1"""A child loop on T-01 with a budget of 4 steps. The budget counts the child's own model calls, and it ends the child2as step_cap with no finish. The child's requests match the recording's first four steps, so they replay."""3from lib.case import load_tasks4from lib.models import ReplayModel5from lib.subagents import run_child6from lib.tools import V17from lib.trace import IdCounter89BUDGET = 410task = load_tasks(only=["T-01"])[0]11child = run_child(ReplayModel("task-set", "T-01"), task, V1, budget=BUDGET, ids=IdCounter())12print("child budget, steps:", BUDGET)13print("child steps:", child.handoff.steps)14print("child result:", child.handoff.ended)15print("child tools:", ", ".join(child.tool_names))16print("child steps, in order:", *child.trace, sep="\n ")17child.run.close()18assert child.handoff.ended == "step_cap" and child.handoff.steps == BUDGET
python child-with-budget.pychild budget, steps: 4
child steps: 4
child result: step_cap
child tools: list_files, read_file, run_tests, write_file, edit_file, ask_user, finish
child steps, in order:
step 1: list_files: 25 files
step 2: read_file: 23 lines
step 3: edit_file: error: old text not found in unitcraft/format.py
step 4: read_file: 23 lines
The budget, not the tools, ended this child: it used all its steps and never called finish. Its budget counts model calls, 4 of them here against a budget of 4, and the harness ends the child as step_cap. Its tools are the full tool set v1, list_files, read_file, run_tests, write_file, edit_file, ask_user, finish, so the budget is what holds the child back, not a smaller tool set.
Those 4 steps are the child's whole run. It lists the files, reads one, tries an edit that fails because the old text isn't in the file as written, and reads the file again. Nothing in the budget cares which of those steps was useful. It counts them.
A parent can start the same child itself, through a tool. In the next example the parent is a loop with two tools, start_child and ask_user. It starts the child on T-02 under both stop rules, reads the child's handoff as the tool's result, and asks the person the question the handoff carries.
1"""A parent loop starts the child on T-02 through a tool, reads the child's handoff and asks the person the child's2question. The output counts the parent's steps apart from the child's, and shows that the child's file text stays out of3the parent's context."""4from lib.case import load_tasks5from lib.loop import Stops, run_task6from lib.models import ReplayModel7from lib.subagents import ParentReadsHandoff, characters, start_child_tools8from lib.tools import V19from lib.trace import IdCounter1011RULES = Stops(repeat_limit=3, no_progress_limit=2)12task = load_tasks(only=["T-02"])[0]13child_ids = IdCounter()14child_ids.next("run") # the recording numbers its runs in task order, so T-02 is run-0002: skip T-01's number15children = []16tools = start_child_tools(task, lambda: ReplayModel("task-set", task.id), ids=child_ids, stops=RULES, children=children)17parent_model = ParentReadsHandoff(task.id)18parent = run_task(parent_model, task, tools, max_steps=tools.step_cap, ids=IdCounter())19child = children[0]20h = child.handoff21# the child's longest tool result is its read of the library file, the text a parent must not receive22file_text = max((m["content"] for m in child.transcript if m["role"] == "tool"), key=len)23parent_text = "\n".join(m["content"] for m in parent_model.messages)24print("child budget, steps:", V1.step_cap)25print("child steps:", h.steps)26print("child result:", h.ended)27print("parent steps:", parent.steps)28print("parent result:", parent.ended)29print("parent tools:", ", ".join(t.name for t in tools.tools))30print("question asked matches the handoff:", "yes" if parent.question == h.question else "no")31print("child transcript, characters:", characters(child.transcript))32print("handoff in parent context, characters:", len(h.text))33print("parent context at last step, characters:", characters(parent_model.messages))34print("child file text in parent context:", "yes" if file_text in parent_text else "no")35print("parent steps, in order:", *parent.trace.lines(), sep="\n ")36assert h.ended == "no_progress" and parent.ended == "ask_user" and parent.steps == 237assert parent.question == h.question and file_text not in parent_text38parent.close()
python parent-starts-child.pychild budget, steps: 16
child steps: 5
child result: no_progress
parent steps: 2
parent result: ask_user
parent tools: start_child, ask_user
question asked matches the handoff: yes
child transcript, characters: 5408
handoff in parent context, characters: 436
parent context at last step, characters: 1041
child file text in parent context: no
parent steps, in order:
step 1: start_child: child no_progress at step 5
step 2: ask_user: ask_user
The parent's question is the child's, word for word, and the child's file text is not in the parent's context. The child takes 5 steps of its own budget, and the parent takes 2, one to start the child and one to ask. The parent receives a handoff of 436 characters, where the child's transcript holds 5408.
The end is a stop like any other. A child that reaches its budget ends without a finish, and the handoff in the section on stops carries that end to the parent, which is where the next decision goes.
Working rule: Give each child a budget of its own, counted in its own model calls and never shared with the parent. Set it from runs that finished on the task set, not from a guess. A budget below what finished runs need turns finished work into stops.
4つの部分からなるブリーフ
ブリーフとは、子エージェントが受け取る形での仕事である。ここでは子エージェントが受け取るのは issue の本文だけである。summary-to-parent の T-02 の子エージェントは、そのタスク自身の issue から作業を始め、親が書いたものは何も受け取らない。Anthropic によるマルチエージェント・リサーチシステムの解説は、各サブエージェントのブリーフに必要な4つの部分を挙げている。目的、出力形式、使うツールと情報源についての指針、そして明確なタスクの境界である。この4つの部分に沿って書くと、T-02 の子エージェント向けのブリーフは次のようになる。
Objective: find out why the two edits to unitcraft/format.py left the test result where it was.
Output format: a short summary, then the files read and the files edited.
Tools and sources: read_file and run_tests on the scratch copy; edit_file only on unitcraft/format.py.
Boundaries: do not change a test or any file other than unitcraft/format.py. If the fix needs a public name changed, call ask_user instead of editing.
各部分は、T-02 の場合に起こりやすい失敗を防ぐ。目的は、子エージェントを2つの編集にとどめ、ライブラリの他の部分に向かわせない。出力形式により、親は結果を一度で読める。ファイルは、親が探す末尾に置かれる。ツールと情報源の行は、子エージェントが編集してよいファイルを示す。これらの例の子エージェントは、write_file を含む完全なツールセット v1 を持つので、この行は親が書くテキストにすぎず、ここでは何もそれを強制しない。ハンドオフの files changed の行は、子エージェントがどのファイルを変更したかを後から示し、edits failed の行は、適用されなかった編集の数を示す。境界は、保守担当者が最初に確認する部分である。見えているテストが検証手段であり、テストを編集すれば、修正がなくても合格してしまうからである。
ブリーフは親が書くテキストであり、本章ではその効果を測定しない。同じ解説は、測定ではなく観察として、曖昧なタスクを与えられたサブエージェントが互いの検索を重複させることがあり、明示的なブリーフがベンダーの対策であったと報告している。ここには、曖昧なブリーフを検証する例はない。ブリーフについて確認できるようになるのは境界である。返ってくるものの節のハンドオフには、子エージェントが読んだファイルと変更したファイルが列挙されており、それらを境界の行と一行ずつ突き合わせることができる。
実践ルール: 子エージェントを開始する前に、4つの部分をすべてブリーフに書く。境界は、意図ではなく、ファイルとツールとして書く。子エージェントがいつ完了するのか、またどのファイルを編集してよいのかを述べられないブリーフは、送る準備ができていない。
返される内容
T-02 の実行は、読み込んだすべてのファイル、失敗したすべての編集、実行したすべてのテストを記録した書き起こしを残す。これは親が必要とする量をはるかに超えている。親に必要なのは、子の結果と、その結果を判断するのに足りるだけの子の経路である。読み込みの内容は必要ない。停止した子にも同じ扱いが必要であり、そこに停止理由と質問が加わる。
T-02 を、タスクセットのステップ上限を設定したうえで両方の停止規則のもとで子として実行し、親が受け取る内容を子の書き起こしの大きさと並べて表示する。
1"""T-02's recorded run as a child, with both stop rules and the task set's step cap. The parent gets the2handoff's fields and not the child's transcript; the example prints the size of each."""3from lib.case import load_tasks4from lib.loop import Stops5from lib.models import ReplayModel6from lib.subagents import characters, run_child, tokens7from lib.tools import V18from lib.trace import IdCounter910RULES = Stops(repeat_limit=3, no_progress_limit=2)11task = load_tasks(only=["T-02"])[0]12ids = IdCounter()13ids.next("run") # the recording numbers its runs in task order, so T-02 is run-0002: skip T-01's number14child = run_child(ReplayModel("task-set", "T-02"), task, V1, budget=V1.step_cap, ids=ids, stops=RULES)15h = child.handoff16print("child result:", h.ended, "at step", h.steps, "of", h.budget)17print("transcript messages:", len(child.transcript))18print("child transcript, characters:", characters(child.transcript))19print("child transcript, estimated tokens:", tokens(characters(child.transcript)))20print("parent receives, characters:", len(h.text))21print("parent receives, estimated tokens:", tokens(len(h.text)))22print("saved by the handoff, characters:", characters(child.transcript) - len(h.text))23print("what the parent receives:")24print(h.text)25child.run.close()26assert task.issue not in h.text and len(h.text) < characters(child.transcript)
python summary-to-parent.pychild result: no_progress at step 5 of 16
transcript messages: 12
child transcript, characters: 5408
child transcript, estimated tokens: 1803
parent receives, characters: 436
parent receives, estimated tokens: 146
saved by the handoff, characters: 4972
what the parent receives:
child: child-0001
ended: no_progress
steps: 5 of 16
tried: edit_file 2, list_files 1, read_file 2
files read: unitcraft/format.py
files changed: none
edits failed: 2
stop: no_progress (edit_file, 2 edits in a row left the test result unchanged: 8 failed, 22 passed)
question: The last 2 edits left the test result unchanged (last result: 8 failed, 22 passed). Should a person look at unitcraft/format.py, or should the agent keep going?
親が受け取るのは引き継ぎだけである。子は no_progress at step 5 of 16 として終了し、子が保持した書き起こしは 5408 文字に達する。親が読む引き継ぎは 436 文字である。
引き継ぎの変更したファイルの行は none と表示され、失敗した編集の行は 2 と表示される。どちらの編集も unitcraft/format.py を対象としていたが、ファイルのバイト列は変わらなかった。そのため、変更の行はこのファイルを含めず、失敗の数が編集の適用されなかったことを示す。
トークン数で見ると、同じ差は 1803 対 146 となる。これらは第5章の規則で求めた推定値であり、モデルのトークナイザによる計数ではない。本章ではサイズの比較にのみ用いる。
引き継ぎの各行は決まった順序で並ぶ。子の ID、終了の仕方、予算に対するステップ数、試したツールとその回数、読み込んだファイル、変更したファイル、失敗した編集の数、そして停止理由と質問である。完了した子は、停止と質問の代わりに要約を渡す。完了した子は数えられるが、その要約は表示されないため、その行はどの出力にも現れない。この例は、イシューの本文が引き継ぎの中にそのまま現れないことを確認する。これにより、親はタスクの文言ではなく、子が行ったことをもとに作業する。
親が引き継ぎをどう扱うかは親の選択であり、本章では台本を示さない。本章のコードが組み立てる選択肢は一つである。親が質問を保守担当者に尋ねる。同じ配線で、引き継ぎに挙がっているファイルを名指しした、より絞った指示を持つ二つ目の子を起動することもできるし、フィールドだけから答えることもできる。そのどちらも例としては作らない。どちらの場合も子の書き起こしは親のコンテキストの外に置かれ、これが引き継ぎを設ける本来の理由である。
子自身の記録は保持され、第11章が追跡するのはこの記録である。親はそれを開かない。
実践ルール: 親には、子の ID、終了の仕方、各種の数、ファイル、そして停止または要約だけを返し、それ以外は返さない。書き起こしは、追跡が読める子自身の記録の中に残す。
この部分はまだ翻訳されていないため、英語で表示している。
A stop handed back
The T-02 run ends stuck, and a stop alone doesn't tell the maintainer what to decide. Chapter 2 gave each stop a name and a reason, but someone still has to choose between taking the task from the agent, giving it more steps and trying another approach. That someone is the maintainer who filed the issue. So a stop that the harness can't resolve becomes a handoff to a parent, and the parent asks the maintainer.
The alternative is to log the stop and drop the run. That keeps the parent's context small, and it leaves the decision with nobody. The handoff keeps the decision with the maintainer, and costs the parent one short step in the runs below.
For the three stops that end a child stuck, step_cap, repeated_call and no_progress, the harness builds the handoff from the run's own record: its trace, its streak of repeated calls and its test counts. The stop reason, the counts and the question all come from that record. No model writes them, so a replayed run gives the same handoff every time. The parent is a loop of its own, with a small step budget and two tools, ask_user and finish. In a live design the parent would be a model that words the question to the maintainer. Here a scripted parent passes the question on exactly as the handoff gives it, so the run shows the wiring and not a model's judgement.
A child that ends some other way is not handed back. A run that ends as no_tool_call, for example, gives a handoff with no stop reason and no question, so the parent has nothing to put to the person. No run here ended that way (0 of the runs), so no example shows it.
Run every task-set run as a child under both stop rules. Each child that ends stuck goes to a parent, which asks the person its question.
1"""The 20 task-set runs as children, with both stop rules. Each child that ended stuck is handed to a parent, which2puts the stop's question to the person with ask_user. Counts only: how the children ended, and what the parents got."""3from collections import Counter45from lib.loop import Stops6from lib.models import ScriptedModel7from lib.subagents import STUCK, asks, characters, hand_to_parent, task_set_children8from lib.trace import IdCounter910RULES = Stops(repeat_limit=3, no_progress_limit=2)11ENDS = ("finish", "ask_user", "step_cap", "repeated_call", "no_progress", "no_tool_call")12children = task_set_children(RULES)13stuck = [(task, h, transcript) for task, h, _, transcript in children if h.stuck]14ends = Counter(h.ended for _, h, _, _ in children)15print("child runs:", len(children))16for ended in ENDS:17 print(f" {ended}: {ends[ended]}")18print("done with the rules:", sum(1 for _, _, ok, _ in children if ok))19print("ended with finish or ask_user:", sum(1 for _, h, _, _ in children if h.ended in ("finish", "ask_user")))20print("done among the handed back:", sum(1 for _, h, ok, _ in children if h.stuck and ok))21print("handed back to a parent:", len(stuck))22handed = Counter(h.ended for _, h, _ in stuck)23for ended in STUCK:24 print(f" {ended}: {handed[ended]}")25print("handed back, tasks:", ", ".join(task.id for task, _, _ in stuck))2627parent_ids = IdCounter() # the parents number their runs apart, so the children's run IDs stay the recording's28parents = [(h, hand_to_parent(ScriptedModel([asks(h.question)]), h, parent_ids)) for _, h, _ in stuck]29print("parent asked the person, with the handoff's question:",30 sum(1 for h, r in parents if r.ended == "ask_user" and r.question == h.question))31print("child steps, all handed back:", sum(h.steps for _, h, _ in stuck))32print("parent steps, all handed back:", sum(r.steps for _, r in parents))33print("child transcripts, characters:", sum(characters(t) for _, _, t in stuck))34print("handoffs the parents read, characters:", sum(len(h.text) for _, h, _ in stuck))35print("saved by the handoffs, characters:",36 sum(characters(t) for _, _, t in stuck) - sum(len(h.text) for _, h, _ in stuck))37assert all(h.stop and h.question for _, h, _ in stuck), "every stuck child gives a stop reason and a question"38assert not any(ok for _, h, ok, _ in children if h.stuck), "a done task must not be handed back"
python handoff-on-stuck.pychild runs: 20
finish: 6
ask_user: 1
step_cap: 1
repeated_call: 1
no_progress: 11
no_tool_call: 0
done with the rules: 5
ended with finish or ask_user: 7
done among the handed back: 0
handed back to a parent: 13
step_cap: 1
repeated_call: 1
no_progress: 11
handed back, tasks: T-01, T-02, T-03, T-06, T-10, T-11, T-12, T-13, T-15, T-16, T-17, T-19, T-20
parent asked the person, with the handoff's question: 13
child steps, all handed back: 83
parent steps, all handed back: 13
child transcripts, characters: 95252
handoffs the parents read, characters: 5874
saved by the handoffs, characters: 89378
None of the runs a stop handed back was done. The rules hand back 13 of the 20 runs, and none of those is done. Each one reaches a parent, and the parents put the question to the person 13 times, once for each. The stop that comes up most is no_progress, the same stop T-02 ended on.
The stop rules cost no finished work. 7 runs ended with finish (6) or with ask_user (1), and all 5 done runs are among them, because none of the handed-back runs was done. The other runs in that group are not done, and none of them ended on a stop rule, so no handoff covers them. A run that ends with finish or ask_user never reaches a parent under these rules, whether or not it was right to end there.
The handed-back runs are T-01, T-02, T-03, T-06, T-10, T-11, T-12, T-13, T-15, T-16, T-17, T-19, T-20. Between them their children took 83 steps, and their parents took 13 steps, one each, the call that asks the person.
The children's transcripts held 95252 characters, and the parents read 5874 characters of handoff between them. Every handed-back child is checked to give a stop reason and a question. That checks the shape of the handoff, and it doesn't check that the question is the right one to ask.
The question for the T-02 run ends: "Should a person look at unitcraft/format.py, or should the agent keep going?" It names the file that both failed edits named, so the maintainer knows where to look without opening the transcript. The handoff's files changed line says no file changed, so the question points at a file the edits named but never changed.
One caveat, said once: a handoff says that a run stopped and why. It doesn't say the task could not be finished. This book counts a handed-back run as not done, as the example does.
Working rule: Hand every stuck stop (step_cap, repeated_call, no_progress) to a person as a question, with its stop reason, its counts and its files. A parent works from the handoff. The child's record stays with the child, where a trace can read it.
二つの設計と、誰の数値か
分割にどちらの設計を用いるべきかは、親が子の結果をどう扱う必要があるかによって決まる。広く使われている設計は二つあり、会話の扱いが異なる。この章の設計では、子は結果を返して終了する。SDK のハンドオフでは、会話が別のエージェントに移る。SDK は後者の設計にハンドオフという語を使っているが、これは本章でのハンドオフの意味ではない。この節の内容はここでは何も実行しておらず、示す数値はそれぞれの出典のものである。
OpenAI Agents SDK のハンドオフに関するドキュメント(2026年11月に取得した SDK 0.24.0 版)は、後者を説明している。ハンドオフとは、モデルが呼び出すツールであり、転送先にちなんで名付けられる。その例が transfer_to_refund_agent である。受け取る側のエージェントは、入力フィルタが見える内容を変えない限り、それまでの会話全体を見る。会話を引き継がずに結果だけを返す専門エージェントについては、同じページがエージェントをツールとして包む方法を勧めており、それには Agent.as_tool を使う。それまでの会話を要約するネスト履歴は、オプトイン式のベータ機能であり、既定では無効である。
Claude Code のサブエージェントのドキュメント(2026年11月に取得)は、前者の種類を説明している。サブエージェントにはエージェントとしてのターン数に上限があり、本書ではこれをステップと呼ぶことになるが、その設定は maxTurns である。サブエージェントが上限に達すると、その出力は部分的であるという印を付けて返され、親はそれを再開できる。このページは、部分的であるという印について「Claude Code v2.1.246 以降が必要」と述べているが、そのバージョンではここで何も実行していない。組み込みのサブエージェントは親の権限ルールを継承し、その多くは制限されたツールセットで動作する。カスタムのサブエージェントは、独自のツールと独立した権限を持つ。この形は本章の予算と一致しており、部分的な結果の役割をハンドオフが担っている。
この節が引用する測定は、測定対象のシステムを作った企業によるものである。2025年6月、Anthropic による自社のリサーチシステムの解説は、「リードエージェントに Claude Opus 4、サブエージェントに Claude Sonnet 4 を用いたマルチエージェントシステムは、社内のリサーチ評価において、単一エージェントの Claude Opus 4 を 90.2% 上回った」と報告した。この比較は、マルチエージェントシステムを単一のエージェントと比べたものであり、サブエージェントには別のモデルが使われ、評価の指標も記事には示されていない。記事によれば、その評価は幅優先のクエリを重視しており、そこでは多くの独立した方向を同時に追える。
同じ記事は、BrowseComp 評価における二つ目の測定を示している。「トークン使用量だけで分散の 80% が説明される」というものである。記事は、マルチエージェントシステムが機能するのは主に、問題を解くのに十分なトークンを使うからだと述べている。記事自身のデータでは、エージェントはチャットの約4倍、マルチエージェントシステムは約15倍のトークンを使っていた。また、エージェントが一つのコンテキストを共有しなければならない領域や、互いに多くの点で依存し合う領域は適していないこと、リードエージェントはサブエージェントをバッチで実行し、各組の完了を待っていたことも述べている。分割は、複数のエージェントがあるからといって並列になるわけではない。
分割に反対する広く読まれた議論は、2025年に Cognition が公開した Walden Yan のエッセイ「Don't Build Multi-Agents」に見られる。その第一原則は「コンテキストを共有し、個々のメッセージだけでなく、エージェントのトレース全体を共有せよ」である。ハンドオフはこの原則に反する。ハンドオフが渡すのは子のフィールドとその要約または停止であり、トレース全体は渡さない。エッセイの第二原則は、行動には暗黙の決定が伴うため、別々に動くエージェントは互いに矛盾する決定に基づいて行動しうる、というものである。これはエッセイであり、一人の実務家の判断である。
エッセイが原則に従う最も単純な方法は、連続したコンテキストを持つ一本の線形なエージェントである。非常に長いタスクについては、履歴を重要な詳細、出来事、決定に圧縮するモデルを提案しているが、それを正しく行うのは難しいとも述べている。これは第5章のコンパクションと、このハンドオフに近い。エッセイは、明確に定義された問いに答え、通常はコードを書かないサブエージェントも認めている。
本章の例の子はコードを書く。T-02 の子は unitcraft/format.py を編集しており、これはエッセイが反対する場合にあたる。ここでは編集するのは一つの子であり、親はそのファイルを編集しないので、第二原則が述べる衝突はこれらの例では起こらない。それでも、子が編集を行った理由は親に届かず、それに対するエッセイの異議は残る。それでも本書が子を作るのは、T-02 の場合にライブラリを変更できる子が必要だからである。分割が成り立つのは、結果をその理由なしに使える場合であり、これは製品ドキュメントが述べている場合である。
結果が単独で成り立つ副次的なタスクには子を、親と子が同じファイルを編集することになる作業には一つのループを勧める。
実践ルール: 結果をその理由なしに使えるとき、すなわち事実、ファイルの一覧、または問いを伴う停止であるときは、子を使う。子が編集するファイルに対して親が行動しなければならないときは、一つのループにとどめる。本書は分割と一つのループを比較して測定していないので、このルールは測定ではなく、上の議論に基づいている。
この部分はまだ翻訳されていないため、英語で表示している。
What goes wrong in production
Splitting work brings failures that a single loop doesn't have. The first is a budget in the wrong unit. A budget counted in seconds stops a child for a slow test run as readily as for a loop, and a replay can't repeat it, because the same run takes a different time each time. That is why this chapter counts model calls and no time.
The second is a parent that decides for the person. The parent in handoff-on-stuck has finish as well as ask_user among its tools, so a model that thinks it knows the answer can end a stuck run without asking anyone. In production, a parent handed a stop should have only the means to ask, and a stop that reaches it should always end with a question to the maintainer.
The third is a split the parent can't reconcile. Two children that edit the same file can each hand back a clean summary, and the parent then has to open both records to see that their edits disagree. The handoff doesn't show that disagreement by itself, which is the point of the counter-view.
The fourth is cost that doesn't show. A child's tokens are its own, and the vendor's figure puts a multi-agent system at about fifteen times a chat's tokens. Trace each child's tokens on its own record, as chapter 11 does, or the cost of a split never reaches the parent's count.
Working rule: Count a child's budget in model calls, give its parent only the means to ask, and check each split's edits against the files the other children changed before you merge them. Trace each child's tokens on its own record, so a split's cost is counted where it is spent.
この章で決めたこと
メンテナにとっての変化は、T-02 の停止が一つのファイルについての質問として届くようになったことである。従来の停止は、メンテナが読まなければならないログで終わり、判断は何も添えられていなかった。この設計では、停止は関連するファイルと、見るべきファイルを示す質問を伴ってメンテナに届く。以下の選択はいずれも変更の余地があり、どれも実行が失敗したときにメンテナが目にするものを変える。最初の三つは、子が何を消費してよいか、何を返すか、停止の理由がどこから来るかを決める。最後の三つは、子を切り出す価値があるのはいつか、子が完了できないときに誰が答えるかを決める。
- 子の予算は子自身のモデル呼び出しを数え、親の呼び出し数には子の分を含めない。
- 子はフィールドと、その要約または停止を返し、トランスクリプトは返さない。トランスクリプトは子自身の記録に残る。
- 停止の理由、件数、質問は、コードが作成した実行の記録から得る。このため、リプレイでも同じ引き継ぎが得られる。
- 行き詰まった子は、ステップ予算の小さい親に渡される。親は
ask_userを通じて、その issue を起票したメンテナに尋ねる。 - 子は、結果が単独で成り立つ副次的なタスクのために使う。親と子が同じファイルを編集する作業は、一つのループにとどめる。
- 質問として人に届く停止は、ログで終わる停止より有用である。第 12 章では、どのような分割もエージェントも、そのコストに見合わない場合を扱う。
この版における本章
第2026.11.2版2026年11月20日時点で例が通過この章の4 例件のうち4件が合格
英語版の書籍(版2026.11.2)から翻訳した。