diff --git a/cli/azd/extensions/azure.ai.agents/internal/cmd/init.go b/cli/azd/extensions/azure.ai.agents/internal/cmd/init.go index 9d17d200a9c..e207a88f85a 100644 --- a/cli/azd/extensions/azure.ai.agents/internal/cmd/init.go +++ b/cli/azd/extensions/azure.ai.agents/internal/cmd/init.go @@ -545,16 +545,42 @@ func (a *InitAction) configureModelChoice( } // If the manifest has no model resources, skip the model configuration prompt - // but still ensure subscription and location are set for agent creation + // but still ensure subscription and location are set for agent creation. + // When --project-id is provided, use the existing project to derive location + // and configure Foundry env vars (ACR, AppInsights, etc.) instead of prompting. if !manifestHasModelResources(agentManifest) { - newCred, err := ensureSubscriptionAndLocation( - ctx, a.azdClient, a.azureContext, a.environment.Name, - "Select an Azure subscription to provision your agent and Foundry project resources.", - ) - if err != nil { - return nil, err + if a.flags.projectResourceId != "" { + newCred, err := ensureSubscription( + ctx, a.azdClient, a.azureContext, a.environment.Name, + "Select an Azure subscription to provision your agent and Foundry project resources.", + ) + if err != nil { + return nil, err + } + a.credential = newCred + + selectedProject, err := selectFoundryProject( + ctx, a.azdClient, a.credential, a.azureContext, a.environment.Name, + a.azureContext.Scope.SubscriptionId, a.flags.projectResourceId, + ) + if err != nil { + return nil, err + } + + if selectedProject == nil { + return nil, fmt.Errorf("foundry project not found: %s", a.flags.projectResourceId) + } + } else { + newCred, err := ensureSubscriptionAndLocation( + ctx, a.azdClient, a.azureContext, a.environment.Name, + "Select an Azure subscription to provision your agent and Foundry project resources.", + ) + if err != nil { + return nil, err + } + a.credential = newCred } - a.credential = newCred + return agentManifest, nil }