ポッドキャストに戻るClaude
Claude Code subagents
効果的なサブエージェントの設計方法
Now that you know how to create sub aents, let's look at patterns that lead to effective sub aents.
サブエージェントの作り方を理解したところで、効果的なサブエージェントにつながるパターンを見ていきましょう。
First, let's get a better idea of how subit data in the sub aent config file is used.
まず、サブエージェントの設定ファイルのデータがどのように使われるかを詳しく確認します。
Whenever you send a message to the main context window agent, the name and description of each sub aent is included in the system prompt.
メインエージェントにメッセージを送るたびに、各サブエージェントの名前と説明が system prompt に含まれます。
So, if you want to better control when the main agent launches a sub agent automatically, you should modify the name and description.
メインエージェントがサブエージェントを自動的に起動するタイミングをより細かく制御したい場合は、名前と説明を変更してください。
Next, remember that when a sub agent is launched, the main agent writes an input prompt.
次に、サブエージェントが起動されるとき、メインエージェントが入力プロンプトを作成することを覚えておいてください。
When writing this input prompt, it uses the description as guidance.
この入力プロンプトを作成する際、説明をガイドとして使用します。
So, if you want to better control when the main agent launches a sub agent automatically, you should modify the name and description.
メインエージェントがサブエージェントを自動的に起動するタイミングをより細かく制御したい場合は、名前と説明を変更してください。
Let's consider our review sub aent again.
レビュー用サブエージェントをもう一度確認してみましょう。
Right now, when the main agent runs this sub agent, the sub aent is given an input prompt telling it to use get diff to find the current changes.
現在、メインエージェントがこのサブエージェントを実行すると、get diff を使って現在の変更を確認するよう指示する入力プロンプトが渡されます。
If we wanted the main agent to more reliably tell the sub agent exactly which files to review, we would update the description.
メインエージェントがレビュー対象のファイルをサブエージェントに正確に伝えられるようにするには、説明を更新します。
You must tell the agent precisely which files you want it to review.
レビューしたいファイルをエージェントに正確に伝えてください。
Now, if we ask claw to run the code reviewer agent, we'll see a different input.
Claude にコードレビュー用サブエージェントを実行させると、異なる入力が表示されます。
You can also influence what the main thread tells a sub agent through the description.
説明を通じて、メインスレッドがサブエージェントに伝える内容に影響を与えることもできます。
So adding return sources that can be cited to a web search sub aents description causes the main thread to include that instruction when delegating the task.
例えば、ウェブ検索サブエージェントの説明に「引用可能なソースを返す」と追加すると、メインスレッドはタスクを委任する際にその指示を含めるようになります。
The most important improvement that you can make is defining an output format in the system prompt.
最も重要な改善点は、system prompt に出力フォーマットを定義することです。
This creates natural stopping points for the sub aent.
これにより、サブエージェントに自然な終了ポイントが生まれます。
Without a defined output format, sub aents struggle to decide when enough research has been done and they tend to run much much longer than sub agents that are given an output format.
出力フォーマットが定義されていないと、サブエージェントは調査が十分かどうかを判断しにくく、フォーマットありのサブエージェントよりずっと長く実行し続ける傾向があります。
When a sub agent discovers a workaround to some issue like solving a dependency issue or finding that a certain command needs particular flags, these details should appear in the summary.
サブエージェントが問題の回避策を発見した場合、例えば依存関係の解決や特定のコマンドに特定のフラグが必要とわかった場合、その詳細はサマリーに記載してください。
Otherwise, the main thread has to rediscover the same solutions, obstacles encountered, any setup issues, workarounds discovered or environment quirks, commands that needed special flags or configuration, dependencies or imports that cause problems.
そうしないと、メインスレッドが同じ解決策を再発見しなければなりません。遇遇した障害、セットアップの問題、発見した回避策、環境の特殊事情、特別なフラグや設定が必要なコマンド、問題を起こす依存関係やインポートなどが対象です。
Explicitly asking for obstacle reporting in the output format surfaces this information.
出力フォーマットで障害の報告を明示的に求めることで、この情報が浮かび上がります。
A readonly sub aent using just glob grap read cannot accidentally modify files.
glob、grep、read だけを使う読み取り専用のサブエージェントは、ファイルを誤って変更することができません。
This constraint clarifies that the sub aents role and prevents unintended side effects.
この制約によってサブエージェントの役割が明確になり、意図しない副作用を防げます。
So think about what sub aents actually needs to do.
サブエージェントが実際に何をする必要があるかを考えてみましょう。
If it's just researching it only needs to read files.
調査だけなら、ファイルを読む権限だけで十分です。
So keep it read only.
読み取り専用にしてください。
That way it can't accidentally modify anything while exploring.
そうすることで、探索中に誤って何かを変更することがなくなります。
A reviewer needs to run get diff to see what changed.
レビュー担当サブエージェントは get diff を実行して変更を確認する必要があります。
So give it bash access, but it still doesn't need to edit files.
bash のアクセスを与えてください。それでもファイルを編集する必要はありません。
Only give edit and write to sub aents that should actually change your code, like a styling agent applying CSS updates.
edit と write は、CSS の更新を適用するスタイリングエージェントなど、実際にコードを変更するサブエージェントにのみ付与してください。
This also helps clarify what each sub aent is for when you have several of them.
複数のサブエージェントがある場合も、それぞれの役割が明確になります。
So effective sub aents use structured output report obstacles have specific descriptions and limit tool access.
効果的なサブエージェントは、構造化された出力を使い、障害を報告し、具体的な説明を持ち、ツールアクセスを制限します。