🛠️ HostedエージェントV2Py
Azure AI Foundryで、コンテナを使ったAIアシ
📺 まず動画で見る(YouTube)
▶ 【衝撃】最強のAIエージェント「Claude Code」の最新機能・使い方・プログラミングをAIで効率化する超実践術を解説! ↗
※ jpskill.com 編集部が参考用に選んだ動画です。動画の内容と Skill の挙動は厳密には一致しないことがあります。
📜 元の英語説明(参考)
Build hosted agents using Azure AI Projects SDK with ImageBasedHostedAgentDefinition. Use when creating container-based agents in Azure AI Foundry.
🇯🇵 日本人クリエイター向け解説
Azure AI Foundryで、コンテナを使ったAIアシ
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o hosted-agents-v2-py.zip https://jpskill.com/download/2980.zip && unzip -o hosted-agents-v2-py.zip && rm hosted-agents-v2-py.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/2980.zip -OutFile "$d\hosted-agents-v2-py.zip"; Expand-Archive "$d\hosted-agents-v2-py.zip" -DestinationPath $d -Force; ri "$d\hosted-agents-v2-py.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
hosted-agents-v2-py.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
hosted-agents-v2-pyフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-17
- 取得日時
- 2026-05-17
- 同梱ファイル
- 1
💬 こう話しかけるだけ — サンプルプロンプト
- › Hosted Agents V2 Py を使って、最小構成のサンプルコードを示して
- › Hosted Agents V2 Py の主な使い方と注意点を教えて
- › Hosted Agents V2 Py を既存プロジェクトに組み込む方法を教えて
これをClaude Code に貼るだけで、このSkillが自動発動します。
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
Azure AI Hosted Agents (Python)
Azure AI Projects SDK の ImageBasedHostedAgentDefinition を使用して、コンテナベースのホスト型エージェントを構築します。
インストール
pip install azure-ai-projects>=2.0.0b3 azure-identity
最小 SDK バージョン: ホスト型エージェントのサポートには 2.0.0b3 以降が必要です。
環境変数
AZURE_AI_PROJECT_ENDPOINT=https://<resource>.services.ai.azure.com/api/projects/<project>
前提条件
ホスト型エージェントを作成する前に:
- コンテナイメージ - 構築して Azure Container Registry (ACR) にプッシュします。
- ACR プル権限 - プロジェクトのマネージド ID に ACR 上で
AcrPullロールを付与します。 - Capability Host - アカウントレベルの capability host で
enablePublicHostingEnvironment=trueを設定します。 - SDK バージョン -
azure-ai-projects>=2.0.0b3を確認します。
認証
常に DefaultAzureCredential を使用してください。
from azure.identity import DefaultAzureCredential
from azure.ai.projects import AIProjectClient
credential = DefaultAzureCredential()
client = AIProjectClient(
endpoint=os.environ["AZURE_AI_PROJECT_ENDPOINT"],
credential=credential
)
コアワークフロー
1. インポート
import os
from azure.identity import DefaultAzureCredential
from azure.ai.projects import AIProjectClient
from azure.ai.projects.models import (
ImageBasedHostedAgentDefinition,
ProtocolVersionRecord,
AgentProtocol,
)
2. ホスト型エージェントの作成
client = AIProjectClient(
endpoint=os.environ["AZURE_AI_PROJECT_ENDPOINT"],
credential=DefaultAzureCredential()
)
agent = client.agents.create_version(
agent_name="my-hosted-agent",
definition=ImageBasedHostedAgentDefinition(
container_protocol_versions=[
ProtocolVersionRecord(protocol=AgentProtocol.RESPONSES, version="v1")
],
cpu="1",
memory="2Gi",
image="myregistry.azurecr.io/my-agent:latest",
tools=[{"type": "code_interpreter"}],
environment_variables={
"AZURE_AI_PROJECT_ENDPOINT": os.environ["AZURE_AI_PROJECT_ENDPOINT"],
"MODEL_NAME": "gpt-4o-mini"
}
)
)
print(f"Created agent: {agent.name} (version: {agent.version})")
3. エージェントバージョンのリスト表示
versions = client.agents.list_versions(agent_name="my-hosted-agent")
for version in versions:
print(f"Version: {version.version}, State: {version.state}")
4. エージェントバージョンの削除
client.agents.delete_version(
agent_name="my-hosted-agent",
version=agent.version
)
ImageBasedHostedAgentDefinition パラメータ
| パラメータ | 型 | 必須 | 説明 |
|---|---|---|---|
container_protocol_versions |
list[ProtocolVersionRecord] |
はい | エージェントがサポートするプロトコルバージョン |
image |
str |
はい | 完全なコンテナイメージパス (registry/image:tag) |
cpu |
str |
いいえ | CPU 割り当て (例: "1", "2") |
memory |
str |
いいえ | メモリ割り当て (例: "2Gi", "4Gi") |
tools |
list[dict] |
いいえ | エージェントが利用できるツール |
environment_variables |
dict[str, str] |
いいえ | コンテナの環境変数 |
プロトコルバージョン
container_protocol_versions パラメータは、エージェントがサポートするプロトコルを指定します。
from azure.ai.projects.models import ProtocolVersionRecord, AgentProtocol
# RESPONSES protocol - 標準エージェント応答
container_protocol_versions=[
ProtocolVersionRecord(protocol=AgentProtocol.RESPONSES, version="v1")
]
利用可能なプロトコル:
| プロトコル | 説明 |
|----------|-------------|
| AgentProtocol.RESPONSES | エージェントインタラクションのための標準応答プロトコル |
リソース割り当て
コンテナの CPU とメモリを指定します。
definition=ImageBasedHostedAgentDefinition(
container_protocol_versions=[...],
image="myregistry.azurecr.io/my-agent:latest",
cpu="2", # 2 CPU コア
memory="4Gi" # 4 GiB メモリ
)
リソース制限: | リソース | 最小 | 最大 | デフォルト | |----------|-----|-----|---------| | CPU | 0.5 | 4 | 1 | | メモリ | 1Gi | 8Gi | 2Gi |
ツール設定
ホスト型エージェントにツールを追加します。
コードインタプリタ
tools=[{"type": "code_interpreter"}]
MCP ツール
tools=[
{"type": "code_interpreter"},
{
"type": "mcp",
"server_label": "my-mcp-server",
"server_url": "https://my-mcp-server.example.com"
}
]
複数のツール
tools=[
{"type": "code_interpreter"},
{"type": "file_search"},
{
"type": "mcp",
"server_label": "custom-tool",
"server_url": "https://custom-tool.example.com"
}
]
環境変数
コンテナに構成を渡します。
environment_variables={
"AZURE_AI_PROJECT_ENDPOINT": os.environ["AZURE_AI_PROJECT_ENDPOINT"],
"MODEL_NAME": "gpt-4o-mini",
"LOG_LEVEL": "INFO",
"CUSTOM_CONFIG": "value"
}
ベストプラクティス: シークレットをハードコードしないでください。環境変数または Azure Key Vault を使用してください。
完全な例
import os
from azure.identity import DefaultAzureCredential
from azure.ai.projects import AIProjectClient
from azure.ai.projects.models import (
ImageBasedHostedAgentDefinition,
ProtocolVersionRecord,
AgentProtocol,
)
def create_hosted_agent():
"""カスタムコンテナイメージでホスト型エージェントを作成します。"""
client = AIProjectClient(
endpoint=os.environ["AZURE_AI_PROJECT_ENDPOINT"],
credential=DefaultAzureCredential()
)
agent = client.agents.create_version(
agent_name="data-processor-agent",
definition=ImageBasedHostedAgentDefinition(
container_protocol_versions=[
ProtocolVersionRecord(
protocol=AgentProtocol.RESPONSES,
version="v1"
)
],
image="myregistry.azurecr.io/data-processor:v1.0",
cpu="2",
memory="4Gi",
tools=[
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Azure AI Hosted Agents (Python)
Build container-based hosted agents using ImageBasedHostedAgentDefinition from the Azure AI Projects SDK.
Installation
pip install azure-ai-projects>=2.0.0b3 azure-identity
Minimum SDK Version: 2.0.0b3 or later required for hosted agent support.
Environment Variables
AZURE_AI_PROJECT_ENDPOINT=https://<resource>.services.ai.azure.com/api/projects/<project>
Prerequisites
Before creating hosted agents:
- Container Image - Build and push to Azure Container Registry (ACR)
- ACR Pull Permissions - Grant your project's managed identity
AcrPullrole on the ACR - Capability Host - Account-level capability host with
enablePublicHostingEnvironment=true - SDK Version - Ensure
azure-ai-projects>=2.0.0b3
Authentication
Always use DefaultAzureCredential:
from azure.identity import DefaultAzureCredential
from azure.ai.projects import AIProjectClient
credential = DefaultAzureCredential()
client = AIProjectClient(
endpoint=os.environ["AZURE_AI_PROJECT_ENDPOINT"],
credential=credential
)
Core Workflow
1. Imports
import os
from azure.identity import DefaultAzureCredential
from azure.ai.projects import AIProjectClient
from azure.ai.projects.models import (
ImageBasedHostedAgentDefinition,
ProtocolVersionRecord,
AgentProtocol,
)
2. Create Hosted Agent
client = AIProjectClient(
endpoint=os.environ["AZURE_AI_PROJECT_ENDPOINT"],
credential=DefaultAzureCredential()
)
agent = client.agents.create_version(
agent_name="my-hosted-agent",
definition=ImageBasedHostedAgentDefinition(
container_protocol_versions=[
ProtocolVersionRecord(protocol=AgentProtocol.RESPONSES, version="v1")
],
cpu="1",
memory="2Gi",
image="myregistry.azurecr.io/my-agent:latest",
tools=[{"type": "code_interpreter"}],
environment_variables={
"AZURE_AI_PROJECT_ENDPOINT": os.environ["AZURE_AI_PROJECT_ENDPOINT"],
"MODEL_NAME": "gpt-4o-mini"
}
)
)
print(f"Created agent: {agent.name} (version: {agent.version})")
3. List Agent Versions
versions = client.agents.list_versions(agent_name="my-hosted-agent")
for version in versions:
print(f"Version: {version.version}, State: {version.state}")
4. Delete Agent Version
client.agents.delete_version(
agent_name="my-hosted-agent",
version=agent.version
)
ImageBasedHostedAgentDefinition Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
container_protocol_versions |
list[ProtocolVersionRecord] |
Yes | Protocol versions the agent supports |
image |
str |
Yes | Full container image path (registry/image:tag) |
cpu |
str |
No | CPU allocation (e.g., "1", "2") |
memory |
str |
No | Memory allocation (e.g., "2Gi", "4Gi") |
tools |
list[dict] |
No | Tools available to the agent |
environment_variables |
dict[str, str] |
No | Environment variables for the container |
Protocol Versions
The container_protocol_versions parameter specifies which protocols your agent supports:
from azure.ai.projects.models import ProtocolVersionRecord, AgentProtocol
# RESPONSES protocol - standard agent responses
container_protocol_versions=[
ProtocolVersionRecord(protocol=AgentProtocol.RESPONSES, version="v1")
]
Available Protocols:
| Protocol | Description |
|----------|-------------|
| AgentProtocol.RESPONSES | Standard response protocol for agent interactions |
Resource Allocation
Specify CPU and memory for your container:
definition=ImageBasedHostedAgentDefinition(
container_protocol_versions=[...],
image="myregistry.azurecr.io/my-agent:latest",
cpu="2", # 2 CPU cores
memory="4Gi" # 4 GiB memory
)
Resource Limits: | Resource | Min | Max | Default | |----------|-----|-----|---------| | CPU | 0.5 | 4 | 1 | | Memory | 1Gi | 8Gi | 2Gi |
Tools Configuration
Add tools to your hosted agent:
Code Interpreter
tools=[{"type": "code_interpreter"}]
MCP Tools
tools=[
{"type": "code_interpreter"},
{
"type": "mcp",
"server_label": "my-mcp-server",
"server_url": "https://my-mcp-server.example.com"
}
]
Multiple Tools
tools=[
{"type": "code_interpreter"},
{"type": "file_search"},
{
"type": "mcp",
"server_label": "custom-tool",
"server_url": "https://custom-tool.example.com"
}
]
Environment Variables
Pass configuration to your container:
environment_variables={
"AZURE_AI_PROJECT_ENDPOINT": os.environ["AZURE_AI_PROJECT_ENDPOINT"],
"MODEL_NAME": "gpt-4o-mini",
"LOG_LEVEL": "INFO",
"CUSTOM_CONFIG": "value"
}
Best Practice: Never hardcode secrets. Use environment variables or Azure Key Vault.
Complete Example
import os
from azure.identity import DefaultAzureCredential
from azure.ai.projects import AIProjectClient
from azure.ai.projects.models import (
ImageBasedHostedAgentDefinition,
ProtocolVersionRecord,
AgentProtocol,
)
def create_hosted_agent():
"""Create a hosted agent with custom container image."""
client = AIProjectClient(
endpoint=os.environ["AZURE_AI_PROJECT_ENDPOINT"],
credential=DefaultAzureCredential()
)
agent = client.agents.create_version(
agent_name="data-processor-agent",
definition=ImageBasedHostedAgentDefinition(
container_protocol_versions=[
ProtocolVersionRecord(
protocol=AgentProtocol.RESPONSES,
version="v1"
)
],
image="myregistry.azurecr.io/data-processor:v1.0",
cpu="2",
memory="4Gi",
tools=[
{"type": "code_interpreter"},
{"type": "file_search"}
],
environment_variables={
"AZURE_AI_PROJECT_ENDPOINT": os.environ["AZURE_AI_PROJECT_ENDPOINT"],
"MODEL_NAME": "gpt-4o-mini",
"MAX_RETRIES": "3"
}
)
)
print(f"Created hosted agent: {agent.name}")
print(f"Version: {agent.version}")
print(f"State: {agent.state}")
return agent
if __name__ == "__main__":
create_hosted_agent()
Async Pattern
import os
from azure.identity.aio import DefaultAzureCredential
from azure.ai.projects.aio import AIProjectClient
from azure.ai.projects.models import (
ImageBasedHostedAgentDefinition,
ProtocolVersionRecord,
AgentProtocol,
)
async def create_hosted_agent_async():
"""Create a hosted agent asynchronously."""
async with DefaultAzureCredential() as credential:
async with AIProjectClient(
endpoint=os.environ["AZURE_AI_PROJECT_ENDPOINT"],
credential=credential
) as client:
agent = await client.agents.create_version(
agent_name="async-agent",
definition=ImageBasedHostedAgentDefinition(
container_protocol_versions=[
ProtocolVersionRecord(
protocol=AgentProtocol.RESPONSES,
version="v1"
)
],
image="myregistry.azurecr.io/async-agent:latest",
cpu="1",
memory="2Gi"
)
)
return agent
Common Errors
| Error | Cause | Solution |
|---|---|---|
ImagePullBackOff |
ACR pull permission denied | Grant AcrPull role to project's managed identity |
InvalidContainerImage |
Image not found | Verify image path and tag exist in ACR |
CapabilityHostNotFound |
No capability host configured | Create account-level capability host |
ProtocolVersionNotSupported |
Invalid protocol version | Use AgentProtocol.RESPONSES with version "v1" |
Best Practices
- Version Your Images - Use specific tags, not
latestin production - Minimal Resources - Start with minimum CPU/memory, scale up as needed
- Environment Variables - Use for all configuration, never hardcode
- Error Handling - Wrap agent creation in try/except blocks
- Cleanup - Delete unused agent versions to free resources
Reference Links
When to Use
This skill is applicable to execute the workflow or actions described in the overview.
Limitations
- Use this skill only when the task clearly matches the scope described above.
- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.