Summary
Add a new command azd ai agent code download that allows developers to download the deployed source code of a code-based hosted agent from Azure AI Foundry.
Motivation
Currently azd deploy pushes local code to Foundry (via CreateAgentFromZip/UpdateAgentFromZip), but there is no reverse operation. Developers cannot:
- Inspect the code that is actually running on a deployed agent
- Restore/clone an agent's source code to local
- Download a previous version's code for comparison or rollback
The Vienna backend already supports this via GET /agents/{name}/code:download?agent_version=N (feature-gated by CodeAgents=V1Preview,HostedAgents=V1Preview).
Proposed Command
azd ai agent code download [name] [flags]
Flags
| Flag |
Required |
Description |
[name] |
No |
Agent name (resolved from azure.yaml if omitted) |
--version, -v |
No |
Agent version to download (default: latest) |
--output, -o |
No |
Output path (default: ./<agent-name>/) |
--zip |
No |
Save as .zip instead of extracting |
Behavior
- Calls
GET /agents/{name}/code:download?agent_version=N
- Default: downloads zip, extracts to output directory, deletes temp zip
--zip: saves zip file directly
- If output path already exists: error with suggestion to use
-o
- Verifies SHA256 hash from
x-ms-code-zip-sha256 response header
- Prints summary: agent name, version downloaded, output path
Implementation
- New API method
DownloadAgentCode() in operations.go (streaming pattern, same as DownloadSessionFile)
- New command group
code with download subcommand in cmd/code.go
- Register in
root.go
- Feature header:
CodeAgents=V1Preview,HostedAgents=V1Preview (same as zip upload)
Notes
- No breaking changes to existing commands
- No conflicts with existing command names
- The
CodeAgents=V1Preview feature flag is already used by zip upload (deploy), so this is gated at the same level
Summary
Add a new command
azd ai agent code downloadthat allows developers to download the deployed source code of a code-based hosted agent from Azure AI Foundry.Motivation
Currently
azd deploypushes local code to Foundry (viaCreateAgentFromZip/UpdateAgentFromZip), but there is no reverse operation. Developers cannot:The Vienna backend already supports this via
GET /agents/{name}/code:download?agent_version=N(feature-gated byCodeAgents=V1Preview,HostedAgents=V1Preview).Proposed Command
Flags
[name]--version, -v--output, -o./<agent-name>/)--zipBehavior
GET /agents/{name}/code:download?agent_version=N--zip: saves zip file directly-ox-ms-code-zip-sha256response headerImplementation
DownloadAgentCode()inoperations.go(streaming pattern, same asDownloadSessionFile)codewithdownloadsubcommand incmd/code.goroot.goCodeAgents=V1Preview,HostedAgents=V1Preview(same as zip upload)Notes
CodeAgents=V1Previewfeature flag is already used by zip upload (deploy), so this is gated at the same level