Skip to content

[Agent Extension] Add file operations for hosted agent sessions#7141

Draft
trangevi wants to merge 1 commit intomainfrom
trangevi/agent-files-handling
Draft

[Agent Extension] Add file operations for hosted agent sessions#7141
trangevi wants to merge 1 commit intomainfrom
trangevi/agent-files-handling

Conversation

@trangevi
Copy link
Member

Add 'azd ai agent files' command group with upload, download, list, and remove subcommands for managing session-scoped files on hosted agent sandboxes. This enables debugging, seeding data, and agent setup.

New commands:

  • files upload --path
  • files download [-o ]
  • files list [remote-path] [--output json|table]
  • files remove [--recursive]

All commands require --name, --version, and --session flags. Uses the vnext API version (2025-11-15-preview) for session-scoped endpoints.

Add 'azd ai agent files' command group with upload, download, list, and
remove subcommands for managing session-scoped files on hosted agent
sandboxes. This enables debugging, seeding data, and agent setup.

New commands:
- files upload <remote-path> --path <local-path>
- files download <remote-path> [-o <output-path>]
- files list [remote-path] [--output json|table]
- files remove <remote-path> [--recursive]

All commands require --name, --version, and --session flags. Uses the
vnext API version (2025-11-15-preview) for session-scoped endpoints.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new azd ai agent files command group to the azure.ai.agents extension to manage session-scoped files on hosted agent sandboxes, backed by new session file API operations and models.

Changes:

  • Introduces files command group with upload, download, list, and remove subcommands (plus basic command/formatting tests).
  • Adds session file API operations (upload/download/list/remove) to the agent API client.
  • Adds session file listing models and new extension error codes for file-related failures.

Reviewed changes

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

Show a summary per file
File Description
cli/azd/extensions/azure.ai.agents/internal/pkg/agents/agent_api/operations.go Adds client operations for session file upload/download/list/remove.
cli/azd/extensions/azure.ai.agents/internal/pkg/agents/agent_api/models.go Adds models for representing session file listings.
cli/azd/extensions/azure.ai.agents/internal/exterrors/codes.go Introduces new error codes for file operation scenarios.
cli/azd/extensions/azure.ai.agents/internal/cmd/root.go Registers the new files command group on the extension root command.
cli/azd/extensions/azure.ai.agents/internal/cmd/files.go Implements the files command group and subcommands (CLI UX + printing).
cli/azd/extensions/azure.ai.agents/internal/cmd/files_test.go Adds tests for subcommand presence, required flags, and output helpers.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +1008 to +1027
token, err := c.credential.GetToken(ctx, policy.TokenRequestOptions{
Scopes: []string{"https://ai.azure.com/.default"},
})
if err != nil {
return fmt.Errorf("failed to get auth token: %w", err)
}

req, err := http.NewRequestWithContext(ctx, http.MethodPut, u.String(), body)
if err != nil {
return fmt.Errorf("failed to create request: %w", err)
}

req.Header.Set("Authorization", "Bearer "+token.Token)
req.Header.Set("Content-Type", "application/octet-stream")
req.Header.Set("User-Agent", fmt.Sprintf("azd-ext-azure-ai-agents/%s", version.Version))

httpClient := &http.Client{}
//nolint:gosec // request URL is built from trusted SDK endpoint + path components
resp, err := httpClient.Do(req)
if err != nil {
Comment on lines +1062 to +1079
token, err := c.credential.GetToken(ctx, policy.TokenRequestOptions{
Scopes: []string{"https://ai.azure.com/.default"},
})
if err != nil {
return nil, fmt.Errorf("failed to get auth token: %w", err)
}

req, err := http.NewRequestWithContext(ctx, http.MethodGet, u.String(), nil)
if err != nil {
return nil, fmt.Errorf("failed to create request: %w", err)
}

req.Header.Set("Authorization", "Bearer "+token.Token)
req.Header.Set("User-Agent", fmt.Sprintf("azd-ext-azure-ai-agents/%s", version.Version))

httpClient := &http.Client{}
//nolint:gosec // request URL is built from trusted SDK endpoint + path components
resp, err := httpClient.Do(req)

func newFilesCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "files <command>",
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants