feat(ai-agents): add --inspector-port flag to azd ai agent run - #9366
feat(ai-agents): add --inspector-port flag to azd ai agent run#9366glharper wants to merge 2 commits into
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: fed9e97b-e79b-4889-ac76-0d9a428599cd
📋 Prioritization NoteThanks for the contribution! The linked issue isn't in the current milestone yet. |
|
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. |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
Co-authored-by: glharper <64209257+glharper@users.noreply.github.com>
jongio
left a comment
There was a problem hiding this comment.
Two optional hardening ideas inline, both about --inspector-port values that pass validation but still don't reach the inspector. Neither blocks.
LOW
--inspector-portis accepted and then dropped when the local client is suppressed, and when the project is an activity agent--inspector-portequal to--portclears 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 { |
There was a problem hiding this comment.
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) makeshandleInspectorAutoLaunchreturn early, so the port never reaches the workflow.- Activity agent projects take the
handlePlaygroundAutoLaunchbranch 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) { |
There was a problem hiding this comment.
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.
Summary
--inspector-portflag toazd ai agent runand forward it toai inspector launchazure.ai.inspectorextension stays the source of truth for the default UI port (8087) and existing behavior is unchangedUnblocks 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 --silentThe 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=1go build ./...golangci-lint run ./internal/cmd/...cspell lint internal/cmd/run.go internal/cmd/run_test.goNew coverage:
--inspector-portis omitted when unset and forwarded when set, the flag is registered with the documented default, and out-of-range values are rejected.No
TestFigSpecsnapshot update: that snapshot installs published extension artifacts fromregistry.json, so it picks this flag up on the nextazure.ai.agentsrelease.Fixes #9222