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.
Use azd ai agent init to scaffold a hosted agent project with the files you need to build, test, and deploy an AI agent to Microsoft Foundry. In this article, you choose a starting point and initialize the project from a template, from your own code, or against an existing Foundry project.

Prerequisites

Choose a starting point

There are three ways to begin a project. Pick the path that matches your situation.

Initialize from a template

Run the interactive wizard in an empty directory and select Start new from a template:
The wizard walks you through the following choices. The agent name comes from the template. The CLI creates an azd environment named <directory>-dev and configures it with details from your selected Foundry project. Each template includes agent source code, a Dockerfile, and an azure.yaml file that acts as the unified project manifest for the azd project and hosted agent configuration.

Initialize from an azure.yaml URL

If you have a specific agent sample, point -m to the sample’s azure.yaml. The CLI adopts that file as the project manifest and downloads the referenced agent source.
Agent manifests (agent.manifest.yaml) and standalone agent definitions (agent.yaml) are deprecated. As of the Foundry azd extensions (azure.ai.agents 1.0.0-beta.1), all hosted agent configuration lives in a single azure.yaml. See Author azure.yaml for hosted agents.
The -m option still accepts a legacy agent manifest URL, but current samples publish a unified azure.yaml.

Specify a model

Choose a model at init time:
Or use an existing model deployment in your Foundry project:

Choose a deploy mode

By default, azd ai agent init uses code deployment for Python and .NET projects. Code deployment uploads your source as a ZIP package. To scaffold a container-based project instead, pass --deploy-mode container:
To deploy a prebuilt container image, pass --image and --agent-name. This option skips template and language selection, code scaffolding, Dockerfile generation, and Azure Container Registry setup.

Browse templates noninteractively

To inspect the catalog before you scaffold, or to drive azd ai agent init from a script, list the catalog:
Each entry includes a ready-to-run initCommand that you copy and run in the directory you want to scaffold into.
When you reuse a sample under a different Foundry agent identity, pass --agent-name <new-name> on azd ai agent init so the name written to azure.yaml doesn’t collide with the sample default name.

Initialize from existing code

If you have existing Python or .NET agent code, run azd ai agent init inside the directory that already contains your code:
The CLI detects the existing files and generates an azure.yaml service entry around them without overwriting your code. For container deployment, it also adds a Dockerfile. Infrastructure remains bicep-less by default unless you eject infrastructure as code later. Your agent code must meet the hosted agent runtime contract:
  • Listen on port 8088.
  • Serve a health probe at GET /readiness.
  • Handle one of the supported protocols (responses or invocations).
If your code doesn’t already speak one of these protocols, add a protocol adapter, a lightweight SDK wrapper that translates between the Foundry protocol and your agent’s logic. To add an agent to an existing azd project, init detects the project and adds a new service entry to your existing azure.yaml. Use --src to specify a subdirectory:

Connect to an existing Foundry project

To manage an existing Foundry project through azd, run the wizard and select the option to connect to an existing project. You can also skip the interactive selection by providing the project’s Azure resource ID directly:
To find the project ID, open the Foundry portal, go to Operate > Admin, select your Foundry project, and copy the Resource ID value.
When you initialize against an existing project with --project-id, the tooling skips the automatic role assignments that it performs when it creates a new project. Make sure the required roles are already assigned. For the full matrix, see Hosted agent permissions reference.

Review what gets created

After init completes, your project directory contains the following structure:
Templates and samples publish a unified azure.yaml at the project root. During init, azd adopts or generates that file. You work with azure.yaml going forward. Infrastructure is bicep-less by default. Eject infrastructure only when you need to manage the generated IaC files directly.