Skip to main content
Items marked (preview) in this article are currently in public preview. This preview is provided without a service-level agreement, and we don’t recommend it for production workloads. Certain features might not be supported or might have constrained capabilities. For more information, see Supplemental Terms of Use for Microsoft Azure Previews.
A hosted agent project keeps all its configuration in a single azure.yaml file at the project root. This file declares your Foundry resources - the project, model deployments, connections, toolboxes, and the agent itself - as a set of services. It also tells the Azure Developer CLI (azd) how to provision and deploy them. This article walks through each part of azure.yaml you’re likely to edit: the project and its model, the agent service, tools, and how the agent deploys. You typically start from a file that azd ai agent init generates, so each section shows one block at a time to help you find and edit it. For a field-by-field description of every service and property, see azure.yaml reference for hosted agents.

Prerequisites

  • An Azure subscription with permission to create resources, such as the Contributor role on the target subscription or resource group.
  • The Azure Developer CLI Foundry extensions installed.
  • An authenticated Azure session (azd auth login).
  • A hosted agent project. To scaffold one, see Initialize a hosted agent project.
  • Sufficient model quota in your target region for the deployment you declare.
  • Docker installed and running, but only if you deploy with container mode or build from a Dockerfile. Code deployment doesn’t require Docker.

Understand the structure

Every entry under services is a named service with a host field that identifies the kind of Foundry resource it declares. Services reference each other through the uses field, which forms a dependency graph that azd resolves when it provisions and deploys. A minimal project has two services: an azure.ai.project service that owns the model deployment, and an azure.ai.agent service that depends on it.
The first line is a schema annotation that turns on validation and autocompletion in editors that support the YAML language server.

Start from a generated file

You rarely start with an empty file. When you run azd ai agent init, the CLI writes an azure.yaml for you, either from a template, from a sample’s azure.yaml that you pass with -m, or wrapped around your existing code. The command is interactive and prompts for values such as the Foundry project, model deployment, and agent name. Open the generated file and adjust it to match your agent. The rest of this article explains each part you’re likely to change.

Declare the project and a model deployment

The azure.ai.project service provisions (or connects to) a Foundry project and owns its model deployments. Add a deployment under deployments:
To connect to an existing project instead of provisioning a new one, set the endpoint field to the project’s endpoint URL and omit any deployments you don’t want azd to manage. The model version and SKU are illustrative. When you run azd ai agent init, the CLI resolves the current values from the model catalog. To reference the deployment from your agent, expose the deployment name as an environment variable. During azd ai agent init, the CLI records the deployment name you select in your azd environment as AZURE_AI_MODEL_DEPLOYMENT_NAME, and the agent reads it with ${AZURE_AI_MODEL_DEPLOYMENT_NAME}, as shown in the next step. To change the deployment later, run azd env set AZURE_AI_MODEL_DEPLOYMENT_NAME <deployment-name>.

Configure the agent service

The azure.ai.agent service carries the agent definition. Set kind: hosted for a containerized agent built from source, point project at the source directory, and declare the protocol the agent implements:
The src/my-agent directory holds your agent code and, for container builds, a Dockerfile. Running azd ai agent init scaffolds both. See Initialize a hosted agent project. Key fields to set:
  • language identifies the build language. Use docker. The example shows the container build path (Dockerfile, startupCommand, and container.resources); deploy mode is a separate choice, described in Choose a deploy mode.
  • kind sets the agent kind. Use hosted so Foundry builds and runs your agent source, in either deploy mode.
  • uses lists the services this agent depends on. Start with the project, then add connections and toolboxes as you introduce them.
  • protocols declares the HTTP contract the agent serves. Use responses for the OpenAI Responses API; invocations and a2a are also available.
  • env passes environment variables to the container. Use ${VAR_NAME} to read values from your active azd environment (.azure/<env>/.env). Variables you define use your own names; platform-injected variables use the reserved FOUNDRY_ prefix, such as FOUNDRY_PROJECT_ENDPOINT.
  • startupCommand starts the agent server. azd ai agent run uses it locally, and the container uses it at startup.
  • container.resources sets CPU and memory. Set cpu from "0.25" to "4.0" and memory from 0.5Gi to 8.0Gi.
Don’t declare FOUNDRY_PROJECT_ENDPOINT in env. The platform injects it into hosted containers automatically, and azd ai agent run sets it for local development.

Add a connection

A connection links your project to an external resource, such as a remote Model Context Protocol (MCP) server or a search index. Declare it as an azure.ai.connection service whose key is the connection name, and depend on the project:
Store secret values in your azd environment and reference them with ${VAR} rather than hardcoding them. Set the secret with azd env set GITHUB_PAT <value>.

Add a toolbox and wire it to the agent

A toolbox is a named bundle of tools that the agent uses at runtime. Declare an azure.ai.toolbox service, list its tools, and point connection-backed tools at a connection service:
Then wire the toolbox into the agent by adding its service name to both the agent’s uses list and its toolboxes list:

Split large definitions with $ref

As a project grows, you can move a service or a list entry into its own file and include it with $ref. Relative paths resolve from the file that contains the reference:
File includes keep azure.yaml readable and let you share definitions across projects. Remote URLs aren’t supported.

Choose a deploy mode

Deploy mode is a separate choice from the language: docker build setting. A hosted agent deploys in one of two modes: Select the mode at initialization time:
To deploy a prebuilt image instead of building from source, set the image field on the agent service to the image URL. For the codeConfiguration fields that code mode uses, see Deploy a hosted agent from source code.

Choose infrastructure

The azd ai agent init command doesn’t use Bicep by default. It doesn’t create an infra/ directory. Instead, azd generates the infrastructure from your azure.yaml services when you provision. To create infrastructure-as-code files that you can customize and check in, eject them:
When an infra block is present in azure.yaml, azd uses those files instead of synthesizing infrastructure.

Complete example

The following azure.yaml combines every block in this article into one file: the project and its model deployment, a connection, a toolbox wired to the agent, and the hosted agent itself. It introduces no new fields. Use it to check the indentation and the cross-service uses references in your own file.
The uses fields form the dependency graph that azd resolves at provision and deploy time. Each arrow points from a service to the service it depends on:

Validate your azure.yaml

Confirm the file provisions and deploys as expected:
A successful azd provision prints a summary of the resources it created or reused. azd ai agent run builds and starts the agent locally and prints the local URL it serves the Responses API on. To confirm the agent responds, send a request to that URL or run azd ai agent invoke --local. If your editor supports the YAML language server, the schema annotation at the top of the file provides autocompletion and flags basic type mismatches as you type.

Troubleshoot

Clean up resources

When you’re finished, delete the resources you provisioned so they don’t continue to incur cost: