Skip to content

fix: allow --local with a named agent in azd ai agent invoke#8771

Merged
huimiu merged 3 commits into
mainfrom
trangevi/fix-local-invoke-named-agent
Jun 23, 2026
Merged

fix: allow --local with a named agent in azd ai agent invoke#8771
huimiu merged 3 commits into
mainfrom
trangevi/fix-local-invoke-named-agent

Conversation

@trangevi

Copy link
Copy Markdown
Member

Why

In multi-agent projects, azd ai agent invoke my-agent --local "message" fails with:

cannot use --local with a named agent; named agents are always invoked remotely on Foundry

This forces users to go through the interactive picker every time, even when they already know the agent name. The downstream local code paths (responsesLocal, invocationsLocal) already accept and correctly use the agent name for session key resolution, so the validation guard was unnecessarily restrictive.

What changed

  • Removed the validation block that rejected --local combined with a positional agent name.
  • Fixed resolveProtocol() to pass a.flags.name (instead of empty string) when --local is set, so protocol auto-detection reads the correct agent's agent.yaml in multi-agent projects.
  • Added a command example showing azd ai agent invoke my-agent --local "Hello!".
  • Added TestInvokeLocalWithNamedAgent verifying the combination passes validation.

All existing tests pass.

Fixes: #7928

Remove the validation guard that rejected --local combined with a
positional agent name. The downstream local code paths (responsesLocal,
invocationsLocal) already accept and use the agent name for session key
resolution and protocol detection.

Also fix resolveProtocol to pass the agent name (instead of empty
string) when --local is set, so protocol auto-detection reads the
correct agent's agent.yaml in multi-agent projects.

Fixes #7928

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 22, 2026 23:18
@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

This PR updates the azd ai agent invoke command in the azure.ai.agents extension to allow combining --local with an explicitly named agent, which is important for multi-agent projects to avoid interactive selection and to ensure protocol detection reads the correct agent’s agent.yaml.

Changes:

  • Removed the validation that rejected --local when a positional agent name is provided.
  • Fixed protocol auto-detection for local invocation to use the provided agent name.
  • Added a CLI example and a regression test covering invoke <name> --local.

Reviewed changes

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

File Description
cli/azd/extensions/azure.ai.agents/internal/cmd/invoke.go Removes the --local+name validation guard and ensures protocol resolution uses the named agent for local invokes; adds an example for the new supported usage.
cli/azd/extensions/azure.ai.agents/internal/cmd/invoke_test.go Adds a test to verify --local with a positional agent name is not rejected during argument/flag validation.

Comment thread cli/azd/extensions/azure.ai.agents/internal/cmd/invoke.go Outdated
Comment thread cli/azd/extensions/azure.ai.agents/internal/cmd/invoke_test.go
@github-actions github-actions Bot added the ext-agents azure.ai.agents extension label Jun 22, 2026
Collapse redundant if/else branches in resolveProtocol since both
paths now call resolveAgentProtocol with identical arguments.

Improve TestInvokeLocalWithNamedAgent: assert error is returned,
discard Cobra output to keep test runs clean.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@huimiu

huimiu commented Jun 23, 2026

Copy link
Copy Markdown
Member

@copilot resolve the merge conflicts in this pull request

…voke-named-agent

# Conflicts:
#	cli/azd/extensions/azure.ai.agents/internal/cmd/invoke.go

Co-authored-by: huimiu <107838226+huimiu@users.noreply.github.com>

Copilot AI commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

Resolved the merge conflict in invoke.go by merging origin/main (commit d6e8b6d). The conflict was in resolveProtocol(): main added service-name caching to avoid a double prompt (#8770), while this PR collapsed the redundant --local/remote branches into a single resolveAgentProtocol call using a.flags.name. The resolution combines both — a single call passing a.flags.name plus main's service-name caching. Build and the azure.ai.agents extension tests pass.

@huimiu

huimiu commented Jun 23, 2026

Copy link
Copy Markdown
Member

/check-enforcer override

@huimiu huimiu enabled auto-merge (squash) June 23, 2026 10:07
@huimiu huimiu merged commit deb6ec7 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.

cannot use --local with a named agent

5 participants