Claude Agent SDK 開発者ガイド
Claude Code SDKは正式にClaude Agent SDKに改名され、より完全なAIエージェント構築体験を提供します。本ガイドはPython/TypeScriptクイックスタート、コアコンセプト、エンタープライズベストプラクティスを網羅します。
Claude Agent SDKとは
seo_agent_sdk.rename_title
seo_agent_sdk.rename_desc
seo_agent_sdk.why_rename_title
seo_agent_sdk.why_rename_desc
統一ツールインターフェース
Claude Codeと同じツールシステムとエージェントループを共有し、ローカルとクラウドデプロイをシームレスに切り替えられます。
プロダクション対応
エラーリトライ、セッション管理、ストリーミング出力などエンタープライズ機能が標準搭載。
多言語サポート
公式PythonとTypeScript SDKは対称的なAPI設計と包括的なドキュメントを提供。
コアコンセプト
ツール (Tools)
Agentが呼び出せる関数のコレクション。デコレータで宣言し、JSON Schemaを自動生成してClaudeが理解・実行できます。
エージェントループ
Claude思考→ツール選択→実行→結果観察→継続思考のループ。タスク完了まで繰り返します。
メモリ/コンテキスト
セッション内短期メモリ(会話履歴)とクロスセッション長期メモリ(ファイル/DB永続化)の統一管理。
パーミッション
きめ細かな権限制御:ファイルシステム、ネットワーク、コード実行、外部APIアクセス範囲を個別設定可能。
Pythonクイックスタート
3ステップで最初のClaude Agentを構築。QCode.ccプロキシと完全互換。
ステップ1:SDKインストール
pip install anthropic-agent-sdk
ステップ2:Agentを作成
from anthropic_agent_sdk import Agent, tool
@tool
def get_weather(city: str) -> str:
"""Get current weather for a city"""
return f"Weather in {city}: 22°C, sunny"
agent = Agent(
model="claude-opus-4-7",
tools=[get_weather],
base_url="https://api.qcode.cc", # QCode.cc proxy
api_key="your-api-key",
)
result = agent.run("What's the weather in Beijing and Shanghai?")
print(result.output)
ステップ3:カスタムツール定義
from anthropic_agent_sdk import Agent, tool
import requests
@tool
def search_web(query: str, max_results: int = 5) -> list[dict]:
"""Search the web and return results"""
# Your search implementation here
response = requests.get(f"https://api.search.example.com?q={query}&n={max_results}")
return response.json()["results"]
@tool
def read_file(path: str) -> str:
"""Read contents of a local file"""
with open(path, "r") as f:
return f.read()
agent = Agent(
model="claude-opus-4-7",
tools=[search_web, read_file],
base_url="https://api.qcode.cc",
api_key="your-api-key",
system="You are a helpful research assistant.",
)
result = agent.run("Search for recent news about Claude Agent SDK and summarize")
print(result.output)
TypeScriptクイックスタート
Node.js / Bun環境でのClaude Agent開発、完全な型サポート付き。
ステップ1:SDKインストール
npm install @anthropic-ai/agent-sdk
ステップ2:Agentを作成
import { Agent, tool } from '@anthropic-ai/agent-sdk';
const getWeather = tool({
name: 'get_weather',
description: 'Get current weather for a city',
parameters: { city: { type: 'string' } },
execute: async ({ city }) => `Weather in ${city}: 22°C, sunny`,
});
const agent = new Agent({
model: 'claude-opus-4-7',
tools: [getWeather],
baseURL: 'https://api.qcode.cc',
apiKey: process.env.ANTHROPIC_API_KEY,
});
const result = await agent.run("What's the weather in Beijing?");
console.log(result.output);
ステップ3:完全サンプル
import { Agent, tool } from '@anthropic-ai/agent-sdk';
const searchWeb = tool({
name: 'search_web',
description: 'Search the web for information',
parameters: {
query: { type: 'string', description: 'Search query' },
maxResults: { type: 'number', description: 'Max results', default: 5 },
},
execute: async ({ query, maxResults = 5 }) => {
const res = await fetch(`https://api.search.example.com?q=${query}&n=${maxResults}`);
const data = await res.json();
return data.results;
},
});
const agent = new Agent({
model: 'claude-opus-4-7',
tools: [searchWeb],
baseURL: 'https://api.qcode.cc',
apiKey: process.env.ANTHROPIC_API_KEY,
systemPrompt: 'You are a helpful research assistant.',
maxTurns: 10,
});
// Streaming support
for await (const event of agent.stream("Research the latest AI agent frameworks")) {
if (event.type === 'text') process.stdout.write(event.text);
}
Agent SDK vs Managed Agents
| seo_agent_sdk.vs_col_feature |
seo_agent_sdk.vs_col_sdk
|
seo_agent_sdk.vs_col_managed
|
|---|---|---|
| seo_agent_sdk.vs_row1_feature | セルフホスト(ローカル/自社サーバー) | Anthropicクラウドホスト |
| seo_agent_sdk.vs_row2_feature | 手動インスタンス管理 | 自動エラスティックスケーリング |
| seo_agent_sdk.vs_row3_feature | プロトタイピング、高度カスタムシナリオ | エンタープライズ本番Agentデプロイ |
QCode.cc経由での利用
ANTHROPIC_BASE_URLをQCode.ccエンドポイントに設定すれば、Agent SDKのすべての機能が安定して利用できます。
# Python SDK
ANTHROPIC_BASE_URL=https://api.qcode.cc
ANTHROPIC_API_KEY=your-qcode-api-key
# TypeScript SDK
ANTHROPIC_BASE_URL=https://api.qcode.cc
ANTHROPIC_API_KEY=your-qcode-api-key
# Or set inline
agent = Agent(
base_url="https://api.qcode.cc",
api_key="your-qcode-api-key",
)
全Claudeモデル(Opus 4.7/Sonnet 4.6/Haiku 4.5)対応
ツール呼び出し(Function Calling)完全サポート
ストリーミング出力サポート
Managed Agents APIと完全互換
今すぐAIエージェント構築を始める
QCode.ccに登録して、Agent SDKのすべての機能をサポートする安定したClaude APIアクセスを取得しましょう。