講座 › 分野1 エージェントアーキテクチャとオーケストレーション
1.1 エージェントループの設計
配点 3.9%Agentic loops
エージェントは、Claudeに頼み、道具を実行し、結果を返す、という流れを繰り返す。続けるか止めるかは、応答の終わり方を表す値(stop_reason)で決める。
未読
ループの一周:頼む、実行する、返す 読了

エージェントのループは、Claudeがツールの呼び出しを求めるたびに、プログラム側がそのツールを実行し、結果を渡して次の判断をさせる繰り返しです。ツール呼び出しのない応答が出たところで、ループは終わります。
出典:How the agent loop works
Claude continues calling tools and processing results until it produces a response with no tool calls.https://code.claude.com/docs/en/agent-sdk/agent-loop.md(取得 2026-11-20)
出典:How the agent loop works
A turn is one pass through the loop: Claude produces output, and if it includes tool calls, the SDK executes them and the results feed back to Claude automatically.https://code.claude.com/docs/en/agent-sdk/agent-loop.md(取得 2026-11-20)
続けるか止めるかは stop_reason で決める 読了

基本形は、stop_reason が tool_use の間は、ツールを実行して会話を続けるループです。end_turn などそれ以外の値が来たら抜けます。max_tokens や refusal は、最終回答ではなく、別の対応が要る終わり方です。
出典:How tool use works
In practice this reads as: while stop_reason == "tool_use", run the tools and continue the conversation.https://platform.claude.com/docs/en/agents-and-tools/tool-use/how-tool…(取得 2026-11-20)
出典:How tool use works
The loop exits on any other stop reason ("end_turn", "max_tokens", "stop_sequence", or "refusal")https://platform.claude.com/docs/en/agents-and-tools/tool-use/how-tool…(取得 2026-11-20)
ツールの結果を会話に足す 読了

ツールを実行したら、その結果を履歴に足して次のリクエストで送ります。ツール呼び出し1件につき結果を1件返し、失敗したときも省きません。失敗は is_error を付けて返し、再試行の回数には上限を設けます。
出典:Handle tool calls
Add a user message with one tool_result block for each tool_use block in that content, even if the tool failed.https://platform.claude.com/docs/en/agents-and-tools/tool-use/handle-t…(取得 2026-11-20)
出典:Handle tool calls
When a client tool fails or a call is invalid, send a tool_result block with is_error set to true.https://platform.claude.com/docs/en/agents-and-tools/tool-use/handle-t…(取得 2026-11-20)
出典:Handle tool calls
Claude might then call the tool again with a new tool_use block, so limit how many retries your loop allows.https://platform.claude.com/docs/en/agents-and-tools/tool-use/handle-t…(取得 2026-11-20)
出典:Claude Certified Architect – Foundations Exam Guide v1.0(英語)
How tool results are appended to conversation history so the model can reason about the next actionhttps://everpath-course-content.s3-accelerate.amazonaws.com/instructor…(取得 2026-11-20)
次の一手を決めるのは誰か 読了

手順があらかじめ決まっているなら、固定の流れで組めます。次に何のツールを使うかを状況から決めさせたいときが、エージェントの出番です。道筋を決め打ちできない、先の見えない課題に向きます。
出典:Building effective agents
They are typically just LLMs using tools based on environmental feedback in a loop.https://www.anthropic.com/research/building-effective-agents(取得 2026-11-20)
出典:Building effective agents
Agents can be used for open-ended problems where it’s difficult or impossible to predict the required number of steps, and where you can’t hardcode a fixed path.https://www.anthropic.com/research/building-effective-agents(取得 2026-11-20)
出典:Claude Certified Architect – Foundations Exam Guide v1.0(英語)
The distinction between model-driven decision-making (Claude reasons about which tool to call next based on context) and pre-configured decision trees or tool sequenceshttps://everpath-course-content.s3-accelerate.amazonaws.com/instructor…(取得 2026-11-20)
やってはいけない終了判定と、上限の位置づけ 読了

「完了しました」という文面を読み取って終わらせる、文章が出たら終わりとみなす、回数の上限だけで止める。どれも終了判定の主役にしてはいけません。上限は暴走を防ぐ安全装置として、予算とともに置きます。
出典:Claude Certified Architect – Foundations Exam Guide v1.0(英語)
Avoiding anti-patterns such as parsing natural language signals to determine loop termination, setting arbitrary iteration caps as the primary stopping mechanism, or checking for assistant text content as a completion indicatorhttps://everpath-course-content.s3-accelerate.amazonaws.com/instructor…(取得 2026-11-20)
出典:How the agent loop works
Without limits, the loop runs until Claude finishes on its own, which is fine for well-scoped tasks but can run long on open-ended promptshttps://code.claude.com/docs/en/agent-sdk/agent-loop.md(取得 2026-11-20)
出典:How the agent loop works
Setting a budget is a good default for production agents.https://code.claude.com/docs/en/agent-sdk/agent-loop.md(取得 2026-11-20)
試験のポイント
- 続ける条件は stop_reason が tool_use、終わる条件は end_turn。
出典:How tool use works
In practice this reads as: while stop_reason == "tool_use", run the tools and continue the conversation.
https://platform.claude.com/docs/en/agents-and-tools/tool-use/how-tool…(取得 2026-11-20) - ツール結果は、失敗も含めて、1件ずつ履歴に足して返す。
出典:Handle tool calls
Add a user message with one tool_result block for each tool_use block in that content, even if the tool failed.
https://platform.claude.com/docs/en/agents-and-tools/tool-use/handle-t…(取得 2026-11-20) - 文面の解析・文章の有無・回数の上限を、終了判定の主役にしない。
出典:Claude Certified Architect – Foundations Exam Guide v1.0(英語)
Avoiding anti-patterns such as parsing natural language signals to determine loop termination, setting arbitrary iteration caps as the primary stopping mechanism, or checking for assistant text content as a completion indicator
https://everpath-course-content.s3-accelerate.amazonaws.com/instructor…(取得 2026-11-20)