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.
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
containermode or build from aDockerfile. Code deployment doesn’t require Docker.
Understand the structure
Every entry underservices 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.
Start from a generated file
You rarely start with an empty file. When you runazd 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
Theazure.ai.project service provisions (or connects to) a Foundry project and owns its model deployments. Add a deployment under deployments:
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
Theazure.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:
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:
languageidentifies the build language. Usedocker. The example shows the container build path (Dockerfile,startupCommand, andcontainer.resources); deploy mode is a separate choice, described in Choose a deploy mode.kindsets the agent kind. Usehostedso Foundry builds and runs your agent source, in either deploy mode.useslists the services this agent depends on. Start with the project, then add connections and toolboxes as you introduce them.protocolsdeclares the HTTP contract the agent serves. Useresponsesfor the OpenAI Responses API;invocationsanda2aare also available.envpasses environment variables to the container. Use${VAR_NAME}to read values from your activeazdenvironment (.azure/<env>/.env). Variables you define use your own names; platform-injected variables use the reservedFOUNDRY_prefix, such asFOUNDRY_PROJECT_ENDPOINT.startupCommandstarts the agent server.azd ai agent runuses it locally, and the container uses it at startup.container.resourcessets CPU and memory. Setcpufrom"0.25"to"4.0"andmemoryfrom0.5Gito8.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 anazure.ai.connection service whose key is the connection name, and depend on the project:
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 anazure.ai.toolbox service, list its tools, and point connection-backed tools at a connection service:
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:
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 thelanguage: docker build setting. A hosted agent deploys in one of two modes:
Select the mode at initialization time:
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
Theazd 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:
infra block is present in azure.yaml, azd uses those files instead of synthesizing infrastructure.
Complete example
The followingazure.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.
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: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.