[ext-agents]: azd ai agent init -m <azure.yaml> should merge into an existing project's azure.yaml
- Dominant language
- Go
- Stars
- 569
- Forks
- 364
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 136
Description
## Summary
Follow-up to #8798. The initial implementation (PR adopting a sample's unified `azure.yaml` via `azd ai agent init -m`) handles the **fresh-project** case: when the target directory has no `azure.yaml`, the sample's `azure.yaml` (and referenced files) is adopted as the project manifest via azd-core's native template adoption.
The **existing-project** case is not yet supported. When a project-root `azure.yaml` already exists and the user runs `azd ai agent init -m `, the command currently returns a clear, actionable error rather than merging.
## Desired behavior
Fall back to today's "add to project" behavior: append the sample's **agent service(s)** (and any `uses:`-referenced `azure.ai.project` / `azure.ai.connection` / `azure.ai.toolbox` sibling services not already present) into the existing `azure.yaml`, copying each agent's `project:` source directory into the project. Resolve service-name collisions (reuse `resolveCollisions`), and skip siblings that already exist so dependencies still resolve.
## Why it was split out
Correctly appending a unified `azure.yaml`'s services into an existing project requires careful per-host service round-tripping through `Project().AddService` — e.g. `uses:` is carried in `AdditionalProperties` and wired separately in the manifest flow, and each Foundry host promotes a different set of fields. Getting this wrong can drop or duplicate keys in the written `azure.yaml`, and it's hard to verify without live gRPC. Splitting it keeps the primary fresh-project adoption shippable and well-tested.
## Acceptance
- `azd ai agent init -m ` in a directory with an existing project `azure.yaml` appends the sample's agent service(s) + missing referenced siblings, copying source dirs, with collisions resolved.
- The written `azure.yaml` round-trips cleanly (no dropped/duplicated keys; `uses:` preserved).
- Tests cover the merge (including name collisions and already-present siblings).
## Related
- #8798
- Current interim behavior: returns a validation error pointing the user to run in an empty directory or add an individual agent via `-m `.
Contributor guide
Assessment
This issue has not been assessed yet.