RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.
Go agent-harnessagent-native-databaseagentic-aiagentic-retrievalagentic-searchaiai-agentscontext-enginecontext-engineeringcontext-managementharness-engineeringknowledge-compilationragretrieval-augmented-generationretrieval-harnesssearch-harness
fix(agent): save incomplete Iteration outputs and gate Run (#21368)
Sbaaoui Idriss247f3c8ed174
diff --git a/internal/agent/canvas/parallel_subgraph.go b/internal/agent/canvas/parallel_subgraph.goindex 9389960361..73c94cd294 100644--- a/internal/agent/canvas/parallel_subgraph.go+++ b/internal/agent/canvas/parallel_subgraph.go@@ -61,6 +61,11 @@ func buildParallelExpansion(ctx context.Context, c *Canvas, parallelID string) (return nil, fmt.Errorf("agent: buildParallelExpansion: unknown cpn %q", parallelID)}+ // Parallel expansion bypasses normal node construction; validate its params here.+ if _, err := buildNodeBody(ctx, parallelID, "Parallel", "", comp.Obj.Params); err != nil {+ return nil, fmt.Errorf("agent: parallel %q: %w", parallelID, err)+ }+members := collectGroupedMembers(c, parallelID)if len(members) == 0 {members = collectDescendants(c, parallelID)diff --git a/internal/agent/component/dynamic_params.go b/internal/agent/component/dynamic_params.goindex 736d8e0c06..fd12877027 100644--- a/internal/agent/component/dynamic_params.go+++ b/internal/agent/component/dynamic_params.go@@ -17,8 +17,8 @@ func ValidateDynamicEntries(dsl map[string]any) error {}// ValidateDraftDynamicEntries allows unfinished Message content, DataOperations-// entries, Invoke mappings, Compiler configuration, input options, and Loop settings-// in saved drafts.+// entries, Invoke mappings, Compiler configuration, input options, Loop settings,+// and Iteration outputs in saved drafts.// All other checks remain unchanged.func ValidateDraftDynamicEntries(dsl map[string]any) error {return validateDynamicEntries(dsl, true)@@ -108,8 +108,8 @@ func validateDynamicParams(component string, params map[string]any, draft bool)}}}- case "iteration":- return validateIterationOutputs(component, params)+ case "iteration", "parallel":+ return validateIterationOutputs(component, params, draft)case "variableaggregator":return validateVariableAggregatorGroups(component, params)case "userfillup":@@ -256,14 +256,20 @@ func validateVariableAggregatorGroups(component string, params map[string]any) ereturn nil}-func validateIterationOutputs(component string, params map[string]any) error {+func validateIterationOutputs(component string, params map[string]any, draft bool) error {+ if params["outputs"] == nil {+ return nil+ }outputs, ok := params["outputs"].(map[string]any)if !ok {- return nil+ return fmt.Errorf("[%s] outputs must be an object", component)}for name, rawOutput := range outputs {output, ok := rawOutput.(map[string]any)- if isBlank(name) || !ok || output == nil || !isNonBlankString(output["ref"]) {+ if !ok || output == nil {+ return fmt.Errorf("[%s] outputs.%s is incomplete: must be an object", component, name)+ }+ if !draft && (isBlank(name) || !isNonBlankString(output["ref"])) {return fmt.Errorf("[%s] outputs.%s is incomplete", component, name)}}diff --git a/internal/agent/component/dynamic_params_test.go b/internal/agent/component/dynamic_params_test.goindex d953fa3c79..4b32381508 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"] == "DataOperations" || test.component["component_name"] == "Compiler" || test.component["component_name"] == "Loop" || invokeDraft || test.name == "input option" {+ if test.component["component_name"] == "Message" || test.component["component_name"] == "DataOperations" || test.component["component_name"] == "Compiler" || test.component["component_name"] == "Loop" || test.component["component_name"] == "Iteration" || invokeDraft || test.name == "input option" {if draftErr != nil {t.Fatalf("draft rejected unfinished entries: %v", draftErr)}diff --git a/internal/agent/component/parallel.go b/internal/agent/component/parallel.goindex f934dd1abd..4db316f8cb 100644--- a/internal/agent/component/parallel.go+++ b/internal/agent/component/parallel.go@@ -51,6 +51,8 @@ package componentimport ("context"+ "ragflow/internal/agent/runtime"+"gorm.io/gorm")@@ -179,6 +181,9 @@ func (c *ParallelComponent) Stream(ctx context.Context, db *gorm.DB, inputs map[// by the parallel extension.func init() {Register(componentNameParallel, func(params map[string]any) (Component, error) {+ if err := validateDynamicParams(componentNameParallel, params, false); err != nil {+ return nil, runtime.NewUserFacingError(err.Error())+ }var p ParallelParamif err := p.Update(params); err != nil {return nil, errdiff --git a/web/src/locales/en.ts b/web/src/locales/en.tsindex 4be62d2d69..86cc6fde17 100644--- a/web/src/locales/en.ts+++ b/web/src/locales/en.ts@@ -3616,6 +3616,8 @@ This process aggregates variables from multiple branches into a single variablechecklistTitle: 'The following issues may affect running or publishing',loopRowsIncomplete:'Complete the loop variables and termination conditions',+ iterationOutputsIncomplete:+ 'Complete the iteration output names and references',issueNotConnected: 'This step is not connected to anything',issueVariableInvalid: 'Invalid variable: {{variable}}',memoryUnavailable:diff --git a/web/src/locales/zh.ts b/web/src/locales/zh.tsindex 28c26d0b0d..2ae39da7a8 100644--- a/web/src/locales/zh.ts+++ b/web/src/locales/zh.ts@@ -3131,6 +3131,7 @@ NER:使用 spaCy NER 和基于规则的关键词提取来抽取 Entities 和 RchecklistEmpty: '未发现问题',checklistTitle: '以下问题可能影响运行或发布',loopRowsIncomplete: '请完善循环变量和终止条件',+ iterationOutputsIncomplete: '请完善迭代输出名称和引用',issueNotConnected: '该步骤未与任何算子连接',issueVariableInvalid: '变量失效:{{variable}}',memoryUnavailable: '所选记忆不可用(已删除),请重新选择',diff --git a/web/src/pages/agent/utils/canvas-checklist.ts b/web/src/pages/agent/utils/canvas-checklist.tsindex 0203ddf9db..7be2000c9b 100644--- a/web/src/pages/agent/utils/canvas-checklist.ts+++ b/web/src/pages/agent/utils/canvas-checklist.ts@@ -608,6 +608,23 @@ export function collectCanvasIssues({});}+ if (+ label === Operator.Iteration &&+ Object.entries(form?.outputs ?? {}).some(+ ([name, output]) =>+ !name.trim() ||+ typeof (output as Record<string, unknown>)?.ref !== 'string' ||+ !(output as Record<string, string>).ref.trim(),+ )+ ) {+ issues.push({+ ...target,+ type: CanvasIssueType.MissingRequired,+ messageKey: 'flow.iterationOutputsIncomplete',+ blocksRun: true,+ });+ }+if (ApiKeyRequiredOperators.includes(label) && !form?.api_key) {issues.push({...target,