Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Deploy, evaluate, and manage AI agents end-to-end on Microsoft Azure AI Foundry
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
foundry-agent/create/references/azd-ai-cli.md
1# azd ai CLI Reference23Core mental model for the `azd ai agent` extension. Use this when you need to understand command surface, file layout, or where a given setting lives.45## CLI surface67```bash8azd ai project show # which Foundry project endpoint is active9azd ai agent show # is the agent deployed? what version?10azd ai agent doctor # full health check, suggests fixes1112azd ai agent sample list # curated catalog -- pick a manifestUrl13azd ai agent init -m <manifestUrl> # scaffold from a sample14azd ai agent init --from-code # scaffold from existing source1516azd ai agent run # start the agent on localhost:808817azd ai agent invoke "<msg>" # remote invoke (billed; gated)18azd ai agent invoke --local "<msg>" # local invoke (no billing)1920azd provision # core azd; creates Foundry project + infra21azd deploy # core azd; packages + registers new agent version22azd ai agent endpoint update # patch agentEndpoint / agentCard in place2324azd ai agent connection list / show / create / update / delete25azd ai toolbox list / show / create / update / delete26azd ai toolbox connection add / remove / list27azd ai toolbox version list2829azd ai agent files list / show / upload / download / delete / stat / mkdir30azd ai agent sessions list / show / create / update / delete31azd ai agent monitor # per-session log stream (SSE)3233azd ai agent eval generate / run / show / update / list34azd ai agent optimize / optimize status / optimize apply / optimize deploy / optimize cancel35```3637Read-only commands accept `--output json` and never require `--force`. Write commands are gated by a confirmation envelope (see "Confirmation envelope" below).3839## Two files, two schemas4041After `azd ai agent init`, every hosted agent is defined by **two** files plus the active azd env. Putting a field in the wrong file is the most common scaffolding failure.4243| File | What it holds |44|------|---------------|45| `<service-dir>/agent.yaml` | The flat `ContainerAgent`: `kind`, `name`, `protocols`, `environment_variables`, `agentEndpoint`, `agentCard`, `code_configuration` / `image`, container `resources` (cpu, memory). |46| `azure.yaml services.<name>.config` | Model deployments, project connections, toolboxes, tool resources, container settings, `startupCommand`. |47| `.azure/<env>/.env` (`azd env set`) | Secrets and `PARAM_<CONN>_<KEY>` credential values referenced from `azure.yaml`. |4849`azd deploy` reads `agent.yaml` and creates a new immutable agent version. `azd provision` reads `config.deployments[]` and `config.connections[]` and applies them via Bicep.5051`agent.manifest.yaml` (the file passed to `-m`) is the seed format -- it is NOT on disk after init. Init splits its `parameters:` / `resources:` blocks across the three files above. Don't reintroduce the `template:` wrapper into `agent.yaml`.5253### Minimal `agent.yaml` (hosted)5455```yaml56# yaml-language-server: $schema=https://raw.githubusercontent.com/microsoft/AgentSchema/refs/heads/main/schemas/v1.0/ContainerAgent.yaml57kind: hosted58name: my-agent59protocols:60- protocol: responses61version: "1.0.0"62resources:63cpu: "0.25"64memory: "0.5Gi"65environment_variables:66- name: AZURE_AI_MODEL_DEPLOYMENT_NAME67value: ${AZURE_AI_MODEL_DEPLOYMENT_NAME}68code_configuration:69runtime: python_3_1370entry_point: app.py71dependency_resolution: remote_build # or "bundled"72```7374- `protocols` -- `responses` (OpenAI), `invocations` (A2A). Editing requires `azd deploy`.75- `resources` -- valid tiers: `0.25/0.5Gi`, `1/2Gi`, `2/4Gi`.76- `environment_variables` -- `${VAR}` resolves from the active azd env. Not for secrets.77- `code_configuration` present -> direct code deploy (ZIP, Foundry builds). Absent -> container/ACR deploy (Dockerfile + `docker:` in `azure.yaml`). `image:` skips the Dockerfile build.78- In non-interactive mode, `azd ai agent init` defaults to container deploy. Pass `--deploy-mode code --runtime <runtime> --entry-point <file>` during init to get `code_configuration`.79- `agentEndpoint` / `agentCard` -- patch in place with `azd ai agent endpoint update` (no new version).8081### Minimal `azure.yaml` service config8283```yaml84services:85my-agent:86project: ./src/my-agent87host: azure.ai.agent88language: python89config:90startupCommand: "python -m main"91container:92resources:93cpu: "0.5"94memory: "1Gi"95deployments:96- name: AZURE_AI_MODEL_DEPLOYMENT_NAME97model:98name: gpt-4.1-mini99format: OpenAI100version: "2024-04-09"101sku:102name: GlobalStandard103capacity: 50104connections: [...] # see tools.md105toolboxes: [...] # see tools.md106```107108- `startupCommand` -- what `azd ai agent run` executes locally. Auto-detected at init.109- `config.container.resources` -- deployment-time CPU/memory. Keep this aligned with `agent.yaml resources`; this value can override the agent file.110- `deployments[]` -- model deployments provisioned via Bicep. `name` is the env var the agent reads.111- `connections[]` -- project connections provisioned via Bicep. Use `PARAM_<CONN>_<KEY>` env-var references for secrets.112- `toolboxes[]` -- declarative record of intent; today you still drive the toolbox CLI to materialize them on Foundry. See [tools](tools.md).113114## State (azd env vars)115116| Variable | Read by | Where to set |117|----------|---------|--------------|118| `AZURE_AI_PROJECT_ENDPOINT` | Every `azd ai agent` command | `azd env set` or `azd ai project show` |119| `AZURE_AI_PROJECT_ID` | `azd ai agent show` (playground URL) | `azd env set` |120| `AZURE_SUBSCRIPTION_ID`, `AZURE_LOCATION` | `azd provision` | `azd config get defaults` |121| `AGENT_<SVC>_NAME` / `_VERSION` / `_<PROTO>_ENDPOINT` | Auto-written by deploy | Auto |122| `PARAM_<CONN>_<KEY>` | Connection credentials in `azure.yaml` | `azd env set` |123124Manage with `azd env get-values`, `azd env set`, `azd env list`, `azd env new`, `azd env select`.125126The platform also injects `FOUNDRY_*` and `AGENT_*` into the running container at runtime. **Never** put these in the agent.yaml environment_variables section.127128## Resolving subscription / location129130`azd ai project show` returns only the Foundry project endpoint. For subscription / location, try in order:1311321. `azd config get defaults`1332. `azd env get-values`1343. Ask the user.1354. Last resort, with explicit consent: `az account list --output json`.136137For the Foundry project ARM ID (`--project-id`), ask the user: "New project, or use an existing one?" If existing, ask for the ID and hint where to find it (https://ai.azure.com -> Operate -> Admin). Do NOT shell out to `az cognitiveservices` -- it returns the wrong resource shape.138139## Common error codes140141- `not_logged_in` / `login_expired` -- ask the user to run `azd auth login`.142- `missing_project_endpoint` -- run `azd provision`, or `azd env set AZURE_AI_PROJECT_ENDPOINT <url>`.143- `project_not_found` -- cwd has no `azure.yaml`. Move to project root or run init.144- `invalid_agent_manifest` -- `agent.yaml` is malformed. Run `azd ai agent doctor` and read the named field.145- `invalid_connection` -- inspect with `azd ai agent connection show <name>`.146- `eval_config_invalid` -- `eval.yaml` failed validation. Run `azd ai agent doctor`.147- `agent_definition_not_found` -- deployed name doesn't match `azure.yaml`. Re-deploy from project root.148149Any unfamiliar `code` value is safe to surface verbatim to the user.150