Skip to content

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

fix(agent): warn at save time when an Agent node has no model selected (#18996)

euvred8c7b9dd9dcd
diff --git a/web/src/locales/en.ts b/web/src/locales/en.ts
index d592e0afbc..5234ec8194 100644
--- a/web/src/locales/en.ts
+++ b/web/src/locales/en.ts
@@ -3369,6 +3369,8 @@ This process aggregates variables from multiple branches into a single variable
tokenizerRequired: 'Please add the Indexer node first',
nodeFormInvalid:
'Cannot save: "{{name}}" has invalid settings. Please fix them first',
+ agentModelMissing:
+ 'Cannot save: "{{name}}" has no model selected. Please choose one first',
tokenizerDescription:
'Transforms text into the required data structure (e.g., vector embeddings for Embedding Search) depending on the chosen search method.',
tokenChunker: 'Token Chunker',
diff --git a/web/src/locales/zh.ts b/web/src/locales/zh.ts
index 492ad15e93..73b5e4ac84 100644
--- a/web/src/locales/zh.ts
+++ b/web/src/locales/zh.ts
@@ -2929,6 +2929,7 @@ NER:使用 spaCy NER 和基于规则的关键词提取来抽取 Entities 和 R
tokenizer: '分词器',
tokenizerRequired: '请先添加 Tokenizer 节点',
nodeFormInvalid: '无法保存:“{{name}}” 配置有误,请先修正',
+ agentModelMissing: '无法保存:“{{name}}” 未选择模型,请先选择',
tokenizerDescription:
'根据所选的搜索方法,将文本转换为所需的数据结构(例如,用于嵌入搜索的 Embedding)。',
tokenChunker: '按 Token 分块',
diff --git a/web/src/pages/agent/hooks/use-save-graph.ts b/web/src/pages/agent/hooks/use-save-graph.ts
index 40b50cfc30..00f8da650b 100644
--- a/web/src/pages/agent/hooks/use-save-graph.ts
+++ b/web/src/pages/agent/hooks/use-save-graph.ts
@@ -18,6 +18,7 @@ import { Operator } from '../constant';
import { FormSchema as ParserFormSchema } from '../form/parser-form';
import useGraphStore from '../store';
import { getEmptyMessageNodeNames } from '../utils';
+import { findAgentNodeWithoutModel } from '../utils/agent-node-model';
import { useBuildDslData } from './use-build-dsl';
/**
@@ -26,13 +27,27 @@ import { useBuildDslData } from './use-build-dsl';
* same schema before persisting, but only for nodes the user actually edited —
* a node still carrying stale DSL from an older version must not wedge saving.
*/
-function findInvalidNode(nodes: RAGFlowNodeType[], editedNodeIds: string[]) {
- return nodes.find(
+function findInvalidNode(
+ nodes: RAGFlowNodeType[],
+ editedNodeIds: string[],
+): { node: RAGFlowNodeType; messageKey: string } | undefined {
+ const invalidParserNode = nodes.find(
(node) =>
editedNodeIds.includes(node.id) &&
node.data?.label === Operator.Parser &&
!ParserFormSchema.safeParse(node.data?.form).success,
);
+ if (invalidParserNode) {
+ return { node: invalidParserNode, messageKey: 'flow.nodeFormInvalid' };
+ }
+ // Unlike the schema re-check above, the missing-model check is not gated on
+ // editedNodeIds: a canvas loaded from storage with an empty model must warn
+ // on the very next save, not only after the node is edited again.
+ const agentNode = findAgentNodeWithoutModel(nodes);
+ if (agentNode) {
+ return { node: agentNode, messageKey: 'flow.agentModelMissing' };
+ }
+ return undefined;
}
export const useValidateNodeForms = () => {
@@ -50,10 +65,10 @@ export const useValidateNodeForms = () => {
// publish stay silent and just skip the write.
const notifyIfInvalid = useCallback(
(currentNodes?: RAGFlowNodeType[]) => {
- const invalidNode = getInvalidNode(currentNodes);
- if (invalidNode) {
+ const invalid = getInvalidNode(currentNodes);
+ if (invalid) {
message.warning(
- t('flow.nodeFormInvalid', { name: invalidNode.data?.name }),
+ t(invalid.messageKey, { name: invalid.node.data?.name }),
);
return false;
}
diff --git a/web/src/pages/agent/utils/agent-node-model.test.ts b/web/src/pages/agent/utils/agent-node-model.test.ts
new file mode 100644
index 0000000000..079460316a
--- /dev/null
+++ b/web/src/pages/agent/utils/agent-node-model.test.ts
@@ -0,0 +1,39 @@
+import { Operator } from '@/constants/agent';
+import { RAGFlowNodeType } from '@/interfaces/database/agent';
+import { findAgentNodeWithoutModel } from './agent-node-model';
+
+function baseNode(
+ id: string,
+ label: Operator,
+ form: Record<string, any> = {},
+): RAGFlowNodeType {
+ return {
+ id,
+ type: 'ragNode',
+ position: { x: 0, y: 0 },
+ data: { label, name: id, form },
+ } as RAGFlowNodeType;
+}
+
+describe('findAgentNodeWithoutModel', () => {
+ it('flags an Agent node whose model is empty', () => {
+ const nodes = [
+ baseNode('agent-1', Operator.Agent),
+ baseNode('agent-2', Operator.Agent, { llm_id: '' }),
+ ];
+ expect(findAgentNodeWithoutModel(nodes)).toBe(nodes[0]);
+ });
+
+ it('accepts an Agent node with a model', () => {
+ const nodes = [baseNode('agent-1', Operator.Agent, { llm_id: 'gpt-4o' })];
+ expect(findAgentNodeWithoutModel(nodes)).toBeUndefined();
+ });
+
+ it('ignores nodes of other operators without a model', () => {
+ const nodes = [
+ baseNode('message-1', Operator.Message),
+ baseNode('retrieval-1', Operator.Retrieval),
+ ];
+ expect(findAgentNodeWithoutModel(nodes)).toBeUndefined();
+ });
+});
diff --git a/web/src/pages/agent/utils/agent-node-model.ts b/web/src/pages/agent/utils/agent-node-model.ts
new file mode 100644
index 0000000000..8055403c2b
--- /dev/null
+++ b/web/src/pages/agent/utils/agent-node-model.ts
@@ -0,0 +1,12 @@
+import { Operator } from '@/constants/agent';
+import { RAGFlowNodeType } from '@/interfaces/database/agent';
+
+/**
+ * An Agent node without a model is unrunnable — the backend only rejects it
+ * with `invalid param "model_id": required` once a question is asked. Saving
+ * must surface the gap instead of letting it fail at run time.
+ */
+export const findAgentNodeWithoutModel = (nodes: RAGFlowNodeType[]) =>
+ nodes.find(
+ (node) => node.data?.label === Operator.Agent && !node.data?.form?.llm_id,
+ );