Skip to content

Commit 82cc8be

Browse files
committed
Refactor foundry-agent documentation and tests
- Removed the direct-code deployment reference file as it is no longer needed. - Added unit tests for the azd-based hosted-agent create workflow to ensure the new patterns are correctly implemented. - Deleted outdated toolbox paths unit tests that referenced removed samples. - Introduced unit tests for the azd-based hosted-agent deploy workflow to validate the new deployment process. - Removed direct-code unit tests that were redundant after the removal of the direct-code deployment reference.
1 parent fbf983a commit 82cc8be

11 files changed

Lines changed: 837 additions & 1154 deletions

File tree

plugin/skills/microsoft-foundry/SKILL.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ This skill includes specialized sub-skills for specific workflows. **Use these i
2323

2424
| Sub-Skill | When to Use | Reference |
2525
|-----------|-------------|-----------|
26-
| **deploy** | Containerize, build, push to ACR, create/update/clone agent deployments | [deploy](foundry-agent/deploy/deploy.md) |
26+
| **deploy** | Deploy hosted agents with `azd provision` + `azd deploy`, smoke-test with `azd ai agent show`/`invoke`. Create or update prompt agents via the Foundry MCP `agent_update` tool. Manage versions, endpoint patches, multi-env deploys. | [deploy](foundry-agent/deploy/deploy.md) |
2727
| **invoke** | Send messages to an agent, single or multi-turn conversations | [invoke](foundry-agent/invoke/invoke.md) |
2828
| **invocations-ws** | Build, deploy, and connect to hosted agents that speak the `invocations_ws` duplex WebSocket protocol — voice agents, real-time streams, and signaling for out-of-band media transports. | [invocations-ws](foundry-agent/invocations-ws/invocations-ws.md) |
2929
| **observe** | Evaluate agent quality, run batch evals, analyze failures, optimize prompts, improve agent instructions, compare versions, set up CI/CD monitoring, and enable continuous production evaluation | [observe](foundry-agent/observe/observe.md) |
3030
| **trace** | Query traces, analyze latency/failures, correlate eval results to specific responses via App Insights `customEvents` | [trace](foundry-agent/trace/trace.md) |
3131
| **troubleshoot** | View hosted agent logs, query telemetry, diagnose failures | [troubleshoot](foundry-agent/troubleshoot/troubleshoot.md) |
32-
| **create** | Create new hosted agent applications. Supports Microsoft Agent Framework, LangGraph, or custom frameworks in Python or C#, across `responses`, `invocations`, or `invocations_ws` protocols. | [create](foundry-agent/create/create-hosted.md) |
32+
| **create** | Scaffold a hosted Foundry agent project with `azd ai agent init` -- greenfield from a curated sample, or brownfield from existing code (`--from-code`). Run + iterate locally with `azd ai agent run` and `azd ai agent invoke --local` before deploying. Add tools (web search, AI Search, MCP, A2A) via the toolbox workflow. | [create](foundry-agent/create/create-hosted.md) |
3333
| **agent-optimizer** | Make existing Python hosted-agent code optimization-ready, configure eval.yaml, run Agent Optimizer jobs, apply candidates locally, and deploy through azd after review. | [agent-optimizer](foundry-agent/agent-optimizer/agent-optimizer.md) |
3434
| **eval-datasets** | Harvest production traces into evaluation datasets, manage dataset versions and splits, track evaluation metrics over time, detect regressions, and maintain full lineage from trace to deployment. Use for: create dataset from traces, dataset versioning, evaluation trending, regression detection, dataset comparison, eval lineage. | [eval-datasets](foundry-agent/eval-datasets/eval-datasets.md) |
3535
| **project/create** | Creating a new Azure AI Foundry project for hosting agents and models. Use when onboarding to Foundry or setting up new infrastructure. | [project/create/create-foundry-project.md](project/create/create-foundry-project.md) |

plugin/skills/microsoft-foundry/foundry-agent/create/create-hosted.md

