Skip to content
Merged
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
95 changes: 18 additions & 77 deletions cli/azd/extensions/azure.ai.agents/internal/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"os"
"path/filepath"
"regexp"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -1485,94 +1484,36 @@ func (a *InitAction) addToProject(ctx context.Context, targetDir string, agentMa
}

func (a *InitAction) populateContainerSettings(ctx context.Context) (*project.ContainerSettings, error) {
if a.flags.NoPrompt {
fmt.Printf("No prompt mode enabled, using default container settings\n")
return &project.ContainerSettings{
Resources: &project.ResourceSettings{
Memory: project.DefaultMemory,
Cpu: project.DefaultCpu,
},
Scale: &project.ScaleSettings{
MinReplicas: project.DefaultMinReplicas,
MaxReplicas: project.DefaultMaxReplicas,
},
}, nil
}

// Default values
defaultMemory := project.DefaultMemory
defaultCpu := project.DefaultCpu
defaultMinReplicas := fmt.Sprintf("%d", project.DefaultMinReplicas)
defaultMaxReplicas := fmt.Sprintf("%d", project.DefaultMaxReplicas)

// Prompt for memory allocation
memoryResp, err := a.azdClient.Prompt().Prompt(ctx, &azdext.PromptRequest{
Options: &azdext.PromptOptions{
Message: "Enter desired container memory allocation (e.g., '1Gi', '512Mi')",
DefaultValue: defaultMemory,
},
})
if err != nil {
return nil, fmt.Errorf("prompting for memory allocation: %w", err)
}

// Prompt for CPU allocation
cpuResp, err := a.azdClient.Prompt().Prompt(ctx, &azdext.PromptRequest{
Options: &azdext.PromptOptions{
Message: "Enter desired container CPU allocation (e.g., '1', '500m')",
DefaultValue: defaultCpu,
},
})
if err != nil {
return nil, fmt.Errorf("prompting for CPU allocation: %w", err)
}

// Prompt for minimum replicas
minReplicasResp, err := a.azdClient.Prompt().Prompt(ctx, &azdext.PromptRequest{
Options: &azdext.PromptOptions{
Message: "Enter desired container minimum number of replicas",
DefaultValue: defaultMinReplicas,
},
})
if err != nil {
return nil, fmt.Errorf("prompting for minimum replicas: %w", err)
choices := make([]*azdext.SelectChoice, len(project.ResourceTiers))
for i, t := range project.ResourceTiers {
choices[i] = &azdext.SelectChoice{
Label: t.String(),
Value: fmt.Sprintf("%d", i),
}
}

// Prompt for maximum replicas
maxReplicasResp, err := a.azdClient.Prompt().Prompt(ctx, &azdext.PromptRequest{
Options: &azdext.PromptOptions{
Message: "Enter desired container maximum number of replicas",
DefaultValue: defaultMaxReplicas,
defaultIndex := int32(0)
resp, err := a.azdClient.Prompt().Select(ctx, &azdext.SelectRequest{
Options: &azdext.SelectOptions{
Message: "Select container resource allocation (CPU and Memory) for your agent. You can adjust these settings later in the azure.yaml file if needed.",
Choices: choices,
SelectedIndex: &defaultIndex,
},
})
Comment thread
trangevi marked this conversation as resolved.
if err != nil {
return nil, fmt.Errorf("prompting for maximum replicas: %w", err)
return nil, fmt.Errorf("prompting for container resources: %w", err)
}

// Convert string values to appropriate types
minReplicas, err := strconv.Atoi(minReplicasResp.Value)
if err != nil {
return nil, fmt.Errorf("invalid minimum replicas value: %w", err)
}

maxReplicas, err := strconv.Atoi(maxReplicasResp.Value)
if err != nil {
return nil, fmt.Errorf("invalid maximum replicas value: %w", err)
}

// Validate that max replicas >= min replicas
if maxReplicas < minReplicas {
return nil, fmt.Errorf("maximum replicas (%d) must be greater than or equal to minimum replicas (%d)", maxReplicas, minReplicas)
}
selected := project.ResourceTiers[*resp.Value]

return &project.ContainerSettings{
Resources: &project.ResourceSettings{
Memory: memoryResp.Value,
Cpu: cpuResp.Value,
Memory: selected.Memory,
Cpu: selected.Cpu,
},
Scale: &project.ScaleSettings{
MinReplicas: minReplicas,
MaxReplicas: maxReplicas,
MinReplicas: project.DefaultMinReplicas,
MaxReplicas: project.DefaultMaxReplicas,
},
Comment thread
trangevi marked this conversation as resolved.
}, nil
}
Expand Down
23 changes: 23 additions & 0 deletions cli/azd/extensions/azure.ai.agents/internal/project/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,29 @@ const (
DefaultMaxReplicas = 1
)

// ResourceTier defines a preset CPU and memory allocation for container resources.
type ResourceTier struct {
Cpu string
Memory string
}

// String returns a human-readable label for the resource tier.
func (t ResourceTier) String() string {
coreUnit := "cores"
if t.Cpu == "1" {
coreUnit = "core"
}
return fmt.Sprintf("%s %s, %s memory", t.Cpu, coreUnit, t.Memory)
}

// ResourceTiers defines the available container resource allocation options.
var ResourceTiers = []ResourceTier{
{Cpu: DefaultCpu, Memory: DefaultMemory},
{Cpu: "0.5", Memory: "1Gi"},
{Cpu: "1", Memory: "2Gi"},
{Cpu: "2", Memory: "4Gi"},
}

// ServiceTargetAgentConfig provides custom configuration for the Azure AI Service target
type ServiceTargetAgentConfig struct {
Environment map[string]string `json:"env,omitempty"`
Expand Down
Loading