Skip to content

fix: avoid double agent service prompt in azd ai agent invoke#8770

Merged
huimiu merged 3 commits into
mainfrom
trangevi/fix-invoke-double-agent-service-prompt
Jun 23, 2026
Merged

fix: avoid double agent service prompt in azd ai agent invoke#8770
huimiu merged 3 commits into
mainfrom
trangevi/fix-invoke-double-agent-service-prompt

Conversation

@trangevi

Copy link
Copy Markdown
Member

Problem

When running azd ai agent invoke hello with multiple agent services defined in azure.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:

  1. resolveProtocol() -- to auto-detect the protocol from agent.yaml
  2. resolveRemoteContext() (or resolveLocalAgentKey() for --local) -- to resolve the agent name and endpoint

Each call sees an empty name and multiple services, so each triggers an interactive prompt.

Approach

  • Modified resolveAgentProtocol() in helpers.go to 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.
  • Updated resolveProtocol() in invoke.go to cache the returned service name into a.flags.name when 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 provided

Fixes: #7782

trangevi and others added 2 commits June 22, 2026 15:57
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>
Copilot AI review requested due to automatic review settings June 22, 2026 23:07
@github-actions

github-actions Bot commented Jun 22, 2026

Copy link
Copy Markdown

📋 Prioritization Note

Thanks for the contribution! The linked issue isn't in the current milestone yet.
Review may take a bit longer — reach out to @RickWinter or @kristenwomack if you'd like to discuss prioritization.

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

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 resolveAgentProtocol to return both the detected protocol and the resolved azure.yaml service name.
  • Cached the resolved service name in InvokeAction.resolveProtocol so 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 resolveAgentProtocol call.

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.

Comment thread cli/azd/extensions/azure.ai.agents/internal/cmd/helpers_test.go
Comment thread cli/azd/extensions/azure.ai.agents/internal/cmd/helpers_test.go
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 huimiu merged commit 17727ff into main Jun 23, 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.

[Bug] [azd ai agent] "azd ai agent invoke" asks for agent service twice

3 participants