6 6
7> Claude Code をライブラリとして使用して、本番環境対応の AI エージェントを構築します7> Claude Code をライブラリとして使用して、本番環境対応の AI エージェントを構築します
8 8
9ファイルを自動的に読み取り、コマンドを実行し、ウェブを検索し、コードを編集するなど、さらに多くのことができる AI エージェントを構築します。Agent SDK は、Claude Code を強化する同じツール、エージェントループ、およびコンテキスト管理を提供し、Python と TypeScript でプログラム可能です。エージェントハーネス設計の背景については、ブログの「[A harness for every task: dynamic workflows in Claude Code](https://claude.com/blog/a-harness-for-every-task-dynamic-workflows-in-claude-code)」を参照してください。9エージェントは、独自のステップを計画し、ファイルを読み取る、コマンドを実行する、またはコードを編集するツールを呼び出すことでタスクを完了するアプリケーションです。Agent SDK は、Claude Code を強化する同じツール、[エージェントループ](/docs/ja/agent-sdk/agent-loop)、およびコンテキスト管理を提供し、Python と TypeScript でプログラム可能です。
10 10
11<CodeGroup>11<h2 id="compare-the-agent-sdk-to-other-claude-tools">
12 ```python Python theme={null}12 Agent SDK と他の Claude ツールの比較
13 import asyncio
14 from claude_agent_sdk import query, ClaudeAgentOptions
15
16
17 async def main():
18 async for message in query(
19 prompt="Find and fix the bug in auth.py",
20 options=ClaudeAgentOptions(allowed_tools=["Read", "Edit", "Bash"]),
21 ):
22 print(message) # Claude reads the file, finds the bug, edits it
23
24
25 asyncio.run(main())
26 ```
27
28 ```typescript TypeScript theme={null}
29 import { query } from "@anthropic-ai/claude-agent-sdk";
30
31 for await (const message of query({
32 prompt: "Find and fix the bug in auth.ts",
33 options: { allowedTools: ["Read", "Edit", "Bash"] }
34 })) {
35 console.log(message); // Claude reads the file, finds the bug, edits it
36 }
37 ```
38</CodeGroup>
39
40Agent SDK には、ファイルの読み取り、コマンドの実行、コードの編集用の組み込みツールが含まれているため、ツール実行を実装することなく、エージェントはすぐに動作を開始できます。クイックスタートに進むか、SDK で構築された実際のエージェントを探索してください。
41
42<CardGroup cols={2}>
43 <Card title="クイックスタート" icon="play" href="/ja/agent-sdk/quickstart">
44 数分でバグ修正エージェントを構築します
45 </Card>
46
47 <Card title="エージェントの例" icon="star" href="https://github.com/anthropics/claude-agent-sdk-demos">
48 メールアシスタント、リサーチエージェント、その他
49 </Card>
50</CardGroup>
51
52<h2 id="get-started">
53 はじめに
54</h2>13</h2>
55 14
56<Steps>15Agent SDK、CLI、Client SDK、および Managed Agents はそれぞれ異なるニーズに対応しています。構築しているものに合致するツールを見つけるために、表を使用してください。
57 <Step title="SDK をインストールします">
58 <Tabs>
59 <Tab title="TypeScript">
60 ```bash theme={null}
61 npm install @anthropic-ai/claude-agent-sdk
62 ```
63 </Tab>
64
65 <Tab title="Python (uv)">
66 [uv](https://docs.astral.sh/uv/) は、仮想環境を自動的に処理する高速な Python パッケージマネージャーです。
67
68 ```bash theme={null}
69 uv init
70 uv add claude-agent-sdk
71 ```
72 </Tab>
73
74 <Tab title="Python (pip)">
75 仮想環境を作成してアクティベートしてから、パッケージをインストールします。仮想環境にインストールすることで、最近の Debian、Ubuntu、Homebrew インストールのシステム Python が venv 外の `pip install` に対して返す `error: externally-managed-environment` エラーを回避できます。
76
77 macOS または Linux の場合:
78
79 ```bash theme={null}
80 python3 -m venv .venv
81 source .venv/bin/activate
82 pip install claude-agent-sdk
83 ```
84
85 Windows の場合:
86
87 ```powershell theme={null}
88 py -m venv .venv
89 .venv\Scripts\Activate.ps1
90 pip install claude-agent-sdk
91 ```
92
93 PowerShell が実行ポリシーエラーで `Activate.ps1` をブロックする場合は、まず `Set-ExecutionPolicy -Scope Process RemoteSigned` を実行してください。
94
95 Python パッケージには Python 3.10 以降が必要です。pip が `No matching distribution found for claude-agent-sdk` と報告する場合、インタープリターは 3.10 より古いバージョンです。macOS または Linux では `python3 --version` を実行するか、Windows では `py --version` を実行してバージョンを確認してください。
96 </Tab>
97 </Tabs>
98
99 <Note>
100 TypeScript SDK は、プラットフォーム用のネイティブ Claude Code バイナリをオプションの依存関係としてバンドルしているため、Claude Code を別途インストールする必要はありません。
101 </Note>
102 </Step>
103
104 <Step title="API キーを設定します">
105 [Console](https://platform.claude.com/) から API キーを取得し、環境変数として設定します。
106
107 macOS または Linux の場合:
108
109 ```bash theme={null}
110 export ANTHROPIC_API_KEY=sk-ant-xxxxx
111 ```
112
113 Windows PowerShell の場合:
114
115 ```powershell theme={null}
116 $env:ANTHROPIC_API_KEY = "sk-ant-xxxxx"
117 ```
118
119 SDK はサードパーティ API プロバイダーを介した認証もサポートしています。
120
121 * **Amazon Bedrock**: `CLAUDE_CODE_USE_BEDROCK=1` 環境変数を設定し、AWS 認証情報を構成します
122 * **Claude Platform on AWS**: `CLAUDE_CODE_USE_ANTHROPIC_AWS=1` と `ANTHROPIC_AWS_WORKSPACE_ID` を設定し、AWS 認証情報を構成します
123 * **Google Cloud の Agent Platform**: `CLAUDE_CODE_USE_VERTEX=1` 環境変数を設定し、Google Cloud 認証情報を構成します
124 * **Microsoft Azure**: `CLAUDE_CODE_USE_FOUNDRY=1` 環境変数を設定し、Azure 認証情報を構成します
125
126 詳細については、[Amazon Bedrock](/ja/amazon-bedrock)、[Claude Platform on AWS](/ja/claude-platform-on-aws)、[Google Cloud の Agent Platform](/ja/google-vertex-ai)、または [Microsoft Foundry](/ja/microsoft-foundry) のセットアップガイドを参照してください。
127
128 <Note>
129 事前に承認されていない限り、Anthropic は、Claude Agent SDK で構築されたエージェントを含む、サードパーティ開発者が claude.ai ログインまたはレート制限を提供することを許可していません。代わりに、このドキュメントで説明されている API キー認証方法を使用してください。
130 </Note>
131 </Step>
132 16
133 <Step title="最初のエージェントを実行します">17| 対象 | 使用するツール | 理由 |
134 この例は、組み込みツールを使用して現在のディレクトリ内のファイルをリストするエージェントを作成します。18| ----------------------------------------------------------- | --------------------------------------------------------------------------------- | --------------------------------------------------------------------- |
19| ツールループを自分で実装せずにエージェントを構築している | **Agent SDK** | 独自のプロセス内でエージェントループを実行するライブラリで、Python または TypeScript で利用可能です。 |
20| ターミナルからの対話的な開発またはワンオフタスクの実行 | [**Claude Code CLI**](/docs/ja/overview) | 日常的な対話的使用のために構築されたターミナルインターフェース。 |
21| API を直接呼び出し、ツールループを自分で実装している | [**Client SDK**](https://platform.claude.com/docs/en/api/client-sdks) | Claude Code ではなく Anthropic API への直接アクセス。ツールループを自分で実装します。 |
22| 独自のサンドボックスまたはセッションインフラストラクチャを管理せずに、長時間実行または非同期エージェントを実行している | [**Managed Agents**](https://platform.claude.com/docs/en/managed-agents/overview) | ホストされた REST API で、Agent SDK とは別の製品です。Anthropic がエージェントとサンドボックスを実行します。 |
135 23
136 <CodeGroup>24SDK は Python と TypeScript のライブラリとしてのみ利用可能です。別の言語から同じエージェントループを駆動するには、[`-p` フラグと `--output-format json` を使用して CLI をサブプロセスとして実行](/docs/ja/headless)してください。
137 ```python Python theme={null}
138 import asyncio
139 from claude_agent_sdk import query, ClaudeAgentOptions
140
141
142 async def main():
143 async for message in query(
144 prompt="What files are in this directory?",
145 options=ClaudeAgentOptions(allowed_tools=["Bash", "Glob"]),
146 ):
147 if hasattr(message, "result"):
148 print(message.result)
149
150
151 asyncio.run(main())
152 ```
153
154 ```typescript TypeScript theme={null}
155 import { query } from "@anthropic-ai/claude-agent-sdk";
156
157 for await (const message of query({
158 prompt: "What files are in this directory?",
159 options: { allowedTools: ["Bash", "Glob"] }
160 })) {
161 if ("result" in message) console.log(message.result);
162 }
163 ```
164 </CodeGroup>
165 </Step>
166</Steps>
167
168**構築する準備はできていますか?** [クイックスタート](/ja/agent-sdk/quickstart)に従って、数分でバグを見つけて修正するエージェントを作成します。
169 25
170<h2 id="capabilities">26<h2 id="capabilities">
171 機能27 機能
172</h2>28</h2>
173 29
174Claude Code を強力にするすべてのものが SDK で利用可能です。30これらの Claude Code 機能は SDK で利用可能です。
175
176<Tabs>
177 <Tab title="組み込みツール">
178 エージェントは、ファイルの読み取り、コマンドの実行、コードベースの検索をすぐに実行できます。主要なツールは次のとおりです。
179
180 | ツール | 機能 |
181 | --------------------------------------------------------------------------- | ---------------------------------------- |
182 | **Read** | 作業ディレクトリ内の任意のファイルを読み取ります |
183 | **Write** | 新しいファイルを作成します |
184 | **Edit** | 既存ファイルに正確な編集を加えます |
185 | **Bash** | ターミナルコマンド、スクリプト、git 操作を実行します |
186 | **Monitor** | バックグラウンドスクリプトを監視し、各出力行をイベントとして反応します |
187 | **Glob** | パターン(`**/*.ts`、`src/**/*.py`)でファイルを検索します |
188 | **Grep** | 正規表現でファイルコンテンツを検索します |
189 | **WebSearch** | 現在の情報をウェブで検索します |
190 | **WebFetch** | ウェブページコンテンツを取得して解析します |
191 | **[AskUserQuestion](/ja/agent-sdk/user-input#handle-clarifying-questions)** | 複数選択オプション付きで、ユーザーに明確化の質問をします |
192
193 この例は、コードベースで TODO コメントを検索するエージェントを作成します。
194
195 <CodeGroup>
196 ```python Python theme={null}
197 import asyncio
198 from claude_agent_sdk import query, ClaudeAgentOptions
199
200
201 async def main():
202 async for message in query(
203 prompt="Find all TODO comments and create a summary",
204 options=ClaudeAgentOptions(allowed_tools=["Read", "Glob", "Grep"]),
205 ):
206 if hasattr(message, "result"):
207 print(message.result)
208
209
210 asyncio.run(main())
211 ```
212
213 ```typescript TypeScript theme={null}
214 import { query } from "@anthropic-ai/claude-agent-sdk";
215
216 for await (const message of query({
217 prompt: "Find all TODO comments and create a summary",
218 options: { allowedTools: ["Read", "Glob", "Grep"] }
219 })) {
220 if ("result" in message) console.log(message.result);
221 }
222 ```
223 </CodeGroup>
224 </Tab>
225
226 <Tab title="Hooks">
227 エージェントライフサイクルの重要なポイントでカスタムコードを実行します。SDK hooks はコールバック関数を使用して、エージェントの動作を検証、ログ、ブロック、または変換します。
228
229 **利用可能な hooks:** `PreToolUse`、`PostToolUse`、`Stop`、`SessionStart`、`SessionEnd`、`UserPromptSubmit` など。
230
231 この例は、すべてのファイル変更を監査ファイルにログします。
232
233 <CodeGroup>
234 ```python Python theme={null}
235 import asyncio
236 from datetime import datetime
237 from claude_agent_sdk import query, ClaudeAgentOptions, HookMatcher
238
239
240 async def log_file_change(input_data, tool_use_id, context):
241 file_path = input_data.get("tool_input", {}).get("file_path", "unknown")
242 with open("./audit.log", "a") as f:
243 f.write(f"{datetime.now()}: modified {file_path}\n")
244 return {}
245
246
247 async def main():
248 async for message in query(
249 prompt="Refactor utils.py to improve readability",
250 options=ClaudeAgentOptions(
251 permission_mode="acceptEdits",
252 hooks={
253 "PostToolUse": [
254 HookMatcher(matcher="Edit|Write", hooks=[log_file_change])
255 ]
256 },
257 ),
258 ):
259 if hasattr(message, "result"):
260 print(message.result)
261
262
263 asyncio.run(main())
264 ```
265
266 ```typescript TypeScript theme={null}
267 import { query, HookCallback } from "@anthropic-ai/claude-agent-sdk";
268 import { appendFile } from "fs/promises";
269
270 const logFileChange: HookCallback = async (input) => {
271 const filePath = (input as any).tool_input?.file_path ?? "unknown";
272 await appendFile("./audit.log", `${new Date().toISOString()}: modified ${filePath}\n`);
273 return {};
274 };
275
276 for await (const message of query({
277 prompt: "Refactor utils.py to improve readability",
278 options: {
279 permissionMode: "acceptEdits",
280 hooks: {
281 PostToolUse: [{ matcher: "Edit|Write", hooks: [logFileChange] }]
282 }
283 }
284 })) {
285 if ("result" in message) console.log(message.result);
286 }
287 ```
288 </CodeGroup>
289
290 [hooks の詳細を学ぶ →](/ja/agent-sdk/hooks)
291 </Tab>
292
293 <Tab title="サブエージェント">
294 特定のサブタスクを処理するために特化したエージェントを生成します。メインエージェントが作業を委譲し、サブエージェントが結果を報告します。
295 31
296 特化した指示を持つカスタムエージェントを定義します。サブエージェントは Agent ツール経由で呼び出されるため、`allowedTools` に `Agent` を含めて、それらの呼び出しを自動承認します。32| 機能 | 機能 | 詳細を学ぶ |
33| --------------- | ------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
34| 組み込みツール | ファイルの読み取り、書き込み、編集、コマンド実行、ウェブ検索 | [ツールリファレンス](/docs/ja/tools-reference) |
35| Hooks | エージェントライフサイクルの重要なポイントでカスタムコードを実行 | [Hooks](/docs/ja/agent-sdk/hooks) |
36| Subagents | 特定のサブタスク用に特化したエージェントを生成 | [Subagents](/docs/ja/agent-sdk/subagents) |
37| MCP | Model Context Protocol を介して外部ツールとデータソースを接続 | [MCP](/docs/ja/agent-sdk/mcp) |
38| 権限 | どのツールが自動的に実行されるか、どのツールが承認を必要とするかを制御 | [権限](/docs/ja/agent-sdk/permissions) |
39| セッション | 複数の交換にわたってコンテキストを維持し、後で再開またはフォーク | [セッション](/docs/ja/agent-sdk/sessions) |
40| Skills、コマンド、メモリ | プロジェクトの `.claude/` と `~/.claude/` から自動的に読み込み、Claude Code と同じ | [Skills](/docs/ja/agent-sdk/skills)、[コマンド](/docs/ja/agent-sdk/skills#commands-in-agent-sdk-sessions)、[メモリ](/docs/ja/agent-sdk/modifying-system-prompts)、[設定読み込み](/docs/ja/agent-sdk/claude-code-features) |
41| Plugins | Skills、エージェント、hooks、MCP サーバーをパッケージ化し、ローカルパスで読み込み | [Plugins](/docs/ja/agent-sdk/plugins) |
297 42
298 <CodeGroup>43<h2 id="get-started">
299 ```python Python theme={null}44 はじめに
300 import asyncio
301 from claude_agent_sdk import query, ClaudeAgentOptions, AgentDefinition
302
303
304 async def main():
305 async for message in query(
306 prompt="Use the code-reviewer agent to review this codebase",
307 options=ClaudeAgentOptions(
308 allowed_tools=["Read", "Glob", "Grep", "Agent"],
309 agents={
310 "code-reviewer": AgentDefinition(
311 description="Expert code reviewer for quality and security reviews.",
312 prompt="Analyze code quality and suggest improvements.",
313 tools=["Read", "Glob", "Grep"],
314 )
315 },
316 ),
317 ):
318 if hasattr(message, "result"):
319 print(message.result)
320
321
322 asyncio.run(main())
323 ```
324
325 ```typescript TypeScript theme={null}
326 import { query } from "@anthropic-ai/claude-agent-sdk";
327
328 for await (const message of query({
329 prompt: "Use the code-reviewer agent to review this codebase",
330 options: {
331 allowedTools: ["Read", "Glob", "Grep", "Agent"],
332 agents: {
333 "code-reviewer": {
334 description: "Expert code reviewer for quality and security reviews.",
335 prompt: "Analyze code quality and suggest improvements.",
336 tools: ["Read", "Glob", "Grep"]
337 }
338 }
339 }
340 })) {
341 if ("result" in message) console.log(message.result);
342 }
343 ```
344 </CodeGroup>
345
346 サブエージェントのコンテキスト内からのメッセージには `parent_tool_use_id` フィールドが含まれており、どのメッセージがどのサブエージェント実行に属しているかを追跡できます。
347
348 [サブエージェントの詳細を学ぶ →](/ja/agent-sdk/subagents)
349 </Tab>
350
351 <Tab title="MCP">
352 Model Context Protocol を介して外部システムに接続します。データベース、ブラウザ、API、および[数百以上](https://github.com/modelcontextprotocol/servers)。
353
354 この例は、[Playwright MCP サーバー](https://github.com/microsoft/playwright-mcp)を接続して、エージェントにブラウザ自動化機能を提供します。
355
356 <CodeGroup>
357 ```python Python theme={null}
358 import asyncio
359 from claude_agent_sdk import query, ClaudeAgentOptions
360
361
362 async def main():
363 async for message in query(
364 prompt="Open example.com and describe what you see",
365 options=ClaudeAgentOptions(
366 mcp_servers={
367 "playwright": {"command": "npx", "args": ["@playwright/mcp@latest"]}
368 }
369 ),
370 ):
371 if hasattr(message, "result"):
372 print(message.result)
373
374
375 asyncio.run(main())
376 ```
377
378 ```typescript TypeScript theme={null}
379 import { query } from "@anthropic-ai/claude-agent-sdk";
380
381 for await (const message of query({
382 prompt: "Open example.com and describe what you see",
383 options: {
384 mcpServers: {
385 playwright: { command: "npx", args: ["@playwright/mcp@latest"] }
386 }
387 }
388 })) {
389 if ("result" in message) console.log(message.result);
390 }
391 ```
392 </CodeGroup>
393
394 [MCP の詳細を学ぶ →](/ja/agent-sdk/mcp)
395 </Tab>
396
397 <Tab title="権限">
398 エージェントが使用できるツールを正確に制御します。安全な操作を許可し、危険な操作をブロックするか、機密アクションの承認を要求します。
399
400 <Note>
401 対話的な承認プロンプトと `AskUserQuestion` ツールについては、[承認とユーザー入力の処理](/ja/agent-sdk/user-input)を参照してください。
402 </Note>
403
404 この例は、コードを分析できるが変更できない読み取り専用エージェントを作成します。`allowed_tools` は `Read`、`Glob`、および `Grep` を事前承認します。
405
406 <CodeGroup>
407 ```python Python theme={null}
408 import asyncio
409 from claude_agent_sdk import query, ClaudeAgentOptions
410
411
412 async def main():
413 async for message in query(
414 prompt="Review this code for best practices",
415 options=ClaudeAgentOptions(
416 allowed_tools=["Read", "Glob", "Grep"],
417 ),
418 ):
419 if hasattr(message, "result"):
420 print(message.result)
421
422
423 asyncio.run(main())
424 ```
425
426 ```typescript TypeScript theme={null}
427 import { query } from "@anthropic-ai/claude-agent-sdk";
428
429 for await (const message of query({
430 prompt: "Review this code for best practices",
431 options: {
432 allowedTools: ["Read", "Glob", "Grep"]
433 }
434 })) {
435 if ("result" in message) console.log(message.result);
436 }
437 ```
438 </CodeGroup>
439
440 [権限の詳細を学ぶ →](/ja/agent-sdk/permissions)
441 </Tab>
442
443 <Tab title="セッション">
444 複数の交換にわたってコンテキストを維持します。Claude は読み取ったファイル、実行した分析、および会話履歴を記憶します。後でセッションを再開するか、異なるアプローチを探索するためにフォークします。
445
446 この例は、最初のクエリからセッション ID をキャプチャし、その後、完全なコンテキストで続行するために再開します。
447
448 <CodeGroup>
449 ```python Python theme={null}
450 import asyncio
451 from claude_agent_sdk import query, ClaudeAgentOptions, SystemMessage, ResultMessage
452
453
454 async def main():
455 session_id = None
456
457 # First query: capture the session ID
458 async for message in query(
459 prompt="Read the authentication module",
460 options=ClaudeAgentOptions(allowed_tools=["Read", "Glob"]),
461 ):
462 if isinstance(message, SystemMessage) and message.subtype == "init":
463 session_id = message.data["session_id"]
464
465 # Resume with full context from the first query
466 async for message in query(
467 prompt="Now find all places that call it", # "it" = auth module
468 options=ClaudeAgentOptions(resume=session_id),
469 ):
470 if isinstance(message, ResultMessage):
471 print(message.result)
472
473
474 asyncio.run(main())
475 ```
476
477 ```typescript TypeScript theme={null}
478 import { query } from "@anthropic-ai/claude-agent-sdk";
479
480 let sessionId: string | undefined;
481
482 // First query: capture the session ID
483 for await (const message of query({
484 prompt: "Read the authentication module",
485 options: { allowedTools: ["Read", "Glob"] }
486 })) {
487 if (message.type === "system" && message.subtype === "init") {
488 sessionId = message.session_id;
489 }
490 }
491
492 // Resume with full context from the first query
493 for await (const message of query({
494 prompt: "Now find all places that call it", // "it" = auth module
495 options: { resume: sessionId }
496 })) {
497 if ("result" in message) console.log(message.result);
498 }
499 ```
500 </CodeGroup>
501
502 [セッションの詳細を学ぶ →](/ja/agent-sdk/sessions)
503 </Tab>
504</Tabs>
505
506<h3 id="claude-code-features">
507 Claude Code の機能
508</h3>
509
510SDK はまた Claude Code のファイルシステムベースの構成をサポートしています。デフォルトオプションでは、SDK は作業ディレクトリの `.claude/` と `~/.claude/` からこれらを読み込みます。どのソースを読み込むかを制限するには、オプションで `setting_sources`(Python)または `settingSources`(TypeScript)を設定します。
511
512| 機能 | 説明 | 場所 |
513| ------------------------------------------------ | ---------------------------------------------- | ----------------------------------- |
514| [Skills](/ja/agent-sdk/skills) | Claude が自動的に使用するか、`/name` で呼び出す特化した機能 | `.claude/skills/*/SKILL.md` |
515| [Commands](/ja/agent-sdk/slash-commands) | レガシー形式のカスタムコマンド。新しいカスタムコマンドには skills を使用してください | `.claude/commands/*.md` |
516| [Memory](/ja/agent-sdk/modifying-system-prompts) | プロジェクトコンテキストと指示 | `CLAUDE.md` または `.claude/CLAUDE.md` |
517| [Plugins](/ja/agent-sdk/plugins) | skills、エージェント、hooks、および MCP サーバーで拡張 | `plugins` オプション経由でプログラム的に |
518
519<h2 id="compare-the-agent-sdk-to-other-claude-tools">
520 Agent SDK と他の Claude ツールを比較します
521</h2>45</h2>
522 46
523Claude Platform は Claude で構築するための複数の方法を提供しています。Agent SDK がどのように適合するかは次のとおりです。47[クイックスタート](/docs/ja/agent-sdk/quickstart)に従って、SDK をインストールし、API キーを設定し、既存のコード内のバグを見つけて修正するエージェントを構築してください。
524
525<Tabs>
526 <Tab title="Agent SDK vs Client SDK">
527 [Anthropic Client SDK](https://platform.claude.com/docs/ja/api/client-sdks) は直接 API アクセスを提供します。プロンプトを送信し、ツール実行を自分で実装します。**Agent SDK** は、組み込みツール実行を備えた Claude を提供します。
528
529 Client SDK では、ツールループを実装します。Agent SDK では、Claude がそれを処理します。
530
531 <CodeGroup>
532 ```python Python theme={null}
533 # Client SDK: You implement the tool loop
534 response = client.messages.create(...)
535 while response.stop_reason == "tool_use":
536 result = your_tool_executor(response.tool_use)
537 response = client.messages.create(tool_result=result, **params)
538
539 # Agent SDK: Claude handles tools autonomously
540 async for message in query(prompt="Fix the bug in auth.py"):
541 print(message)
542 ```
543
544 ```typescript TypeScript theme={null}
545 // Client SDK: You implement the tool loop
546 let response = await client.messages.create({ ...params });
547 while (response.stop_reason === "tool_use") {
548 const result = yourToolExecutor(response.tool_use);
549 response = await client.messages.create({ tool_result: result, ...params });
550 }
551
552 // Agent SDK: Claude handles tools autonomously
553 for await (const message of query({ prompt: "Fix the bug in auth.ts" })) {
554 console.log(message);
555 }
556 ```
557 </CodeGroup>
558 </Tab>
559 48
560 <Tab title="Agent SDK vs Claude Code CLI">49<Note>
561 同じ機能、異なるインターフェース。50 事前に承認されていない限り、Anthropic は、Agent SDK 上に構築されたエージェントを含む、サードパーティの開発者が claude.ai ログインまたはレート制限を提供することを許可していません。代わりに、[クイックスタート](/docs/ja/agent-sdk/quickstart)で説明されている API キー認証方法を使用してください。
562 51</Note>
563 | ユースケース | 最適な選択 |
564 | ------------ | ----- |
565 | インタラクティブな開発 | CLI |
566 | CI/CD パイプライン | SDK |
567 | カスタムアプリケーション | SDK |
568 | 1 回限りのタスク | CLI |
569 | 本番環境の自動化 | SDK |
570
571 多くのチームは両方を使用しています。日常的な開発には CLI、本番環境には SDK を使用します。ワークフローはそれらの間で直接変換されます。
572 </Tab>
573
574 <Tab title="Agent SDK vs Managed Agents">
575 [Managed Agents](https://platform.claude.com/docs/ja/managed-agents/overview) はホストされた REST API です。Anthropic がエージェントとサンドボックスを実行し、アプリケーションがイベントを送信して結果をストリーミングで返します。**Agent SDK** は、独自のプロセス内でエージェントループを実行するライブラリです。
576
577 | | Agent SDK | Managed Agents |
578 | ----------------- | -------------------------------------------- | -------------------------------------------------------------- |
579 | **実行場所** | ユーザーのプロセス、ユーザーのインフラストラクチャ | Anthropic 管理インフラストラクチャ |
580 | **インターフェース** | Python または TypeScript ライブラリ | REST API |
581 | **エージェントが動作する場所** | ユーザーのインフラストラクチャ上のファイル | セッションごとの管理サンドボックス |
582 | **セッション状態** | ユーザーのファイルシステム上の JSONL | Anthropic ホスト型イベントログ |
583 | **カスタムツール** | インプロセス Python または TypeScript 関数 | Claude がツールをトリガーします。ユーザーが実行して結果を返します |
584 | **最適な用途** | ローカルプロトタイピング、ユーザーのファイルシステムとサービスで直接動作するエージェント | サンドボックスまたはセッションインフラストラクチャを運用する必要のない本番環境エージェント、長時間実行および非同期セッション |
585
586 一般的なパスは、Agent SDK でローカルにプロトタイプを作成してから、本番環境用に Managed Agents に移行することです。
587 </Tab>
588</Tabs>
589 52
590<h2 id="changelog">53<h2 id="changelog">
591 変更ログ54 変更ログ
596* **TypeScript SDK**: [CHANGELOG.md を表示](https://github.com/anthropics/claude-agent-sdk-typescript/blob/main/CHANGELOG.md)59* **TypeScript SDK**: [CHANGELOG.md を表示](https://github.com/anthropics/claude-agent-sdk-typescript/blob/main/CHANGELOG.md)
597* **Python SDK**: [CHANGELOG.md を表示](https://github.com/anthropics/claude-agent-sdk-python/blob/main/CHANGELOG.md)60* **Python SDK**: [CHANGELOG.md を表示](https://github.com/anthropics/claude-agent-sdk-python/blob/main/CHANGELOG.md)
598 61
599<h2 id="reporting-bugs">62<h2 id="report-bugs">
600 バグの報告63 バグの報告
601</h2>64</h2>
602 65
634 次のステップ97 次のステップ
635</h2>98</h2>
636 99
637<CardGroup cols={2}>100これらのリソースは、Agent SDK を使用して構築するための、より深い技術的詳細とサンプルプロジェクトをカバーしています。
638 <Card title="クイックスタート" icon="play" href="/ja/agent-sdk/quickstart">
639 数分でバグを見つけて修正するエージェントを構築します
640 </Card>
641
642 <Card title="エージェントの例" icon="star" href="https://github.com/anthropics/claude-agent-sdk-demos">
643 メールアシスタント、リサーチエージェント、その他
644 </Card>
645
646 <Card title="TypeScript SDK" icon="code" href="/ja/agent-sdk/typescript">
647 完全な TypeScript API リファレンスと例
648 </Card>
649 101
650 <Card title="Python SDK" icon="code" href="/ja/agent-sdk/python">102* [クイックスタート](/docs/ja/agent-sdk/quickstart):バグを見つけて修正する最初のエージェントを構築します
651 完全な Python API リファレンスと例103* [マイグレーションガイド](/docs/ja/agent-sdk/migration-guide):Claude Code SDK パッケージから Agent SDK へマイグレーションします
652 </Card>104* [エージェントループ](/docs/ja/agent-sdk/agent-loop):Claude がどのように計画を立て、ツールを呼び出し、タスクが完了したかを判断するか
653</CardGroup>105* [エージェントの例](https://github.com/anthropics/claude-agent-sdk-demos):ローカル開発用のデモアプリ
106* [TypeScript SDK](/docs/ja/agent-sdk/typescript):完全な TypeScript API リファレンスと例
107* [Python SDK](/docs/ja/agent-sdk/python):完全な Python API リファレンスと例
108* [エージェントハーネス設計](https://claude.com/blog/a-harness-for-every-task-dynamic-workflows-in-claude-code):Claude Code チームが多くのサブエージェントを一度にオーケストレーションするために動的ワークフローをどのように使用するか