Skip to content

[Agents Extension] Better handling for protocol flag#7725

Merged
trangevi merged 2 commits intomainfrom
trangevi/silent-invoke-failure
Apr 15, 2026
Merged

[Agents Extension] Better handling for protocol flag#7725
trangevi merged 2 commits intomainfrom
trangevi/silent-invoke-failure

Conversation

@trangevi
Copy link
Copy Markdown
Member

Handles silent failure due to missing protocol. Also addresses bug where multiple protocols would always use the first one if no flag was provided

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

Note

Copilot was unable to run its full agentic suite in this review.

Improves agent invocation protocol resolution by surfacing actionable errors when a protocol can’t be determined and fixing incorrect selection behavior when multiple protocols are declared.

Changes:

  • Makes resolveProtocol/resolveAgentProtocol return errors instead of silently defaulting.
  • Consolidates protocol auto-detection logic to use a single azd client path for local/remote resolution.
  • Updates unit test(s) to handle the new (protocol, error) return shape.

Reviewed changes

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

File Description
cli/azd/extensions/azure.ai.agents/internal/cmd/invoke.go Propagates protocol resolution errors and consolidates local/remote protocol detection into one flow.
cli/azd/extensions/azure.ai.agents/internal/cmd/helpers.go Changes protocol resolution to return contextual validation errors when agent.yaml can’t be read/parsed or is ambiguous.
cli/azd/extensions/azure.ai.agents/internal/cmd/invoke_test.go Updates existing test to handle the new error-returning API.

Comment thread cli/azd/extensions/azure.ai.agents/internal/cmd/helpers.go
Comment thread cli/azd/extensions/azure.ai.agents/internal/cmd/invoke.go
Comment thread cli/azd/extensions/azure.ai.agents/internal/cmd/helpers.go
Comment thread cli/azd/extensions/azure.ai.agents/internal/cmd/helpers.go
Signed-off-by: trangevi <trangevi@microsoft.com>
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.

The approach is solid - converting silent defaults to explicit exterrors.Validation errors is the right fix. Users with misconfigured agent.yaml now get clear guidance instead of mysterious wrong-protocol behavior.

The resolveLocalProtocol/resolveRemoteProtocol consolidation is clean. They only differed on the name parameter, so the single if/else on a.flags.local is simpler and correct.

Two things before this merges:

  1. The case 1 path should validate that hosted.Protocols[0].Protocol isn't empty - a protocols: [{ version: v1 }] entry (missing protocol field) returns "" with nil error, which silently falls through to responses downstream. The bot's suggestion here is valid.

  2. The five new error scenarios in resolveAgentProtocol are the core value of this PR and need test coverage. This is non-trivial since it requires mocking the azdClient, but the existing TestResolveProtocol_ExplicitFlag pattern could be extended with a test fixture that writes temp agent.yaml files.

Side note: the author's rejection of the error-wrapping suggestion on invoke.go:167 is correct. The exterrors package docs say not to wrap structured errors with fmt.Errorf, and the fmt.Errorf("failed to create azd client: %%w", err) pattern on line 205 matches 7+ other call sites in this extension.

@github-actions
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 @rajeshkamal5050 or @kristenwomack if you'd like to discuss prioritization.

@trangevi trangevi merged commit 74f125a into main Apr 15, 2026
19 checks passed
wbreza pushed a commit to wbreza/azure-dev that referenced this pull request Apr 15, 2026
* Better handling for protocol flag

Signed-off-by: trangevi <trangevi@microsoft.com>

* Pr comments

Signed-off-by: trangevi <trangevi@microsoft.com>

---------

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

invoke silently fails when not running in the directory with the agent.yaml

4 participants