Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions cli/azd/extensions/azure.ai.agents/internal/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ type InitAction struct {
models *modelSelector

deploymentDetails []project.Deployment
needsProvision bool
containerSettings *project.ContainerSettings
isCodeDeploy bool // true when user selects code deploy mode; skips ACR config
httpClient *http.Client
Expand Down Expand Up @@ -2086,10 +2087,7 @@ func (a *InitAction) addToProject(ctx context.Context, targetDir string, agentMa
"\nAdded your agent as a service entry named '%s' under the file azure.yaml.\n",
a.serviceNameOverride,
)
if projectID, _ := a.azdClient.Environment().GetValue(ctx, &azdext.GetEnvRequest{
EnvName: a.environment.Name,
Key: "AZURE_AI_PROJECT_ID",
}); projectID != nil && projectID.Value != "" && len(a.deploymentDetails) == 0 {
if a.initCompletionNeedsDeploy(ctx) {
fmt.Printf("To deploy your agent, use %s.\n",
color.HiBlueString("azd deploy %s", a.serviceNameOverride))
} else {
Expand All @@ -2101,6 +2099,21 @@ func (a *InitAction) addToProject(ctx context.Context, targetDir string, agentMa
return nil
}

// initCompletionNeedsDeploy returns true when the user only needs to run
// "azd deploy <service>" (i.e. infrastructure is already provisioned and no
// new model deployments were requested). When false, the user should run
// "azd up" to provision and deploy.
func (a *InitAction) initCompletionNeedsDeploy(ctx context.Context) bool {
if a.needsProvision {
return false
}
projectID, _ := a.azdClient.Environment().GetValue(ctx, &azdext.GetEnvRequest{
EnvName: a.environment.Name,
Key: "AZURE_AI_PROJECT_ID",
})
return projectID != nil && projectID.Value != ""
}

// resolveCollisions checks whether the auto-computed target directory or
// service name already exist. When a collision is detected, the user is
// prompted for a new name (or a numeric suffix is appended in no-prompt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ func (a *InitAction) getModelDeploymentDetails(ctx context.Context, model agent_
return nil, fmt.Errorf("failed to get model details: %w", err)
}

// This path creates a new model deployment that needs provisioning
a.needsProvision = true

message := fmt.Sprintf("Enter model deployment name for model '%s' (defaults to model name)", modelDetails.ModelName)

modelDeploymentInput, err := a.azdClient.Prompt().Prompt(ctx, &azdext.PromptRequest{
Expand Down
59 changes: 59 additions & 0 deletions cli/azd/extensions/azure.ai.agents/internal/cmd/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2282,3 +2282,62 @@ func TestDownloadAgentYaml_NoPromptManifestInSrcWithoutForce(t *testing.T) {
t.Errorf("suggestion should mention --force, got: %s", localErr.Suggestion)
}
}

func TestInitCompletionNeedsDeploy(t *testing.T) {
t.Parallel()

tests := []struct {
name string
needsProvision bool
projectID string // empty means AZURE_AI_PROJECT_ID is not set
want bool
}{
{
name: "existing project, no new deployments → deploy only",
needsProvision: false,
projectID: "/subscriptions/sub/resourceGroups/rg/providers/Microsoft.CognitiveServices/accounts/acct/projects/proj",
want: true,
},
{
name: "existing project, new model deployed → needs provision",
needsProvision: true,
projectID: "/subscriptions/sub/resourceGroups/rg/providers/Microsoft.CognitiveServices/accounts/acct/projects/proj",
want: false,
},
{
name: "no project set → needs provision",
needsProvision: false,
projectID: "",
want: false,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

envName := "test-env"
envServer := &testEnvironmentServiceServer{
values: map[string]map[string]string{},
}
if tt.projectID != "" {
envServer.values[envName] = map[string]string{
"AZURE_AI_PROJECT_ID": tt.projectID,
}
}

azdClient := newTestAzdClient(t, envServer, &testWorkflowServiceServer{})

action := &InitAction{
azdClient: azdClient,
needsProvision: tt.needsProvision,
environment: &azdext.Environment{Name: envName},
}

got := action.initCompletionNeedsDeploy(t.Context())
if got != tt.want {
t.Errorf("initCompletionNeedsDeploy() = %v, want %v", got, tt.want)
}
})
}
}
Loading