Skip to content

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

fix(agent): clear stale template dataset references (#19399)

Sbaaoui Idriss76c197f12ae6
diff --git a/agent/templates/smart_customer_service_specialist.json b/agent/templates/smart_customer_service_specialist.json
index 3d84686e61..5b2ffb963f 100644
--- a/agent/templates/smart_customer_service_specialist.json
+++ b/agent/templates/smart_customer_service_specialist.json
@@ -238,9 +238,7 @@
"params": {
"cross_languages": [],
"empty_response": "",
- "dataset_ids": [
- "a5aaec4a819b11f095f1047c16ec874f"
- ],
+ "dataset_ids": [],
"retrieval_from": "dataset",
"keywords_similarity_weight": 0.7,
"outputs": {
@@ -270,9 +268,7 @@
"params": {
"cross_languages": [],
"empty_response": "",
- "dataset_ids": [
- "65cb5150819b11f08347047c16ec874f"
- ],
+ "dataset_ids": [],
"retrieval_from": "dataset",
"keywords_similarity_weight": 0.7,
"meta_data_filter": {},
@@ -592,9 +588,7 @@
"form": {
"cross_languages": [],
"empty_response": "",
- "dataset_ids": [
- "65cb5150819b11f08347047c16ec874f"
- ],
+ "dataset_ids": [],
"retrieval_from": "dataset",
"keywords_similarity_weight": 0.7,
"meta_data_filter": {},
@@ -693,9 +687,7 @@
"form": {
"cross_languages": [],
"empty_response": "",
- "dataset_ids": [
- "a5aaec4a819b11f095f1047c16ec874f"
- ],
+ "dataset_ids": [],
"retrieval_from": "dataset",
"keywords_similarity_weight": 0.7,
"outputs": {
diff --git a/agent/templates/stock_market_research_assistant.json b/agent/templates/stock_market_research_assistant.json
index 17cea04a30..a04aca4cd3 100644
--- a/agent/templates/stock_market_research_assistant.json
+++ b/agent/templates/stock_market_research_assistant.json
@@ -184,9 +184,7 @@
"cross_languages": [],
"description": "A knowledge base of research reports on stock analysis by senior experts",
"empty_response": "",
- "dataset_ids": [
- "60c53ed89acc11f0bc1e7a2a6d0b2755"
- ],
+ "dataset_ids": [],
"retrieval_from": "dataset",
"keywords_similarity_weight": 0.7,
"outputs": {
@@ -1010,9 +1008,7 @@
"cross_languages": [],
"description": "A knowledge base of research reports on stock analysis by senior experts",
"empty_response": "",
- "dataset_ids": [
- "60c53ed89acc11f0bc1e7a2a6d0b2755"
- ],
+ "dataset_ids": [],
"retrieval_from": "dataset",
"keywords_similarity_weight": 0.7,
"outputs": {
diff --git a/web/src/pages/agent/hooks/use-fetch-data.test.ts b/web/src/pages/agent/hooks/use-fetch-data.test.ts
index 5d5af8a33d..0c934322d0 100644
--- a/web/src/pages/agent/hooks/use-fetch-data.test.ts
+++ b/web/src/pages/agent/hooks/use-fetch-data.test.ts
@@ -4,6 +4,7 @@ import { useFetchDataOnMount } from './use-fetch-data';
const mockSetGraphInfo = jest.fn();
const mockRefetch = jest.fn();
const mockUseFetchAgent = jest.fn();
+const mockUseParams = jest.fn();
jest.mock('@/hooks/use-agent-request', () => ({
useFetchAgent: () => mockUseFetchAgent(),
@@ -13,6 +14,10 @@ jest.mock('./use-set-graph', () => ({
useSetGraphInfo: () => mockSetGraphInfo,
}));
+jest.mock('react-router', () => ({
+ useParams: () => mockUseParams(),
+}));
+
jest.mock('../utils/dsl-bridge', () => ({
dslToGraph: (dsl: { graph?: { nodes: unknown[]; edges: unknown[] } }) => ({
nodes: dsl.graph?.nodes ?? [],
@@ -24,6 +29,7 @@ describe('useFetchDataOnMount', () => {
beforeEach(() => {
mockSetGraphInfo.mockClear();
mockRefetch.mockClear();
+ mockUseParams.mockReturnValue({});
});
it('does not apply an empty graph while agent detail has no dsl', () => {
@@ -80,4 +86,28 @@ describe('useFetchDataOnMount', () => {
expect(mockSetGraphInfo).toHaveBeenCalledTimes(1);
});
+
+ it('clears the previous canvas before loading a different agent', () => {
+ mockUseParams.mockReturnValue({ id: 'agent-1' });
+ mockUseFetchAgent.mockReturnValue({
+ loading: false,
+ data: {
+ id: 'agent-1',
+ dsl: { graph: { nodes: [{ id: 'old' }], edges: [] } },
+ },
+ refetch: mockRefetch,
+ });
+
+ const { rerender } = renderHook(() => useFetchDataOnMount());
+
+ mockUseParams.mockReturnValue({ id: 'agent-2' });
+ mockUseFetchAgent.mockReturnValue({
+ loading: true,
+ data: {},
+ refetch: mockRefetch,
+ });
+ rerender();
+
+ expect(mockSetGraphInfo).toHaveBeenLastCalledWith({ nodes: [], edges: [] });
+ });
});
diff --git a/web/src/pages/agent/hooks/use-fetch-data.ts b/web/src/pages/agent/hooks/use-fetch-data.ts
index f0925ecb09..9dbb72d6f9 100644
--- a/web/src/pages/agent/hooks/use-fetch-data.ts
+++ b/web/src/pages/agent/hooks/use-fetch-data.ts
@@ -1,12 +1,23 @@
import { useFetchAgent } from '@/hooks/use-agent-request';
-import { useEffect } from 'react';
+import { useEffect, useLayoutEffect } from 'react';
+import { useParams } from 'react-router';
import { dslToGraph } from '../utils/dsl-bridge';
import { useSetGraphInfo } from './use-set-graph';
export const useFetchDataOnMount = () => {
+ const { id } = useParams();
const { loading, data, refetch } = useFetchAgent();
const setGraphInfo = useSetGraphInfo();
+ // The graph store outlives a route transition. Empty it before retrieval
+ // nodes mount for the next agent, so they cannot query the previous agent's
+ // dataset ids while the new detail request is pending.
+ useLayoutEffect(() => {
+ if (id) {
+ setGraphInfo({ nodes: [], edges: [] });
+ }
+ }, [id, setGraphInfo]);
+
useEffect(() => {
if (!data?.dsl) {
return;