Skip to content

Add 'azd ai agent code download' command#8576

Merged
v1212 merged 1 commit into
Azure:mainfrom
v1212:jw/agent-code-download
Jun 10, 2026
Merged

Add 'azd ai agent code download' command#8576
v1212 merged 1 commit into
Azure:mainfrom
v1212:jw/agent-code-download

Conversation

@v1212

@v1212 v1212 commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add new azd ai agent code download [name] command to download deployed source code of a code-based hosted agent from Azure AI Foundry
  • Completes the round-trip: azd deploy pushes code, code download pulls it back

Details

New API method (operations.go):

  • DownloadAgentCode() — streaming GET to /agents/{name}/code:download?agent_version=N
  • Feature header: CodeAgents=V1Preview,HostedAgents=V1Preview (same gate as zip upload)
  • Returns body stream + SHA-256 hash + version from response headers

New command (code.go):

  • azd ai agent code download [name] — downloads and extracts source code
  • --version, -v — specific version (default: latest)
  • --dest, -d — destination path (default: ./<agent-name>/ or ./<agent-name>.zip)
  • --zip — save raw zip instead of extracting
  • SHA-256 verification against x-ms-code-zip-sha256 response header
  • Zip-slip protection on extraction
  • Error if output path already exists (suggests --dest)

Command registration (root.go):

  • New code subcommand group registered alongside files, sessions, eval, etc.

Note: Renamed --output/-o to --dest/-d because --output/-o is a reserved azd global flag.

Testing

Build & Unit Tests

  • go build ./... passes
  • All existing tests pass (go test ./internal/...)
  • No breaking changes to existing commands

Live Testing (against real deployed agents)

All tests run against agent hello-world-python-invocations (v1) and hello-world-voice (v7) in project wujia-aifproject-260601 (North Central US).

Test 1: Download latest version (auto-extract) ✅

$ azd ai agent code download
Downloaded agent "hello-world-python-invocations" (version 1) -> hello-world-python-invocations
SHA-256: d057042b12ec4daf54079da2779fe6a66d8078e2b914a095bad576415c8456f5

Extracted files: main.py (7415B), README.md (11594B), requirements.txt (106B)

Test 2: Download as zip (--zip) ✅

$ azd ai agent code download --zip
Downloaded agent "hello-world-python-invocations" (version 1) -> hello-world-python-invocations.zip
SHA-256: d057042b12ec4daf54079da2779fe6a66d8078e2b914a095bad576415c8456f5

Zip file size: 7718 bytes. SHA-256 verified independently via Get-FileHash — matches.

Test 3: Download with --dest

$ azd ai agent code download --dest custom-output-dir
Downloaded agent "hello-world-python-invocations" (version 1) -> custom-output-dir
SHA-256: d057042b12ec4daf54079da2779fe6a66d8078e2b914a095bad576415c8456f5

Test 4: Download specific version (--version 1) ✅

$ azd ai agent code download --version 1 --dest v1-test
Downloaded agent "hello-world-python-invocations" (version 1) -> v1-test
SHA-256: d057042b12ec4daf54079da2779fe6a66d8078e2b914a095bad576415c8456f5

Test 5: Error — output path already exists ✅

$ azd ai agent code download
ERROR: output path "hello-world-python-invocations" already exists

Use --dest (-d) to specify a different path

Test 6: Error — non-existent version (404) ✅

$ azd ai agent code download --version 999 --dest v999-test
ERROR: failed to download agent code: GET .../agents/hello-world-python-invocations/code:download
RESPONSE 404: 404 Not Found
ERROR CODE: not_found
{
  "error": {
    "message": "Agent hello-world-python-invocations with version 999 not found [Request ID: ...]"
  }
}

Test 7: Download different code agent (hello-world-voice) ✅

$ azd ai agent code download voice
Downloaded agent "hello-world-voice" (version 7) -> hello-world-voice
SHA-256: cff9776c21bade65067503f18bc62381df635aec223c5e52d90271ceb8192835

Extracted 9 files including main.py, proxy.py, index.html, requirements.txt.

Closes #8575

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new azd ai agent code download command to the azure.ai.agents extension, enabling users to download a deployed code-based hosted agent’s source code (as a zip or extracted directory) from Azure AI Foundry, completing the deploy/download round-trip.

Changes:

  • Added a new Agent API operation DownloadAgentCode that streams a zip download and returns response metadata (hash + agent version).
  • Introduced a new code command group with a download subcommand that downloads, verifies SHA-256, and optionally extracts with zip-slip protection.
  • Registered the new code command group on the extension root command.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
cli/azd/extensions/azure.ai.agents/internal/pkg/agents/agent_api/operations.go Adds a streaming download API for agent code zip + response metadata parsing.
cli/azd/extensions/azure.ai.agents/internal/cmd/root.go Registers the new code command group on the extension root.
cli/azd/extensions/azure.ai.agents/internal/cmd/code.go Implements azd ai agent code download with output handling, hash verification, and extraction logic.

Comment thread cli/azd/extensions/azure.ai.agents/internal/cmd/code.go Outdated
Comment thread cli/azd/extensions/azure.ai.agents/internal/cmd/code.go Outdated
Comment thread cli/azd/extensions/azure.ai.agents/internal/cmd/code.go Outdated
Comment thread cli/azd/extensions/azure.ai.agents/internal/cmd/code.go
@github-actions github-actions Bot added the ext-agents azure.ai.agents extension label Jun 9, 2026
@v1212 v1212 force-pushed the jw/agent-code-download branch 3 times, most recently from 9096576 to 148c25d Compare June 9, 2026 06:58
Implement a new command to download the deployed source code of a
code-based hosted agent from Azure AI Foundry. This completes the
round-trip: azd deploy pushes code up, and this command pulls it back.

- New API method DownloadAgentCode in operations.go (streaming pattern)
- New 'code' command group with 'download' subcommand
- Supports --version, --output, --zip flags
- SHA-256 hash verification from response header
- Zip-slip protection on extraction

Closes Azure#8575
@v1212 v1212 force-pushed the jw/agent-code-download branch from 148c25d to 7c6887c Compare June 9, 2026 07:00

@therealjohn therealjohn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just add to the help text that it downloads the latest version of the agent when --version is not provided.

@v1212 v1212 merged commit 48b955e into Azure:main Jun 10, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ext-agents azure.ai.agents extension

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add azd ai agent code download command

3 participants