-
Notifications
You must be signed in to change notification settings - Fork 27
Create agent llm-provider configuration when creating the agent #605
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
6ab7c78
b09a0d9
0ee0afe
b9b48a5
4613a8e
bc69109
527d4e5
bf07b7d
ca48028
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 |
|---|---|---|
|
|
@@ -668,6 +668,20 @@ func (s *agentManagerService) CreateAgent(ctx context.Context, orgName string, p | |
| } | ||
| } | ||
|
|
||
| // Create LLM configurations (applies to both internal and external agents) | ||
| if len(req.ModelConfig) > 0 { | ||
| if err := s.createAgentLLMConfigs(ctx, orgName, projectName, req); err != nil { | ||
| s.logger.Error("Failed to create LLM configurations for agent", "agentName", req.Name, "error", err) | ||
| if hasSecrets { | ||
| s.cleanupSecretsOnRollback(ctx, secretLocation) | ||
| } | ||
| if errDeletion := s.ocClient.DeleteComponent(ctx, orgName, projectName, req.Name); errDeletion != nil { | ||
| s.logger.Error("Failed to rollback agent after LLM config failure", "agentName", req.Name, "error", errDeletion) | ||
| } | ||
| return err | ||
| } | ||
|
Comment on lines
+671
to
+682
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. Roll back created LLM configs on every failure path. Once |
||
| } | ||
|
|
||
| // For internal agents, enable instrumentation (if enabled) and trigger initial build | ||
| if req.Provisioning.Type == string(utils.InternalAgent) { | ||
| s.logger.Debug("Component created successfully", "agentName", req.Name) | ||
|
|
@@ -744,6 +758,62 @@ func (s *agentManagerService) triggerInitialBuild(ctx context.Context, orgName, | |
| return nil | ||
| } | ||
|
|
||
| func (s *agentManagerService) createAgentLLMConfigs( | ||
| ctx context.Context, orgName, projectName string, req *spec.CreateAgentRequest, | ||
| ) error { | ||
| for i, mc := range req.ModelConfig { | ||
| configName := fmt.Sprintf("%s-llm-config", req.Name) | ||
| if len(req.ModelConfig) > 1 { | ||
| configName = fmt.Sprintf("%s-llm-config-%d", req.Name, i+1) | ||
| } | ||
| createReq := models.CreateAgentModelConfigRequest{ | ||
| Name: configName, | ||
| Type: "llm", | ||
| EnvMappings: convertEnvMappings(mc.EnvMappings), | ||
| EnvironmentVariables: convertEnvVars(mc.EnvironmentVariables), | ||
| } | ||
| if _, err := s.agentConfigurationService.Create(ctx, orgName, projectName, req.Name, createReq, "system"); err != nil { | ||
| return fmt.Errorf("failed to create LLM configuration %d: %w", i+1, err) | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func convertEnvMappings(specMappings map[string]spec.EnvModelConfigRequest) map[string]models.EnvModelConfigRequest { | ||
| result := make(map[string]models.EnvModelConfigRequest, len(specMappings)) | ||
| for env, m := range specMappings { | ||
| policies := make([]models.LLMPolicy, 0, len(m.Configuration.Policies)) | ||
| for _, p := range m.Configuration.Policies { | ||
| paths := make([]models.LLMPolicyPath, 0, len(p.Paths)) | ||
| for _, pp := range p.Paths { | ||
| paths = append(paths, models.LLMPolicyPath{ | ||
| Path: pp.Path, | ||
| Methods: pp.Methods, | ||
| Params: pp.Params, | ||
| }) | ||
| } | ||
| policies = append(policies, models.LLMPolicy{ | ||
| Name: p.Name, | ||
| Version: p.Version, | ||
| Paths: paths, | ||
| }) | ||
| } | ||
| result[env] = models.EnvModelConfigRequest{ | ||
| ProviderName: m.ProviderName, | ||
| Configuration: models.EnvProviderConfiguration{Policies: policies}, | ||
| } | ||
| } | ||
| return result | ||
| } | ||
|
|
||
| func convertEnvVars(specVars []spec.EnvironmentVariableConfig) []models.EnvironmentVariableConfig { | ||
| result := make([]models.EnvironmentVariableConfig, 0, len(specVars)) | ||
| for _, v := range specVars { | ||
| result = append(result, models.EnvironmentVariableConfig{Name: v.Name, Key: v.Key}) | ||
| } | ||
| return result | ||
| } | ||
|
|
||
| // toCreateAgentRequestWithSecrets creates a component request, handling secrets by using secretKeyRef | ||
| func (s *agentManagerService) toCreateAgentRequestWithSecrets(req *spec.CreateAgentRequest) client.CreateComponentRequest { | ||
| result := client.CreateComponentRequest{ | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep
environmentVariablesvalidation docs consistent with the standalone model-config API.uniqueItems: trueonly rejects identical{key, name}objects. The existingCreateAgentModelConfigRequest.environmentVariablesdocs already say duplicate keys are rejected with400, but that rule is omitted here, so the same field shape now has two different documented contracts.📝 Suggested doc fix
environmentVariables: type: array - description: Optional custom environment variable names exposed to the agent + description: Optional custom environment variable names exposed to the agent. Duplicate keys are rejected with 400. uniqueItems: true items: $ref: "#/components/schemas/EnvironmentVariableConfig"🤖 Prompt for AI Agents