講座 › 分野1 エージェントとワークフロー
1.2 Claudeによるエージェントの構築
エージェントの作り方は3段階。Messages APIで自分のループを書く、Agent SDKでClaude Codeのループを組み込む、Managed Agentsで実行基盤ごと任せる。
自分でループを書く(Messages API) 読了

Messages APIを直接使うと、エージェントのループを自分で書けます。Claudeが応答に tool_use ブロックを返したら、アプリが引数を取り出して処理を実行し、結果を tool_result として送り返します。これを最終回答まで繰り返します。細かく制御したいときに向いています。SDKのツールランナーを使うと、このループと型の扱いを自動化できます。
出典:How tool use works
When Claude calls one of your tools, the API response contains a `tool_use` block with the tool name and a JSON object of arguments.https://platform.claude.com/docs/en/agents-and-tools/tool-use/how-tool…(取得 2026-11-17)
出典:Claude Managed Agents overview
Custom agent loops and fine-grained controlhttps://platform.claude.com/docs/en/managed-agents/overview.md(取得 2026-11-17)
出典:Tool runner
The tool runner handles the agentic loop, error wrapping, and type safety so you don’t have to.https://platform.claude.com/docs/en/agents-and-tools/tool-use/tool-run…(取得 2026-11-17)
Claude Agent SDK 読了

Agent SDKは、Claude Codeを動かしているのと同じエージェントループを、自分のPythonやTypeScriptのアプリに組み込むライブラリです。組み込みのツール、権限、セッション、フック、サブエージェントなどをそのまま使えます。Claudeはプロンプトを評価し、ツールを呼び、結果を受け取る流れを、作業が終わるまで繰り返します。
出典:Agent SDK overview
A library that runs the Claude Code binary, with Claude Code's capabilities, such as built-in tools, permissions, sessions, and hooks.https://code.claude.com/docs/en/agent-sdk/overview.md(取得 2026-11-17)
出典:How the agent loop works
Claude evaluates your prompt, calls tools to take action, receives the results, and repeats until the task is complete.https://code.claude.com/docs/en/agent-sdk/agent-loop.md(取得 2026-11-17)
マネージドエージェント:Anthropicホストとセルフホスト 読了

Claude Managed Agentsは、エージェントのハーネスと実行基盤を提供します。自分でループやツール実行の仕組みを作らずに、ファイルの読み書きやコマンド実行ができる環境を使えます。数分から数時間かかる長い作業や、非同期の作業に向いています。セルフホスト版では、サービスとサンドボックスを自社のクラウドやデータセンターに置きます。
出典:Claude Managed Agents overview
Instead of building your own agent loop, tool execution, and runtime, you get a fully managed environmenthttps://platform.claude.com/docs/en/managed-agents/overview.md(取得 2026-11-17)
出典:Claude Managed Agents overview
Tasks that run for minutes or hours with multiple tool callshttps://platform.claude.com/docs/en/managed-agents/overview.md(取得 2026-11-17)
出典:Managed Agents self-hosted
Self-hosted Claude Managed Agents is Managed Agents on your own infrastructure, which can be a cloud account or an on-premise data center.https://platform.claude.com/docs/en/managed-agents/self-hosted.md(取得 2026-11-17)
決定論的な動作はフックで 読了

「必ず実行したい」「必ず止めたい」処理は、モデルの判断に任せずフックで実装します。フックは、ツールが呼ばれる直前(PreToolUse)や直後(PostToolUse)などのタイミングで、自分のコードを実行する仕組みです。危険なコマンドを実行前に止める、といった使い方ができます。
出典:Hooks guide
which gives you deterministic control: certain actions always happen rather than relying on the LLM to choose to run themhttps://code.claude.com/docs/en/hooks-guide.md(取得 2026-11-17)
出典:Agent SDK hooks
Block dangerous operations before they execute, like destructive shell commands or unauthorized file accesshttps://code.claude.com/docs/en/agent-sdk/hooks.md(取得 2026-11-17)
- 細かい制御が欲しいならMessages APIで自作、Claude Codeと同じ道具が欲しいならAgent SDK、長時間・非同期の作業を基盤ごと任せたいならManaged Agents。
出典:Claude Managed Agents overview
Pre-built, configurable agent harness that runs in managed infrastructure. Best for long-running tasks and asynchronous work.
https://platform.claude.com/docs/en/managed-agents/overview.md(取得 2026-11-17) - 「プロンプトでお願いする」は強制にならない。必ず守らせたい動作はフックで決定論的に実装する。
出典:Hooks guide
certain actions always happen rather than relying on the LLM to choose to run them
https://code.claude.com/docs/en/hooks-guide.md(取得 2026-11-17)