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: Restrict the canvas to a single compilation operator. (#20120)
balibabu2b33e0d32d30
diff --git a/web/src/pages/agent/canvas/node/toolbar.tsx b/web/src/pages/agent/canvas/node/toolbar.tsxindex f7c103e29b..fd1b1c67eb 100644--- a/web/src/pages/agent/canvas/node/toolbar.tsx+++ b/web/src/pages/agent/canvas/node/toolbar.tsx@@ -11,6 +11,7 @@ import { MouseEventHandler, PropsWithChildren, useCallback } from 'react';import { Operator } from '../../constant';import { useDuplicateNode } from '../../hooks';import useGraphStore from '../../store';+import { isSingleInstanceOperator } from '../../utils/pipeline-connection';function IconWrapper({ children, className, ...props }: ButtonProps) {return (@@ -63,6 +64,10 @@ export function ToolBar({const duplicateNode = useDuplicateNode();+ // A single-instance operator can never be duplicated: a copy would+ // immediately exceed the one-instance limit.+ const duplicateDisabled = isSingleInstanceOperator(label as Operator);+const handleDuplicate: MouseEventHandler<HTMLButtonElement> = useCallback((e) => {e.stopPropagation();@@ -83,7 +88,7 @@ export function ToolBar({</IconWrapper>)}{showCopy && (- <IconWrapper onClick={handleDuplicate}>+ <IconWrapper onClick={handleDuplicate} disabled={duplicateDisabled}><Copy className="size-3.5" /></IconWrapper>)}diff --git a/web/src/pages/agent/constant/pipeline.tsx b/web/src/pages/agent/constant/pipeline.tsxindex 815fcf033d..7467c291d7 100644--- a/web/src/pages/agent/constant/pipeline.tsx+++ b/web/src/pages/agent/constant/pipeline.tsx@@ -438,8 +438,12 @@ export const NoDebugOperatorsList = [Operator.File];// legacy Python operator and is deliberately excluded.export const ChunkerOperators = [Operator.TokenChunker, Operator.TitleChunker];+// Pipeline operators limited to a single instance per canvas. Title/Token+// chunkers are separate entries here (each blocks its own duplication) but+// also share one slot: see the chunker group rule in buildPipelineNextOperators.export const SingleOperators = [Operator.Tokenizer,+ Operator.Compiler,Operator.GeneralChunker,Operator.TokenChunker,Operator.TitleChunker,diff --git a/web/src/pages/agent/utils/pipeline-connection.test.ts b/web/src/pages/agent/utils/pipeline-connection.test.tsindex 03c01f2434..5e65cf11e3 100644--- a/web/src/pages/agent/utils/pipeline-connection.test.ts+++ b/web/src/pages/agent/utils/pipeline-connection.test.ts@@ -1,6 +1,8 @@import { Operator } from '@/constants/agent';import {+ buildPipelineNextOperators,isChunkerOperator,+ isSingleInstanceOperator,isValidGoPipelineConnection,} from './pipeline-connection';@@ -84,3 +86,70 @@ describe('isValidGoPipelineConnection', () => {).toBe(true);});});++describe('isSingleInstanceOperator', () => {+ it('marks the one-instance pipeline operators', () => {+ expect(isSingleInstanceOperator(Operator.Parser)).toBe(true);+ expect(isSingleInstanceOperator(Operator.Tokenizer)).toBe(true);+ expect(isSingleInstanceOperator(Operator.Compiler)).toBe(true);+ expect(isSingleInstanceOperator(Operator.TokenChunker)).toBe(true);+ expect(isSingleInstanceOperator(Operator.TitleChunker)).toBe(true);+ expect(isSingleInstanceOperator(Operator.GeneralChunker)).toBe(true);+ });++ it('leaves multi-instance operators unchecked', () => {+ expect(isSingleInstanceOperator(Operator.Extractor)).toBe(false);+ expect(isSingleInstanceOperator(Operator.Agent)).toBe(false);+ });+});++describe('buildPipelineNextOperators', () => {+ const noOperator = () => false;++ it('always offers Extractor, which is multi-instance', () => {+ const hasExtractor = (operator: Operator) =>+ operator === Operator.Extractor;+ expect(+ buildPipelineNextOperators(undefined, true, hasExtractor).operators,+ ).toContain(Operator.Extractor);+ });++ it('offers Compiler only when none is on the canvas', () => {+ const offered = buildPipelineNextOperators(+ undefined,+ true,+ noOperator,+ ).operators;+ expect(offered).toContain(Operator.Compiler);++ const hasCompiler = (operator: Operator) => operator === Operator.Compiler;+ expect(+ buildPipelineNextOperators(undefined, true, hasCompiler).operators,+ ).not.toContain(Operator.Compiler);+ });++ it('hides the whole chunker group once any chunker is on the canvas', () => {+ const hasTokenChunker = (operator: Operator) =>+ operator === Operator.TokenChunker;+ const result = buildPipelineNextOperators(+ Operator.TokenChunker,+ false,+ hasTokenChunker,+ );+ expect(result.showChunker).toBe(false);+ expect(result.chunkerOperators).toEqual([]);+ });++ it('offers both chunker variants while the chunker slot is free', () => {+ const result = buildPipelineNextOperators(+ Operator.Tokenizer,+ true,+ noOperator,+ );+ expect(result.showChunker).toBe(true);+ expect(result.chunkerOperators).toEqual([+ Operator.TokenChunker,+ Operator.TitleChunker,+ ]);+ });+});diff --git a/web/src/pages/agent/utils/pipeline-connection.ts b/web/src/pages/agent/utils/pipeline-connection.tsindex 07b3beab0c..ff2d493c69 100644--- a/web/src/pages/agent/utils/pipeline-connection.ts+++ b/web/src/pages/agent/utils/pipeline-connection.ts@@ -1,15 +1,24 @@import { Operator } from '@/constants/agent';-import { ChunkerOperators } from '../constant/pipeline';+import { ChunkerOperators, SingleOperators } from '../constant/pipeline';export function isChunkerOperator(operator: Operator): boolean {return (ChunkerOperators as Operator[]).includes(operator);}+/**+ * Operators that may appear at most once on a pipeline canvas. Duplicating a+ * node with such an operator always exceeds the limit, so the copy action is+ * disabled for them outright.+ */+export function isSingleInstanceOperator(operator: Operator): boolean {+ return SingleOperators.includes(operator);+}+export interface PipelineNextOperators {// Operators offered in the flat top-level list (Parser, Tokenizer,// Extractor, Compiler), minus the single-instance ones already on canvas.operators: Operator[];- // Single-instance chunkers not yet on canvas, shown in the Chunker group.+ // The chunker variants, offered only while the single chunker slot is free.chunkerOperators: Operator[];showChunker: boolean;}@@ -32,20 +41,21 @@ export function buildPipelineNextOperators(// Go pipelines require a Parser to feed a chunker, so from a Parser node// the menu offers only the chunker group.if (!(isGoBackend && source === Operator.Parser)) {- [Operator.Parser, Operator.Tokenizer].forEach((operator) => {- if (!hasOperator(operator)) {- operators.push(operator);- }- });+ [Operator.Parser, Operator.Tokenizer, Operator.Compiler].forEach(+ (operator) => {+ if (!hasOperator(operator)) {+ operators.push(operator);+ }+ },+ );operators.push(Operator.Extractor);- if (source !== Operator.Compiler) {- operators.push(Operator.Compiler);- }}- const chunkerOperators = ChunkerOperators.filter(- (operator) => !hasOperator(operator),- );+ // The chunker group occupies a single slot: any chunker already on the+ // canvas (Title or Token) hides the whole group, keeping the two variants+ // mutually exclusive.+ const chunkerSlotTaken = ChunkerOperators.some(hasOperator);+ const chunkerOperators = chunkerSlotTaken ? [] : ChunkerOperators;// Go pipelines forbid chunker -> chunker, mirroring the existing rule// that Extractor/Compiler never offer the chunker group.