Skip to content

Add azd ai agent code download command #8575

@v1212

Description

@v1212

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

  1. Calls GET /agents/{name}/code:download?agent_version=N
  2. Default: downloads zip, extracts to output directory, deletes temp zip
  3. --zip: saves zip file directly
  4. If output path already exists: error with suggestion to use -o
  5. Verifies SHA256 hash from x-ms-code-zip-sha256 response header
  6. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions