[Agents extension] Prompt user for protocols during "from code" flow#7464
[Agents extension] Prompt user for protocols during "from code" flow#7464
Conversation
Signed-off-by: trangevi <trangevi@microsoft.com>
There was a problem hiding this comment.
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
--protocolflag 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-promptprotocol 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). |
| Message: "Which protocols does your agent support?", | ||
| Choices: choices, | ||
| Hint: "Use arrow keys to move, space to toggle, enter to confirm", |
There was a problem hiding this comment.
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.
| 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", |
| 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) | ||
| } |
There was a problem hiding this comment.
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.
jongio
left a comment
There was a problem hiding this comment.
Issues to address:
- init_from_code.go:822 -
--protocol responses --protocol responsesproduces 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
| if len(flagProtocols) > 0 { | ||
| records := make([]agent_yaml.ProtocolVersionRecord, 0, len(flagProtocols)) | ||
| for _, name := range flagProtocols { |
There was a problem hiding this comment.
[MEDIUM] --protocol responses --protocol responses produces duplicate entries in agent.yaml. Cobra's StringSliceVar preserves duplicates from repeated flags and comma-separated values.
| 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], |
There was a problem hiding this comment.
[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.
When using local code, prompt the user as to what kind of protocol they want to use.