Skip to content

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

fix(agent): save incomplete Invoke mappings and gate Run (#21364)

Sbaaoui Idriss5dc57e450d74
diff --git a/internal/agent/component/dynamic_params.go b/internal/agent/component/dynamic_params.go
index 15f555ac7a..52d8a180d1 100644
--- a/internal/agent/component/dynamic_params.go
+++ b/internal/agent/component/dynamic_params.go
@@ -15,9 +15,8 @@ func ValidateDynamicEntries(dsl map[string]any) error {
return validateDynamicEntries(dsl, false)
}
-// ValidateDraftDynamicEntries allows unfinished Message content and
-// DataOperations entries in saved drafts.
-// All other component checks remain the same as ValidateDynamicEntries.
+// ValidateDraftDynamicEntries allows unfinished Message content, DataOperations
+// entries, and Invoke mappings in saved drafts. All other checks remain unchanged.
func ValidateDraftDynamicEntries(dsl map[string]any) error {
return validateDynamicEntries(dsl, true)
}
@@ -79,7 +78,7 @@ func validateDynamicParams(component string, params map[string]any, draft bool)
return fmt.Errorf("[%s] tools does not support empty entries", component)
}
case "invoke":
- if err := validateInvokeVariables(component, params); err != nil {
+ if err := validateInvokeVariables(component, params, draft); err != nil {
return err
}
case "loop":
@@ -171,8 +170,9 @@ func validateRows(component string, params map[string]any, field string, require
// literal (value). The two sources are alternatives — a reference row has
// no literal and a literal row has no reference — so a row with neither
// is still rejected. Omitted and null variables carry no rows to check;
-// any other non-array value is malformed and rejected.
-func validateInvokeVariables(component string, params map[string]any) error {
+// any other non-array value is malformed and rejected. Drafts retain unfinished
+// mappings while still rejecting malformed containers, rows, and field types.
+func validateInvokeVariables(component string, params map[string]any, draft bool) error {
raw, present := params["variables"]
if !present || raw == nil {
return nil
@@ -183,7 +183,17 @@ func validateInvokeVariables(component string, params map[string]any) error {
}
for i, raw := range rows {
row, ok := raw.(map[string]any)
- if !ok || !isNonBlankString(row["key"]) || !invokeRowHasSource(row) {
+ if !ok || row == nil {
+ return fmt.Errorf("[%s] variables[%d] is incomplete", component, i)
+ }
+ for _, key := range []string{"key", "ref"} {
+ if value := row[key]; value != nil {
+ if _, ok := value.(string); !ok {
+ return fmt.Errorf("[%s] variables[%d] is incomplete: %s must be a string", component, i, key)
+ }
+ }
+ }
+ if !draft && (!isNonBlankString(row["key"]) || !invokeRowHasSource(row)) {
return fmt.Errorf("[%s] variables[%d] is incomplete", component, i)
}
}
diff --git a/internal/agent/component/dynamic_params_test.go b/internal/agent/component/dynamic_params_test.go
index 413216ac3a..396b940431 100644
--- a/internal/agent/component/dynamic_params_test.go
+++ b/internal/agent/component/dynamic_params_test.go
@@ -96,7 +96,12 @@ func TestValidateDynamicEntries(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
draftErr := ValidateDraftDynamicEntries(dslWithComponents(test.component))
- if test.component["component_name"] == "Message" || test.component["component_name"] == "DataOperations" {
+ invokeDraft := test.component["component_name"] == "Invoke"
+ switch test.name {
+ 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" || invokeDraft {
if draftErr != nil {
t.Fatalf("draft rejected unfinished entries: %v", draftErr)
}
diff --git a/internal/agent/component/invoke.go b/internal/agent/component/invoke.go
index b0ed168380..5ded3578b1 100644
--- a/internal/agent/component/invoke.go
+++ b/internal/agent/component/invoke.go
@@ -44,6 +44,7 @@ import (
"net"
"net/http"
"net/url"
+ "ragflow/internal/agent/runtime"
"ragflow/internal/common"
"strings"
"time"
@@ -78,6 +79,9 @@ type InvokeComponent struct {
// NewInvokeComponent constructs an Invoke component.
func NewInvokeComponent(params map[string]any) (Component, error) {
+ if err := validateInvokeVariables(componentNameInvoke, params, false); err != nil {
+ return nil, runtime.NewUserFacingError(err.Error())
+ }
return &InvokeComponent{name: componentNameInvoke, params: cloneInvokeParams(params)}, nil
}
diff --git a/web/src/locales/en.ts b/web/src/locales/en.ts
index e09691aa1d..d3d623b5b7 100644
--- a/web/src/locales/en.ts
+++ b/web/src/locales/en.ts
@@ -2894,6 +2894,8 @@ Best for: Documents with flowing, contextually connected content — such as boo
messageMsg: 'Message cannot be empty',
dataOperationsEntriesIncomplete:
'Complete all data operation entries before running',
+ invokeVariablesIncomplete:
+ 'Complete all variable mappings before running',
addField: 'Add option',
addMessage: 'Add message',
loop: 'Loop',
diff --git a/web/src/pages/agent/utils/canvas-checklist.ts b/web/src/pages/agent/utils/canvas-checklist.ts
index db8ca3c8b9..42a1e800ee 100644
--- a/web/src/pages/agent/utils/canvas-checklist.ts
+++ b/web/src/pages/agent/utils/canvas-checklist.ts
@@ -548,6 +548,27 @@ export function collectCanvasIssues({
}
}
+ if (label === Operator.Invoke && Array.isArray(form?.variables)) {
+ const nonblank = (value: unknown) =>
+ typeof value === 'string' && value.trim().length > 0;
+ if (
+ form.variables.some(
+ (row: any) =>
+ !nonblank(row?.key) ||
+ (!nonblank(row?.ref) &&
+ (row?.value == null ||
+ (typeof row.value === 'string' && !nonblank(row.value)))),
+ )
+ ) {
+ issues.push({
+ ...target,
+ type: CanvasIssueType.MissingRequired,
+ messageKey: 'flow.invokeVariablesIncomplete',
+ blocksRun: true,
+ });
+ }
+ }
+
if (ApiKeyRequiredOperators.includes(label) && !form?.api_key) {
issues.push({
...target,