Skip to content

feat(ai-agents): add --inspector-port flag to azd ai agent run - #9366

Open
glharper wants to merge 2 commits into
mainfrom
glharper/9222-inspector-port
Open

feat(ai-agents): add --inspector-port flag to azd ai agent run#9366
glharper wants to merge 2 commits into
mainfrom
glharper/9222-inspector-port

Conversation

@glharper

Copy link
Copy Markdown
Member

Summary

  • add an --inspector-port flag to azd ai agent run and forward it to ai inspector launch
  • forward the flag only when set, so the azure.ai.inspector extension stays the source of truth for the default UI port (8087) and existing behavior is unchanged
  • reject out-of-range values instead of silently ignoring them
  • document the flag in the extension README

Unblocks running two agents side by side: each agent already gets its own --port, but both Inspectors previously tried to bind 8087.

azd ai agent run --port 9091 --inspector-port 9002
# forwards: ai inspector launch --port 9091 --inspector-port 9002 --silent

The optional auto-increment-on-conflict idea from the issue is not included; that behavior belongs to the inspector extension, which owns the bind.

Testing

  • go test ./internal/cmd -count=1
  • go build ./...
  • golangci-lint run ./internal/cmd/...
  • cspell lint internal/cmd/run.go internal/cmd/run_test.go

New coverage: --inspector-port is omitted when unset and forwarded when set, the flag is registered with the documented default, and out-of-range values are rejected.

No TestFigSpec snapshot update: that snapshot installs published extension artifacts from registry.json, so it picks this flag up on the next azure.ai.agents release.

Fixes #9222

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: fed9e97b-e79b-4889-ac76-0d9a428599cd
Copilot AI review requested due to automatic review settings July 30, 2026 14:39
@github-actions

Copy link
Copy Markdown

📋 Prioritization Note

Thanks for the contribution! The linked issue isn't in the current milestone yet.
Thank you for logging this issue; our team is reviewing it. If you need urgent prioritization, tag @RickWinter and @kristenwomack to let us know.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
21 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

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

Adds configurable Agent Inspector UI ports to support concurrent local agents.

Changes:

  • Adds and validates --inspector-port.
  • Forwards explicitly configured ports to Agent Inspector.
  • Documents and tests the new flag.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
README.md Documents custom Inspector ports.
internal/cmd/run.go Registers, validates, and forwards the flag.
internal/cmd/run_test.go Tests registration, validation, and forwarding.

// port. Validating here keeps an invalid value from being silently dropped or
// failing later inside the inspector with a less obvious message.
func validateInspectorPort(inspectorPort int) error {
if inspectorPort == 0 || (inspectorPort >= 1 && inspectorPort <= 65535) {

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.

Fixed in edcea33: runFlags now records inspectorPortSet from cmd.Flags().Changed("inspector-port"), and validateInspectorPort only allows zero when the flag was not supplied — an explicit --inspector-port 0 is now rejected. Added a test case for it.

@github-actions github-actions Bot added the ext-agents azure.ai.agents extension label Jul 30, 2026
Co-authored-by: glharper <64209257+glharper@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 30, 2026 18:50

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

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

@jongio jongio left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two optional hardening ideas inline, both about --inspector-port values that pass validation but still don't reach the inspector. Neither blocks.

LOW

  • --inspector-port is accepted and then dropped when the local client is suppressed, and when the project is an activity agent
  • --inspector-port equal to --port clears validation and fails later at bind time

}

func runRun(ctx context.Context, flags *runFlags, noPrompt bool) error {
if err := validateInspectorPort(flags.inspectorPort, flags.inspectorPortSet); err != nil {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

validateInspectorPort runs before we know whether the inspector will launch at all, so two paths accept --inspector-port and then drop it:

  • --no-client (or the deprecated --no-inspector) makes handleInspectorAutoLaunch return early, so the port never reaches the workflow.
  • Activity agent projects take the handlePlaygroundAutoLaunch branch instead, which has no inspector port at all.

The doc comment on validateInspectorPort says the reason to validate here is to stop a value from being silently dropped, so the suppressed-client case looks like it deserves the same treatment. init.go already uses exterrors.CodeConflictingArguments with cmd.Flags().Changed(...) for this shape of conflict.

The activity agent case is murkier, since the user can't always predict which branch they'll land on, so a stderr warning may fit better there than a hard error.

// Validating here keeps an invalid value from being silently dropped or failing
// later inside the inspector with a less obvious message.
func validateInspectorPort(inspectorPort int, set bool) error {
if !set || (inspectorPort >= 1 && inspectorPort <= 65535) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider rejecting inspectorPort == agentPort too. azd ai agent run --port 9091 --inspector-port 9091 gets through this check, then the agent binds 127.0.0.1:9091 and the inspector tries to bind the same address and fails. That's the collision this flag exists to prevent, and catching it up front gives the same clearer-error benefit this doc comment describes.

Passing the agent port into this function would change the signature the new tests use, so a separate check in runRun next to the existing call may be the smaller change.

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.

Add --inspector-port flag to azd ai agent run

4 participants