Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Build hosted agents using Azure AI Projects SDK with ImageBasedHostedAgentDefinition. Use when creating container-based agents in Azure AI Foundry.
.claude/skills/hosted-agents-v2-py/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-14 | ✗→✓ | ▲ Improved | — | — |
| case-15 | ✗→✓ | ▲ Improved | — | — |
| case-13 | ✗→✓ | ▲ Improved | — | — |
| case-17 | ✗→✓ | ▲ Improved | — | — |
| case-10 | ✗→✓ | ▲ Improved | — | — |
Primary editorial path for this compatibility group. The full instructions and support files remain local so existing installations continue to work offline. This is one shared procedure, not an additional capability. Preserve the callable ID when an existing manifest or client configuration uses it. Modified in AAS on 2026-09-05; original metadata and license notices are retained.
Build container-based hosted agents using ImageBasedHostedAgentDefinition from the Azure AI Projects SDK.
bashpip install 'azure-ai-projects>=2.0.0b3,<3' azure-identity
These are preview-era SDK v2 sketches. Check the exact installed version and current Azure hosted-agent documentation before provisioning; a broad version range is not an integration test.
bashAZURE_AI_PROJECT_ENDPOINT=https://<resource>.services.ai.azure.com/api/projects/<project>
Before creating hosted agents:
AcrPull role on the ACRenablePublicHostingEnvironment=trueazure-ai-projects>=2.0.0b3Use the approved Azure credential flow for the intended tenant/subscription; this sketch uses DefaultAzureCredential:
pythonfrom azure.identity import DefaultAzureCredential from azure.ai.projects import AIProjectClient import os credential = DefaultAzureCredential() client = AIProjectClient( endpoint=os.environ["AZURE_AI_PROJECT_ENDPOINT"], credential=credential )
pythonimport os from azure.identity import DefaultAzureCredential from azure.ai.projects import AIProjectClient from azure.ai.projects.models import ( ImageBasedHostedAgentDefinition, ProtocolVersionRecord, AgentProtocol, )
pythonclient = 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})")
pythonversions = client.agents.list_versions(agent_name="my-hosted-agent") for version in versions: print(f"Version: {version.version}, State: {version.state}")
pythonclient.agents.delete_version( agent_name="my-hosted-agent", version=agent.version )
| 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 |
The container_protocol_versions parameter specifies which protocols your agent supports:
pythonfrom 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 |
Specify CPU and memory for your container:
pythondefinition=ImageBasedHostedAgentDefinition( container_protocol_versions=[...], image="myregistry.azurecr.io/my-agent:latest", cpu="2", # 2 CPU cores memory="4Gi" # 4 GiB memory )
Illustrative resource sizes; verify regional/SKU limits before provisioning: | Resource | Min | Max | Default | |----------|-----|-----|---------| | CPU | 0.5 | 4 | 1 | | Memory | 1Gi | 8Gi | 2Gi |
Add tools to your hosted agent:
pythontools=[{"type": "code_interpreter"}]
pythontools=[ {"type": "code_interpreter"}, { "type": "mcp", "server_label": "my-mcp-server", "server_url": "https://my-mcp-server.example.com" } ]
pythontools=[ {"type": "code_interpreter"}, {"type": "file_search"}, { "type": "mcp", "server_label": "custom-tool", "server_url": "https://custom-tool.example.com" } ]
Pass configuration to your container:
pythonenvironment_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.
pythonimport 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()
pythonimport 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
| 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" |
latest in productionUse for reviewing or creating an explicitly requested container-based Foundry hosted agent. First confirm image digest, subscription/tenant, region, service availability, permissions and cost scope. Creating agents, granting roles and deleting versions are cloud writes; do them only within the user's authorization.
Given a pinned container image and test project, check SDK model fields and registry pull access, then prepare the create request. Provision only if authorized and record the exact returned version and observed health. Do not delete unrelated versions as routine cleanup. Expected result is a version-specific receipt, not an assumed deploy.
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-22 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-14 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-15 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-20 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-09 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-13 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-17 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-10 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-04 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-21 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-11 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-08 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-06 | pass→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-05 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-07 | pass→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-12 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-03 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-02 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-01 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-16 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-18 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-19 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted. The headline lift of +55 percentage points is the difference between those two pass rates over the 22 comparable cases.
The publisher has shipped newer versions since this run, so these numbers describe v1, not the version currently listed.
The per-case answers from this run were removed by the retention sweep, so the case table below shows the verdicts without the text either arm produced. The counts above were recorded at the time and are unaffected. Answers are now kept for 180 days.
Other measured skills in the registry, with their headline benchmark lift.