fix: avoid double agent service prompt in azd ai agent invoke#8770
Merged
Conversation
When no agent name was provided and multiple agent services existed in azure.yaml, resolveProtocol() and resolveRemoteContext() (or resolveLocalAgentKey()) each independently called resolveAgentService(), causing the user to be prompted twice to select an agent service. Fix by having resolveAgentProtocol() return the resolved service name alongside the protocol, and caching it in a.flags.name inside resolveProtocol(). Downstream calls then find a non-empty name and perform an exact lookup instead of re-prompting. Fixes #7782 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Verifies that resolveAgentProtocol returns the resolved service name alongside the protocol across multiple scenarios: single service auto-resolved, explicit name lookup, and multi-service prompt selection. Also adds a test confirming that a single resolveAgentProtocol call triggers exactly one prompt when multiple services exist. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
📋 Prioritization NoteThanks for the contribution! The linked issue isn't in the current milestone yet. |
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a UX bug in the azd ai agent invoke flow where projects with multiple agent services could prompt the user twice by re-resolving the agent service independently during protocol auto-detection and context resolution.
Changes:
- Updated
resolveAgentProtocolto return both the detected protocol and the resolved azure.yaml service name. - Cached the resolved service name in
InvokeAction.resolveProtocolso downstream resolution uses an exact lookup instead of prompting again. - Added unit tests covering service-name return behavior and verifying only one prompt occurs per
resolveAgentProtocolcall.
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/invoke.go | Caches the resolved service name during protocol auto-detection to prevent a second service-selection prompt downstream. |
| cli/azd/extensions/azure.ai.agents/internal/cmd/helpers.go | Extends resolveAgentProtocol to return the resolved service name alongside the protocol. |
| cli/azd/extensions/azure.ai.agents/internal/cmd/helpers_test.go | Adds gRPC-backed stubs and new tests validating service-name return and prompt behavior. |
Use sync/atomic.Int32 for helpersPromptServer.selectCalls to prevent data races between the gRPC handler goroutine and test goroutine. Close the listener in t.Cleanup alongside grpcServer.Stop() to avoid leaking file descriptors in parallel test runs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
huimiu
approved these changes
Jun 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When running
azd ai agent invoke hellowith multiple agent services defined inazure.yaml, the user is prompted to select an agent service twice.The root cause is that the invoke flow calls
resolveAgentService()independently in two places:resolveProtocol()-- to auto-detect the protocol fromagent.yamlresolveRemoteContext()(orresolveLocalAgentKey()for--local) -- to resolve the agent name and endpointEach call sees an empty name and multiple services, so each triggers an interactive prompt.
Approach
resolveAgentProtocol()inhelpers.goto return the resolved service name as a second return value alongside the protocol. This is a minimal signature change; the function already had the service info in hand but was discarding it.resolveProtocol()ininvoke.goto cache the returned service name intoa.flags.namewhen the name was not already set. Downstream calls (resolveRemoteContext,resolveLocalAgentKey) then find a non-empty name and perform an exact lookup instead of re-prompting.Tests
Added two new test functions in
helpers_test.go:TestResolveAgentProtocol_ReturnsServiceName-- table-driven test covering single-service auto-resolve, explicit name, and multi-service prompt selection (first and second choice)TestResolveAgentProtocol_MultipleServicesPromptsOnce-- asserts exactly one prompt call occurs when multiple services exist and no name is providedFixes: #7782