Skip to content

[feat] optimzie progressive update + adapt to new azure.yaml - #9003

Merged
trangevi merged 3 commits into
Azure:mainfrom
Zyysurely:zyying/optimize_progressive_update
Jul 7, 2026
Merged

[feat] optimzie progressive update + adapt to new azure.yaml#9003
trangevi merged 3 commits into
Azure:mainfrom
Zyysurely:zyying/optimize_progressive_update

Conversation

@Zyysurely

@Zyysurely Zyysurely commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Optimize: progressive polling UX, azure.yaml agent detection, and --output json for status

Summary

Improves the azd ai agent optimize polling experience with live-updating candidate rows and phase-aware progress indicators, migrates agent kind detection to the new azure.yaml inline/config agent definition format, and adds --output json support to optimize status.

Changes

Agent detection from azure.yaml (eval.go, optimize.go)

  • Replaced detectEvalAgentKind with projectpkg.LoadAgentDefinition, which supports the latest azure.yaml agent definition shapes:
    • Inline: agent kind defined directly in azure.yaml service config
    • Config reference: agent kind referenced via config pointer in azure.yaml
    • Legacy disk: standalone agent.yaml file on disk
  • The agent kind source is now accurately reported (azure.yaml (inline), azure.yaml (config), agent.yaml) instead of just showing the file path.
  • Emits a deprecation warning via WarnLegacyAgentShape when legacy config shapes are detected.
  • Removed now-unused detectEvalAgentKind and relPathForYaml functions and their tests.

Optimize agent resolution refactor (optimize.go)

  • Resolution order fixed: resolveOptimizeAgent now tries the azd project context first (passing --agent as a service name to resolveAgentService), then falls back to treating --agent as a raw Foundry agent name. Previously, a non-empty --agent flag would skip project resolution entirely.
  • The --agent flag now also reads the agent version from the environment (via AGENT_{KEY}_VERSION), enabling version-aware optimization.
  • Updated flag help text to clarify: "Agent service name from azure.yaml, or Foundry agent name outside a project".
  • Same resolution fix applied to optimize apply and optimize deploy flag descriptions.

Progressive polling UX (optimize.go, optimize_helpers.go)

  • Live candidate table: Completed candidates are printed as individual table rows as they finish, instead of waiting for the entire job to complete.
  • Phase-aware status line: The spinner distinguishes "Generating" vs "Evaluating" using the new InProgressCandidate.CandidateGenerated field.
  • Candidate progress counter: Shows Generating candidate 2/5 (from MaxCandidates) or Generating candidate 2 when max is unknown.
  • Server-side elapsed time: Uses InProgressCandidate.CreatedAt (server timestamp) instead of a locally-tracked timer.
  • Extracted table rendering helpers: candidateDisplayName, candidateTableHeader, formatCandidateRow, writeCandidateRow are now shared helpers, eliminating duplicated rendering between polling and final results.

optimize status --output json (optimize_status.go)

  • Adds --output flag (json | table, default table) via azdext.RegisterFlagOptions.
  • --output json: prints the full OptimizeJobStatus as indented JSON.
  • --output json --watch: suppresses table output during polling, prints final status as JSON.
  • Informational "Using last job: ..." line suppressed in JSON mode.

API model updates (optimize_api/models.go)

  • Added InProgressCandidate struct with CreatedAt and CandidateGenerated fields.
  • Added InProgressCandidate field to JobProgress.

Tests

  • optimize_status_test.go: --output flag registration, default poll interval, printOptimizeStatusJSON, job summary duration display (present/missing/equal timestamps).
  • optimize_helpers_test.go: candidateDisplayName, candidateTableHeader, formatCandidateRow (empty/non-empty eval & strategy, hidden columns).
  • optimize_test.go: TestPrintOptimizeResults_StrategyDashForMixedMutations.
  • Removed TestDetectEvalAgentKind, TestRelPathForYaml (functions deleted).
  • Renamed TestOptimizeDeployCommand_AgentResolvedFromFlagOrYaml…FromFlagOrProject.