Lines changed: 111 additions & 287 deletions
Large diffs are not rendered by default.
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
# azd ai CLI Reference
2+
3+
Core 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.
4+
5+
## CLI surface
6+
7+
```bash
8+
azd ai project show # which Foundry project endpoint is active
9+
azd ai agent show # is the agent deployed? what version?
10+
azd ai agent doctor # full health check, suggests fixes
11+
12+
azd ai agent sample list # curated catalog -- pick a manifestUrl
13+
azd ai agent init -m <manifestUrl> # scaffold from a sample
14+
azd ai agent init --from-code # scaffold from existing source
15+
16+
azd ai agent run # start the agent on localhost:8088
17+
azd ai agent invoke "<msg>" # remote invoke (billed; gated)
18+
azd ai agent invoke --local "<msg>" # local invoke (no billing)
19+
20+
azd provision # core azd; creates Foundry project + infra
21+
azd deploy # core azd; packages + registers new agent version
22+
azd ai agent endpoint update # patch agentEndpoint / agentCard in place
23+
24+
azd ai agent connection list / show / create / update / delete
25+
azd ai toolbox list / show / create / update / delete
26+
azd ai toolbox connection add / remove / list
27+
azd ai toolbox version list
28+
29+
azd ai agent files list / show / upload / download / delete / stat / mkdir
30+
azd ai agent sessions list / show / create / update / delete
31+
azd ai agent monitor # per-session log stream (SSE)
32+
33+
azd ai agent eval init / run / show / update / list
34+
azd ai agent optimize / optimize status / optimize apply / optimize deploy / optimize cancel
35+
```
36+
37+
Read-only commands accept `--output json` and never require `--force`. Write commands are gated by a confirmation envelope (see "Confirmation envelope" below).
38+
39+
## Two files, two schemas
40+
41+
After `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.
42+
43+
| File | What it holds |
44+
|------|---------------|
45+
| `<service-dir>/agent.yaml` | The flat `ContainerAgent`: `kind`, `name`, `protocols`, `environment_variables`, `agentEndpoint`, `agentCard`, `codeConfiguration` / `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`. |
48+
49+
`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.
50+
51+
`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`.
52+
53+
### Minimal `agent.yaml` (hosted)
54+
55+
```yaml
56+
# yaml-language-server: $schema=https://raw.githubusercontent.com/microsoft/AgentSchema/refs/heads/main/schemas/v1.0/ContainerAgent.yaml
57+
kind: hosted
58+
name: my-agent
59+
protocols:
60+
- protocol: responses
61+
version: "1.0.0"
62+
resources:
63+
cpu: "0.25"
64+
memory: "0.5Gi"
65+
environment_variables:
66+
- name: AZURE_AI_MODEL_DEPLOYMENT_NAME
67+
value: ${AZURE_AI_MODEL_DEPLOYMENT_NAME}
68+
codeConfiguration:
69+
runtime: python_3_13
70+
entryPoint: app.py
71+
dependencyResolution: remote_build # or "bundled"
72+
```
73+
74+
- `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+
- `codeConfiguration` present -> code deploy (ZIP, Foundry builds). Absent -> container deploy (Dockerfile + `docker:` in azure.yaml). `image:` skips the Dockerfile build.
78+
- `agentEndpoint` / `agentCard` -- patch in place with `azd ai agent endpoint update` (no new version).
79+
80+
### Minimal `azure.yaml` service config
81+
82+
```yaml
83+
services:
84+
my-agent:
85+
project: ./src/my-agent
86+
host: ai.agent
87+
language: docker # or "python" / "csharp" for code deploy
88+
docker:
89+
remoteBuild: true # omit for code deploy
90+
config:
91+
startupCommand: "python -m main"
92+
container:
93+
resources:
94+
cpu: "0.5"
95+
memory: "1Gi"
96+
deployments:
97+
- name: AZURE_AI_MODEL_DEPLOYMENT_NAME
98+
model:
99+
name: gpt-4.1-mini
100+
format: OpenAI
101+
version: "2024-04-09"
102+
sku:
103+
name: GlobalStandard
104+
capacity: 50
105+
connections: [...] # see tools.md
106+
toolboxes: [...] # see tools.md
107+
```
108+
109+
- `startupCommand` -- what `azd ai agent run` executes locally. Auto-detected at init.
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).
113+
114+
## State (azd env vars)
115+
116+
| 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` |
123+
124+
Manage with `azd env get-values`, `azd env set`, `azd env list`, `azd env new`, `azd env select`.
125+
126+
The platform also injects `FOUNDRY_*` and `AGENT_*` into the running container at runtime. **Never** put these in the agent.yaml environment_variables section.
127+
128+
## Resolving subscription / location
129+
130+
`azd ai project show` returns only the Foundry project endpoint. For subscription / location, try in order:
131+
132+
1. `azd config get defaults`
133+
2. `azd env get-values`
134+
3. Ask the user.
135+
4. Last resort, with explicit consent: `az account list --output json`.
136+
137+
For 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.
138+
139+
## Common error codes
140+
141+
- `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.
148+
149+
Any unfamiliar `code` value is safe to surface verbatim to the user.
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Local Run Reference
2+
3+
Use this when iterating on a hosted agent before deploying.
4+
5+
## Start the agent locally
6+
7+
```bash
8+
azd ai agent run
9+
```
10+
11+
What this does:
12+
13+
1. Resolves the agent service from `azure.yaml` (auto-picks when only one exists).
14+
2. Detects the project type (Python, .NET, Node.js) from files in the service source dir.
15+
3. Installs dependencies if needed (`uv pip install -e .`, `npm install`, `dotnet restore`).
16+
4. Starts the agent in the foreground on `localhost:8088` (default).
17+
5. Opens **Agent Inspector** in your browser (unless `--no-inspector`).
18+
19+
> First startup takes 30-60 seconds. Wait before sending the first invocation.
20+
21+
`Ctrl+C` stops the agent and clears the saved local session id.
22+
23+
## Useful flags
24+
25+
| Flag | Purpose |
26+
|------|---------|
27+
| `--port <n>` / `-p <n>` | Override the listen port. Useful when 8088 is taken. |
28+
| `--start-command "<cmd>"` / `-c "<cmd>"` | Override `azure.yaml` and auto-detect. Example: `--start-command "python app.py"`. |
29+
| `--no-inspector` | Skip opening Agent Inspector. Use in CI / SSH. |
30+
31+
Pass the service name when there are multiple `ai.agent` services:
32+
33+
```bash
34+
azd ai agent run my-agent
35+
```
36+
37+
## Where the start command comes from
38+
39+
Resolution order (first non-empty wins):
40+
41+
1. `--start-command` flag.
42+
2. `azure.yaml services.<name>.config.startupCommand`.
43+
3. Auto-detected from project type.
44+
45+
Example:
46+
47+
```yaml
48+
# azure.yaml
49+
services:
50+
my-agent:
51+
project: src/my-agent
52+
language: py
53+
host: ai.agent
54+
config:
55+
startupCommand: "uvicorn app:app --host 0.0.0.0 --port 4001"
56+
```
57+
58+
If detection fails and no override is set, `run` errors with the project dir and asks for `--start-command` or `startupCommand`.
59+
60+
## Invoke the local agent
61+
62+
```bash
63+
azd ai agent invoke --local "hello, are you up?"
64+
```
65+
66+
`--local` differs from a remote invoke in:
67+
68+
- Targets `http://localhost:<port>` instead of the Foundry endpoint.
69+
- Skips the confirmation envelope (no billing, no remote mutation).
70+
- `--version` is rejected (versions are a remote concept).
71+
- Named-agent invocation is rejected (only one agent runs locally at a time).
72+
73+
Other useful flags:
74+
75+
| Flag | Purpose |
76+
|------|---------|
77+
| `--protocol responses` (default) / `--protocol invocations` | Wire format your agent speaks. |
78+
| `--input-file request.json` / `-f request.json` | Send a file body instead of a string message. |
79+
| `--new-session` | Drop the saved local session and start fresh. |
80+
| `--port <n>` | Match the port you started `run` with. |
81+
82+
## When to graduate to remote
83+
84+
Local dev validates code shape; remote validates infra + identity + Foundry binding. Move to deploy when:
85+
86+
- You changed `agent.yaml` `model:`, `tools:`, `connections:`, or `protocols:`. Those only take effect on the deployed agent.
87+
- You need to test against real Foundry connections (search indexes, Bing, MCP, A2A) that have no local mock.
88+
- You are ready to publish a new immutable agent version.
89+
90+
Next step -> [deploy/deploy.md](../../deploy/deploy.md).
91+
92+
## Common failures
93+
94+
| Symptom | Likely cause | Fix |
95+
|---------|--------------|-----|
96+
| `could not connect to localhost:<port>` | `run` not started, or wrong port | Start `azd ai agent run`; pass `--port` to `invoke --local` if non-default. |
97+
| `could not detect project type in <dir>` | Missing project marker file | Set `startupCommand` in `azure.yaml` or pass `--start-command`. |
98+
| `cannot use --local with a named agent` | Named-agent invoke against localhost | Drop the name; only one local agent at a time. |
99+
| `cannot use --version with --local` | `--version` is remote-only | Drop `--version`, or remove `--local` to hit the deployed agent. |
100+
| Inspector never opens | Headless env, or extension install failed | Pass `--no-inspector`, or run `azd extension install azure.ai.inspector`. |
101+
| Auth / connection errors against Azure services | Local credentials not wired | Expected -- `DefaultAzureCredential` falls back to your `az login` / VS Code identity. Use `azd auth login` if needed. |

0 commit comments

Comments
 (0)