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: The checklist allows loop operators to reference the outputs of internal operators. (#20205)
balibabuc46662932400
diff --git a/web/src/pages/agent/utils/__tests__/canvas-checklist.test.ts b/web/src/pages/agent/utils/__tests__/canvas-checklist.test.tsindex 85daef0cc5..fe3f886608 100644--- a/web/src/pages/agent/utils/__tests__/canvas-checklist.test.ts+++ b/web/src/pages/agent/utils/__tests__/canvas-checklist.test.ts@@ -409,6 +409,107 @@ describe('collectCanvasIssues: iteration/loop children references', () => {issues.filter((x) => x.type === CanvasIssueType.InvalidVariable),).toHaveLength(0);});++ it('lets a Loop reference its own variables and child outputs', () => {+ const issues = collect({+ nodes: [+ makeNode('Loop:p1', 'Loop', {+ loop_termination_condition: [+ { variable: 'UserFillUp:u1@value', operator: 'is', value: '1' },+ { variable: 'Loop:p1@count', operator: '≥', value: 3 },+ ],+ outputs: { count: { type: 'number' } },+ }),+ makeNode(+ 'UserFillUp:u1',+ 'UserFillUp',+ { outputs: { value: { type: 'string' } } },+ { parentId: 'Loop:p1' },+ ),+ ],+ edges: [makeEdge('Loop:p1', 'Message:m1')],+ });++ expect(+ issues.filter((x) => x.type === CanvasIssueType.InvalidVariable),+ ).toHaveLength(0);+ });++ it('lets an Iteration reference child outputs in its output map', () => {+ const issues = collect({+ nodes: [+ makeNode('Iteration:p1', 'Iteration', {+ outputs: {+ merged: { ref: 'StringTransform:s1@result' },+ },+ }),+ makeNode(+ 'StringTransform:s1',+ 'StringTransform',+ { outputs: { result: { type: 'string' } } },+ { parentId: 'Iteration:p1' },+ ),+ ],+ edges: [makeEdge('Iteration:p1', 'Message:m1')],+ });++ expect(+ issues.filter((x) => x.type === CanvasIssueType.InvalidVariable),+ ).toHaveLength(0);+ });++ it('flags an Iteration referencing the per-item IterationStart outputs', () => {+ const issues = collect({+ nodes: [+ makeNode('Iteration:p1', 'Iteration', {+ outputs: {+ merged: { ref: 'IterationStart:s1@item' },+ },+ }),+ makeNode(+ 'IterationStart:s1',+ 'IterationItem',+ { outputs: { item: { type: 'unknown' } } },+ { parentId: 'Iteration:p1' },+ ),+ ],+ edges: [makeEdge('Iteration:p1', 'Message:m1')],+ });++ expect(issues).toContainEqual(+ expect.objectContaining({+ nodeId: 'Iteration:p1',+ type: CanvasIssueType.InvalidVariable,+ messageParams: { variable: 'IterationStart:s1@item' },+ }),+ );+ });++ it('still flags an outsider referencing a container child', () => {+ const issues = collect({+ nodes: [+ makeNode('Loop:p1', 'Loop', { outputs: {} }),+ makeNode(+ 'UserFillUp:u1',+ 'UserFillUp',+ { outputs: { value: { type: 'string' } } },+ { parentId: 'Loop:p1' },+ ),+ makeNode('Message:m1', 'Message', {+ content: ['{UserFillUp:u1@value}'],+ }),+ ],+ edges: [makeEdge('Loop:p1', 'Message:m1')],+ });++ expect(issues).toContainEqual(+ expect.objectContaining({+ nodeId: 'Message:m1',+ type: CanvasIssueType.InvalidVariable,+ messageParams: { variable: 'UserFillUp:u1@value' },+ }),+ );+ });});describe('collectCanvasIssues: missing required fields', () => {diff --git a/web/src/pages/agent/utils/canvas-checklist.ts b/web/src/pages/agent/utils/canvas-checklist.tsindex 6e6246f954..8f21ea09a7 100644--- a/web/src/pages/agent/utils/canvas-checklist.ts+++ b/web/src/pages/agent/utils/canvas-checklist.ts@@ -133,6 +133,7 @@ function extractReferencesFromText(text: string): string[] {type ReferenceValidationContext = {nodeMap: Map<string, RAGFlowNodeType>;+ childIdsByParent: Map<string, string[]>;edges: Edge[];beginInputKeys: Set<string>;variables?: Record<string, any>;@@ -141,22 +142,42 @@ type ReferenceValidationContext = {function buildReachableNodeIds(node: RAGFlowNodeType,- nodeMap: Map<string, RAGFlowNodeType>,- edges: Edge[],+ ctx: ReferenceValidationContext,) {// Mirrors the variable picker (useBuildVariableOptions): a node may reference// its own upstream, its parent's upstream, and — for Loop parents only — the// parent's own outputs.- const reachable = new Set(filterAllUpstreamNodeIds(edges, [node.id]));+ const reachable = new Set(filterAllUpstreamNodeIds(ctx.edges, [node.id]));const parentId = node.parentId;if (parentId) {- for (const id of filterAllUpstreamNodeIds(edges, [parentId])) {+ for (const id of filterAllUpstreamNodeIds(ctx.edges, [parentId])) {reachable.add(id);}- if (nodeMap.get(parentId)?.data?.label === Operator.Loop) {+ if (ctx.nodeMap.get(parentId)?.data?.label === Operator.Loop) {reachable.add(parentId);}}++ // A container's own form also reads from inside (loop-termination-condition+ // and iteration dynamic-output pickers): Loop picks from its own loop+ // variables plus child outputs, Iteration's output map picks child outputs —+ // except IterationStart, whose per-item outputs the picker never offers.+ const label = node.data?.label;+ if (label === Operator.Loop || label === Operator.Iteration) {+ for (const childId of ctx.childIdsByParent.get(node.id) ?? []) {+ const childLabel = ctx.nodeMap.get(childId)?.data?.label;+ if (+ label === Operator.Iteration &&+ childLabel === Operator.IterationStart+ ) {+ continue;+ }+ reachable.add(childId);+ }+ if (label === Operator.Loop) {+ reachable.add(node.id);+ }+ }return reachable;}@@ -194,11 +215,7 @@ function isReferenceValid(if (!relaxedUpstream) {let reachable = ctx.reachableCache.get(referencingNode.id);if (!reachable) {- reachable = buildReachableNodeIds(- referencingNode,- ctx.nodeMap,- ctx.edges,- );+ reachable = buildReachableNodeIds(referencingNode, ctx);ctx.reachableCache.set(referencingNode.id, reachable);}if (!reachable.has(nodeId)) {@@ -425,11 +442,19 @@ export function collectCanvasIssues({const ctx: ReferenceValidationContext = {nodeMap,+ childIdsByParent: new Map(),edges,beginInputKeys,variables,reachableCache: new Map(),};+ for (const node of nodes) {+ if (node.parentId) {+ const childIds = ctx.childIdsByParent.get(node.parentId) ?? [];+ childIds.push(node.id);+ ctx.childIdsByParent.set(node.parentId, childIds);+ }+ }const issues: CanvasIssue[] = [];