Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

fix(agent): save incomplete aggregation groups and gate Run (#21374)

Sbaaoui Idrissb5b5188e5271
diff --git a/internal/agent/component/dynamic_params.go b/internal/agent/component/dynamic_params.go
index dc27d7edf4..0d8d550d58 100644
--- a/internal/agent/component/dynamic_params.go
+++ b/internal/agent/component/dynamic_params.go
@@ -22,7 +22,7 @@ func ValidateDynamicEntries(dsl map[string]any) error {
// ValidateDraftDynamicEntries allows unfinished Message content, DataOperations
// entries, Invoke mappings, Compiler configuration, input options, Loop settings,
// Iteration outputs, SQL connections, search filters, chunker delimiters, and Agent
-// tool entries in saved drafts.
+// tool entries and aggregation groups in saved drafts.
// All other checks remain unchanged.
func ValidateDraftDynamicEntries(dsl map[string]any) error {
return validateDynamicEntries(dsl, true)
@@ -105,7 +105,7 @@ func validateDynamicParams(component string, params map[string]any, draft bool)
case "iteration", "parallel":
return validateIterationOutputs(component, params, draft)
case "variableaggregator":
- return validateVariableAggregatorGroups(component, params)
+ return validateVariableAggregatorGroups(component, params, draft)
case "userfillup":
return runtime.ValidateUserFillUpOptions(params, draft)
case "exesql":
@@ -225,25 +225,56 @@ func invokeRowHasSource(row map[string]any) bool {
return value != nil && !isBlank(value)
}
-func validateVariableAggregatorGroups(component string, params map[string]any) error {
- if groups, ok := params["groups"].([]any); ok {
- for i, rawGroup := range groups {
- group, ok := rawGroup.(map[string]any)
- if !ok || group == nil {
- return fmt.Errorf("[%s] groups[%d] is incomplete", component, i)
- }
- if !isNonBlankString(group["group_name"]) {
- return fmt.Errorf("[%s] groups[%d] is incomplete", component, i)
+func validateVariableAggregatorGroups(component string, params map[string]any, draft bool) error {
+ var p variableAggregatorParam
+ if err := p.Update(params); err != nil {
+ return fmt.Errorf("[%s] %w", component, err)
+ }
+ if !draft && len(p.Groups) == 0 {
+ return fmt.Errorf("[%s] groups is incomplete", component)
+ }
+ for i, group := range p.Groups {
+ if !draft && !isNonBlankString(group["group_name"]) {
+ return fmt.Errorf("[%s] groups[%d] is incomplete", component, i)
+ }
+ raw, exists := group["variables"]
+ if !exists {
+ if draft {
+ continue
}
- variables, ok := group["variables"].([]any)
- if !ok {
- return fmt.Errorf("[%s] groups[%d].variables is incomplete", component, i)
+ return fmt.Errorf("[%s] groups[%d].variables is incomplete", component, i)
+ }
+ var variables []any
+ switch v := raw.(type) {
+ case []any:
+ variables = v
+ case []map[string]any:
+ for _, entry := range v {
+ variables = append(variables, entry)
}
- for j, rawVariable := range variables {
- variable, ok := rawVariable.(map[string]any)
- if !ok || variable == nil || !isNonBlankString(variable["value"]) {
- return fmt.Errorf("[%s] groups[%d].variables[%d] is incomplete", component, i, j)
+ default:
+ return fmt.Errorf("[%s] groups[%d].variables must be a list", component, i)
+ }
+ if !draft && len(variables) == 0 {
+ return fmt.Errorf("[%s] groups[%d].variables is incomplete", component, i)
+ }
+ for j, raw := range variables {
+ switch v := raw.(type) {
+ case string:
+ case map[string]any:
+ if v == nil {
+ return fmt.Errorf("[%s] groups[%d].variables[%d] must be a selector", component, i, j)
}
+ if value, exists := v["value"]; exists {
+ if _, ok := value.(string); !ok {
+ return fmt.Errorf("[%s] groups[%d].variables[%d].value must be a string", component, i, j)
+ }
+ }
+ default:
+ return fmt.Errorf("[%s] groups[%d].variables[%d] must be a selector", component, i, j)
+ }
+ if !draft && normalizeSelectorRef(raw) == "" {
+ return fmt.Errorf("[%s] groups[%d].variables[%d] is incomplete", component, i, j)
}
}
}
diff --git a/internal/agent/component/dynamic_params_test.go b/internal/agent/component/dynamic_params_test.go
index f6f77352f0..6a39111690 100644
--- a/internal/agent/component/dynamic_params_test.go
+++ b/internal/agent/component/dynamic_params_test.go
@@ -101,7 +101,7 @@ func TestValidateDynamicEntries(t *testing.T) {
case "invoke variable row not a map", "invoke variable nil row", "invoke variable with numeric key", "invoke variables not an array", "invoke variables object":
invokeDraft = false
}
- if test.component["component_name"] == "Message" || test.component["component_name"] == "Agent" || test.component["component_name"] == "DataOperations" || test.component["component_name"] == "Compiler" || test.component["component_name"] == "Loop" || test.component["component_name"] == "Iteration" || test.component["component_name"] == "TokenChunker" || invokeDraft || test.name == "input option" {
+ if test.component["component_name"] == "Message" || test.component["component_name"] == "Agent" || test.component["component_name"] == "DataOperations" || test.component["component_name"] == "Compiler" || test.component["component_name"] == "Loop" || test.component["component_name"] == "Iteration" || test.component["component_name"] == "TokenChunker" || invokeDraft || test.name == "input option" || test.name == "aggregated variable" {
if draftErr != nil {
t.Fatalf("draft rejected unfinished entries: %v", draftErr)
}
diff --git a/internal/agent/component/variable_aggregator.go b/internal/agent/component/variable_aggregator.go
index ce9278d508..dfe8ea62f1 100644
--- a/internal/agent/component/variable_aggregator.go
+++ b/internal/agent/component/variable_aggregator.go
@@ -79,7 +79,7 @@ func (p *variableAggregatorParam) Update(conf map[string]any) error {
out := make([]map[string]any, 0, len(groupsList))
for i, raw := range groupsList {
g, ok := raw.(map[string]any)
- if !ok {
+ if !ok || g == nil {
return &ParamError{Field: fmt.Sprintf("groups[%d]", i), Reason: "must be a map"}
}
out = append(out, g)
@@ -90,26 +90,7 @@ func (p *variableAggregatorParam) Update(conf map[string]any) error {
// Check performs shallow validation. Mirrors VariableAggregatorParam.check.
func (p *variableAggregatorParam) Check() error {
- if len(p.Groups) == 0 {
- return &ParamError{Field: "groups", Reason: "must not be empty"}
- }
- for i, g := range p.Groups {
- name, _ := g["group_name"].(string)
- if name == "" {
- return &ParamError{Field: fmt.Sprintf("groups[%d].group_name", i), Reason: "must not be empty"}
- }
- vars, ok := g["variables"]
- if !ok {
- return &ParamError{Field: fmt.Sprintf("groups[%d].variables", i), Reason: "must be a list"}
- }
- switch vars.(type) {
- case []any, []map[string]any:
- // accept both shapes
- default:
- return &ParamError{Field: fmt.Sprintf("groups[%d].variables", i), Reason: "must be a list"}
- }
- }
- return nil
+ return validateVariableAggregatorGroups(componentNameVariableAggregator, p.AsDict(), false)
}
// AsDict returns the params as a plain map.
@@ -137,7 +118,7 @@ func NewVariableAggregatorComponent(params map[string]any) (Component, error) {
return nil, fmt.Errorf("VariableAggregator: param update: %w", err)
}
if err := p.Check(); err != nil {
- return nil, fmt.Errorf("VariableAggregator: param check: %w", err)
+ return nil, runtime.NewUserFacingError(err.Error())
}
return &VariableAggregatorComponent{
name: componentNameVariableAggregator,
diff --git a/web/src/locales/en.ts b/web/src/locales/en.ts
index 37ccb82629..6497f44d9e 100644
--- a/web/src/locales/en.ts
+++ b/web/src/locales/en.ts
@@ -2888,6 +2888,7 @@ Best for: Documents with flowing, contextually connected content — such as boo
'Output the variable content of the upstream component or the text entered by yourself.',
messagePlaceholder: `Please enter your message content, use '/' to quickly insert variables.`,
messageMsg: 'Message cannot be empty',
+ aggregationIncomplete: 'Complete every aggregation group and variable',
inputOptionsIncomplete: 'Dropdown options cannot contain empty entries',
dataOperationsEntriesIncomplete:
'Complete all data operation entries before running',
diff --git a/web/src/pages/agent/utils/canvas-checklist.ts b/web/src/pages/agent/utils/canvas-checklist.ts
index 99576170a2..3aee45b7b6 100644
--- a/web/src/pages/agent/utils/canvas-checklist.ts
+++ b/web/src/pages/agent/utils/canvas-checklist.ts
@@ -691,6 +691,33 @@ export function collectCanvasIssues({
});
}
+ if (
+ label === Operator.VariableAggregator &&
+ (!Array.isArray(form?.groups) ||
+ form.groups.length === 0 ||
+ form.groups.some(
+ (group: any) =>
+ typeof group?.group_name !== 'string' ||
+ !group.group_name.trim() ||
+ !Array.isArray(group.variables) ||
+ group.variables.length === 0 ||
+ group.variables.some((variable: any) => {
+ const value =
+ typeof variable === 'string' ? variable : variable?.value;
+ return (
+ typeof value !== 'string' || !value.replace(/[{}]/g, '').trim()
+ );
+ }),
+ ))
+ ) {
+ issues.push({
+ ...target,
+ type: CanvasIssueType.MissingRequired,
+ messageKey: 'flow.aggregationIncomplete',
+ blocksRun: true,
+ });
+ }
+
if (ApiKeyRequiredOperators.includes(label) && !form?.api_key) {
issues.push({
...target,