Skip to content

[Agents extension] Prompt user for protocols during "from code" flow#7464

Open
trangevi wants to merge 1 commit intomainfrom
trangevi/low-hanging-fruit
Open

[Agents extension] Prompt user for protocols during "from code" flow#7464
trangevi wants to merge 1 commit intomainfrom
trangevi/low-hanging-fruit

Conversation

@trangevi
Copy link
Copy Markdown
Member

@trangevi trangevi commented Apr 2, 2026

When using local code, prompt the user as to what kind of protocol they want to use.

Signed-off-by: trangevi <trangevi@microsoft.com>
Copy link
Copy Markdown
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

This PR updates the azd ai agent init “from code” flow in the azure.ai.agents extension to let users choose which agent protocols to declare in the generated agent.yaml, instead of always defaulting to responses/v1.

Changes:

  • Added a --protocol flag to allow specifying supported protocols non-interactively.
  • Added an interactive multi-select prompt during “init from code” to choose supported protocols (defaulting to responses).
  • Added unit tests covering flag-driven and --no-prompt protocol selection behavior.

Reviewed changes

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

File Description
cli/azd/extensions/azure.ai.agents/internal/cmd/init.go Adds --protocol flag wiring into init flags.
cli/azd/extensions/azure.ai.agents/internal/cmd/init_from_code.go Prompts (or uses flags) to populate protocols when generating agent.yaml.
cli/azd/extensions/azure.ai.agents/internal/cmd/init_from_code_test.go Adds tests for protocol selection helper logic (flags + no-prompt default).

Comment on lines +859 to +861
Message: "Which protocols does your agent support?",
Choices: choices,
Hint: "Use arrow keys to move, space to toggle, enter to confirm",
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

MultiSelectOptions.Hint is currently ignored by the azd host prompt service (it doesn't map the Hint field into ux.MultiSelectOptions, and ux.MultiSelectOptions doesn't have a Hint property). This means the provided hint text will never be shown to users. Consider removing this field here, or move the guidance into HelpMessage (shown on ?) so it is actually displayed.

Suggested change
Message: "Which protocols does your agent support?",
Choices: choices,
Hint: "Use arrow keys to move, space to toggle, enter to confirm",
Message: "Which protocols does your agent support?",
Choices: choices,
HelpMessage: "Use arrow keys to move, space to toggle, enter to confirm",

Copilot uses AI. Check for mistakes.
Comment on lines +857 to +869
resp, err := azdClient.Prompt().MultiSelect(ctx, &azdext.MultiSelectRequest{
Options: &azdext.MultiSelectOptions{
Message: "Which protocols does your agent support?",
Choices: choices,
Hint: "Use arrow keys to move, space to toggle, enter to confirm",
},
})
if err != nil {
if exterrors.IsCancellation(err) {
return nil, exterrors.Cancelled("protocol selection was cancelled")
}
return nil, fmt.Errorf("failed to prompt for protocols: %w", err)
}
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

promptProtocols adds a new interactive branch (MultiSelect prompt + cancellation handling) but the new tests only cover the flag-driven and --no-prompt default paths. Add unit tests for the interactive path by stubbing the prompt service response (including cancellation and the empty-selection/validation case) to prevent regressions in the new init UX.

Copilot uses AI. Check for mistakes.
@trangevi trangevi linked an issue Apr 2, 2026 that may be closed by this pull request
Copy link
Copy Markdown
Member

@jongio jongio left a comment

Choose a reason for hiding this comment

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

Issues to address:

  • init_from_code.go:822 - --protocol responses --protocol responses produces duplicate entries in agent.yaml; needs dedup
  • init_from_code.go:877 - multi-select response values aren't validated against the known map; silent empty version on unexpected values

Comment on lines +820 to +822
if len(flagProtocols) > 0 {
records := make([]agent_yaml.ProtocolVersionRecord, 0, len(flagProtocols))
for _, name := range flagProtocols {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[MEDIUM] --protocol responses --protocol responses produces duplicate entries in agent.yaml. Cobra's StringSliceVar preserves duplicates from repeated flags and comma-separated values.

Suggested change
if len(flagProtocols) > 0 {
records := make([]agent_yaml.ProtocolVersionRecord, 0, len(flagProtocols))
for _, name := range flagProtocols {
if len(flagProtocols) > 0 {
seen := make(map[string]bool, len(flagProtocols))
records := make([]agent_yaml.ProtocolVersionRecord, 0, len(flagProtocols))
for _, name := range flagProtocols {
if seen[name] {
continue
}
seen[name] = true

if choice.Selected {
records = append(records, agent_yaml.ProtocolVersionRecord{
Protocol: choice.Value,
Version: versionOf[choice.Value],
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[LOW] versionOf[choice.Value] silently returns "" if the value isn't in the map. The choices are built from knownProtocols so this is safe today, but a defensive check would catch unexpected prompt service behavior.

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.

specify supported protocols when generating agent.yaml

4 participants