-
Notifications
You must be signed in to change notification settings - Fork 288
Fix agent init: container resource management and stale UX text #7607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,6 +67,7 @@ type InitAction struct { | |
| models *modelSelector | ||
|
|
||
| deploymentDetails []project.Deployment | ||
| containerSettings *project.ContainerSettings | ||
| httpClient *http.Client | ||
| } | ||
|
|
||
|
|
@@ -475,6 +476,23 @@ func (a *InitAction) Run(ctx context.Context) error { | |
| return fmt.Errorf("configuring model choice: %w", err) | ||
| } | ||
|
|
||
| // For hosted agents, prompt for container resources before writing agent.yaml | ||
| // so the selected values are persisted into the definition file. | ||
| if hostedAgent, ok := agentManifest.Template.(agent_yaml.ContainerAgent); ok { | ||
| containerSettings, err := a.populateContainerSettings(ctx, hostedAgent.Resources) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to populate container settings: %w", err) | ||
| } | ||
| a.containerSettings = containerSettings | ||
|
|
||
| // Update the agent definition with the selected resources | ||
| hostedAgent.Resources = &agent_yaml.ContainerResources{ | ||
trangevi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Cpu: containerSettings.Resources.Cpu, | ||
| Memory: containerSettings.Resources.Memory, | ||
| } | ||
| agentManifest.Template = hostedAgent | ||
| } | ||
|
|
||
| // Write the final agent.yaml to disk (after deployment names have been injected) | ||
| if err := writeAgentDefinitionFile(targetDir, agentManifest); err != nil { | ||
| return fmt.Errorf("writing agent definition: %w", err) | ||
|
|
@@ -1226,12 +1244,8 @@ func (a *InitAction) addToProject(ctx context.Context, targetDir string, agentMa | |
| } | ||
| } | ||
|
|
||
| // Prompt user for container settings | ||
| containerSettings, err := a.populateContainerSettings(ctx) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to populate container settings: %w", err) | ||
| } | ||
| agentConfig.Container = containerSettings | ||
| // Use container settings that were already populated before writing agent.yaml | ||
| agentConfig.Container = a.containerSettings | ||
| } | ||
|
|
||
| agentConfig.Deployments = a.deploymentDetails | ||
|
|
@@ -1282,7 +1296,10 @@ func (a *InitAction) addToProject(ctx context.Context, targetDir string, agentMa | |
| return nil | ||
| } | ||
|
|
||
| func (a *InitAction) populateContainerSettings(ctx context.Context) (*project.ContainerSettings, error) { | ||
| func (a *InitAction) populateContainerSettings( | ||
| ctx context.Context, | ||
| manifestResources *agent_yaml.ContainerResources, | ||
| ) (*project.ContainerSettings, error) { | ||
| choices := make([]*azdext.SelectChoice, len(project.ResourceTiers)) | ||
| for i, t := range project.ResourceTiers { | ||
| choices[i] = &azdext.SelectChoice{ | ||
|
|
@@ -1292,6 +1309,15 @@ func (a *InitAction) populateContainerSettings(ctx context.Context) (*project.Co | |
| } | ||
|
|
||
| defaultIndex := int32(0) | ||
| if manifestResources != nil { | ||
| for i, t := range project.ResourceTiers { | ||
| if t.Cpu == manifestResources.Cpu && t.Memory == manifestResources.Memory { | ||
| defaultIndex = int32(i) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Low] Resource tier pre-selection uses exact string equality
|
||
| break | ||
| } | ||
| } | ||
| } | ||
|
|
||
| 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.", | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.