Copilot AI review requested due to automatic review settings July 6, 2026 21:46
@github-actions github-actions Bot added the ext-agents azure.ai.agents extension label Jul 6, 2026

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 polishes the azd ai agent optimize command's live progress experience and adapts the eval/optimize commands to the newer azure.yaml inline agent-definition model. During polling it now renders a live-updating candidate results table (completed rows appended in place, with an overwritten in-progress status line) instead of a single spinner line, and it replaces the removed on-disk agent.yaml detection in eval with the shared projectpkg.LoadAgentDefinition, which understands inline, legacy-config, and disk sources.

Changes:

  • Progressive polling UI: extracted shared table helpers (candidateTableHeader, formatCandidateRow, candidateDisplayName, writeCandidateRow), added a live candidate table with server-timestamp-based "Total time"/"Duration" output, softened the pre-run warning to a "Note", and bumped the default --poll-interval from 5s to 10s.
  • azure.yaml adaptation: eval now resolves agent kind via LoadAgentDefinition (with legacy-shape warnings) and drops the local detectEvalAgentKind/relPathForYaml helpers; --agent help text is aligned across optimize/deploy/apply/eval to describe service-name vs Foundry-name semantics.
  • Model additions: JobProgress.BaselineScore and a new InProgressCandidate (CreatedAt, CandidateGenerated) type for richer server progress reporting.

Reviewed changes

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

Show a summary per file
File Description
internal/pkg/agents/optimize_api/models.go Adds BaselineScore and InProgressCandidate to job progress payload.
internal/cmd/optimize.go Live candidate table rendering during polling; softened warning; --poll-interval default 10; total-time output.
internal/cmd/optimize_helpers.go New shared candidate-table rendering helpers; removes loadLastOptimizeJobID.
internal/cmd/optimize_status.go Uses loadOptimizeJobIDForAgent; adds Updated/Duration to summary; poll default 10.
internal/cmd/optimize_deploy.go / optimize_apply.go --agent help text and comments updated for azure.yaml semantics.
internal/cmd/eval.go Replaces on-disk kind detection with LoadAgentDefinition; removes now-unused helpers.
internal/cmd/eval_generate.go --agent help text updated.
*_test.go (optimize, status, helpers, deploy, eval) Updates poll-interval assertions, adds table-helper and summary-duration tests, removes tests for deleted helpers.

Comment thread cli/azd/extensions/azure.ai.agents/internal/cmd/optimize.go Outdated

@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.

Clean refactoring that consolidates agent kind detection into the shared LoadAgentDefinition utility and improves the optimize polling UX with a live-updating candidate table.

Key things I verified:

  • loadOptimizeJobIDForAgent("", envName) correctly falls back to the global OPTIMIZE_LAST_OPERATION_ID key, matching the removed loadLastOptimizeJobID behavior.
  • The resolveOptimizeAgent reordering (project-first, flag-as-Foundry-name fallback) is consistent with other commands and preserves backwards compatibility for users specifying a Foundry name directly.
  • New table rendering helpers are well-tested and the extraction from the inline loop is a good separation of concerns.

One optional suggestion inline.

Comment thread cli/azd/extensions/azure.ai.agents/internal/cmd/optimize.go

@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.

Incremental review of the new commit (1760b79, "support -o").

The JSON output support and the improved progress status line both look solid. One logic gap in the terminal-job path when --watch is combined with --output json.

Comment thread cli/azd/extensions/azure.ai.agents/internal/cmd/optimize_status.go

@trangevi trangevi 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.

This looks good overall — just a couple of comments.

Comment thread cli/azd/extensions/azure.ai.agents/internal/cmd/optimize.go
Comment thread cli/azd/extensions/azure.ai.agents/internal/cmd/optimize_test.go
@trangevi
trangevi enabled auto-merge (squash) July 7, 2026 18:16
@trangevi
trangevi merged commit c8092c5 into Azure:main Jul 7, 2026
26 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.

azd ai agent optimize progressive update + adapting to new inline azure.yaml

5 participants