agent-framework-claude は、Claude Agent SDK を ClaudeAgentとしてラップします。 Claude のマネージド エージェント ランタイム、セッション、アクセス許可モデル、組み込みツール、MCP サポートを使用して、Agent Framework の実行インターフェイスとストリーミング インターフェイスを公開します。
この統合は、アプリケーション所有の Agent Framework エージェントの背後にあるモデルとして Claude を使用するAnthropic モデル プロバイダーとは異なります。
前提条件
- Claude Code CLI をインストールして構成します。
- クロード モデルとアクセス許可モードを選択します。
- ファイルまたはシェル ツールを有効にする場合は、制約付き作業ディレクトリでエージェントを実行します。
パッケージをインストールする
pip install agent-framework-claude --pre
Configuration
| Variable | Purpose |
|---|---|
CLAUDE_AGENT_MODEL |
マネージド ランタイムによって使用されるクロード モデル。 |
CLAUDE_AGENT_PERMISSION_MODE |
組み込みツールと MCP ツールの既定のアクセス許可モード。 |
CLAUDE_AGENT_CLI_PATH |
Claude Code CLI への省略可能な明示的パス。 |
CLAUDE_AGENT_CWD |
ランタイムに公開されている作業ディレクトリ。 |
CLAUDE_AGENT_MAX_TURNS |
任意のエージェントのターンの最大数 |
CLAUDE_AGENT_MAX_BUDGET_USD |
実行に対する省略可能なコスト予算。 |
ClaudeAgentを作成する
ClaudeAgent では、通常の実行とストリーミングの実行がサポートされ、Agent Framework 関数ツールを公開できます。
async def non_streaming_example() -> None:
"""Example of non-streaming response."""
print("=== Non-streaming Example ===")
agent = ClaudeAgent(
name="BasicAgent",
instructions="You are a helpful assistant. Keep responses concise.",
tools=[get_weather],
)
async with agent:
query = "What's the weather in Seattle?"
print(f"User: {query}")
result = await agent.run(query)
print(f"Agent: {result.text}\n")
async def streaming_example() -> None:
"""Example of streaming response."""
print("=== Streaming Example ===")
agent = ClaudeAgent(
name="StreamingAgent",
instructions="You are a helpful assistant.",
tools=[get_weather],
)
async with agent:
query = "What's the weather in Paris?"
print(f"User: {query}")
print("Agent: ", end="", flush=True)
async for chunk in agent.run(query, stream=True):
if chunk.text:
print(chunk.text, end="", flush=True)
print("\n")
その他のサンプルの例を次に示します。
- 組み込みのファイルおよびシェル ツールをクロードします。
- 対話型のアクセス許可の処理。
- ローカルおよびリモートの MCP サーバー。
- セッションの永続化と再開。
- URL フェッチと複数のアクセス許可規則。
アクセス許可に関する考慮事項
- タスクをサポートする最小制限の Claude Agent SDK アクセス許可モードから開始します。
- シェル、ファイル、ネットワーク、またはその他の副作用操作に対して明示的な承認が必要です。
- エージェント作業ディレクトリ内の環境変数または読み取り可能なファイルを介して資格情報を公開しないでください。