Skip to content

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

fix: allow zero message history window and clear history for new sessions (#15897) (#15902)

zaviermeekz-cpuc50f9c59aae2
diff --git a/agent/canvas.py b/agent/canvas.py
index 8de3d4bfcc..fde3e8db82 100644
--- a/agent/canvas.py
+++ b/agent/canvas.py
@@ -329,6 +329,11 @@ class Canvas(Graph):
self.dsl["memory"] = self.memory
return super().__str__()
+ def clear_history(self):
+ self.history = []
+ if isinstance(self.globals.get("sys.history"), list):
+ self.globals["sys.history"] = []
+
def reset(self, mem=False):
super().reset()
if not mem:
diff --git a/agent/component/categorize.py b/agent/component/categorize.py
index 3bc48e22db..4b5c39631c 100644
--- a/agent/component/categorize.py
+++ b/agent/component/categorize.py
@@ -40,7 +40,8 @@ class CategorizeParam(LLMParam):
self.update_prompt()
def check(self):
- self.check_positive_integer(self.message_history_window_size, "[Categorize] Message window size > 0")
+ if not isinstance(self.message_history_window_size, int) or self.message_history_window_size < 0:
+ raise ValueError("[Categorize] Message window size cannot be negative")
self.check_empty(self.category_description, "[Categorize] Category examples")
for k, v in self.category_description.items():
if not k:
diff --git a/api/apps/restful_apis/agent_api.py b/api/apps/restful_apis/agent_api.py
index 69ad700048..aff36cc621 100644
--- a/api/apps/restful_apis/agent_api.py
+++ b/api/apps/restful_apis/agent_api.py
@@ -1447,6 +1447,7 @@ async def agent_chat_completion(tenant_id, agent_id=None):
from agent.canvas import Canvas
canvas = Canvas(dsl_str, str(tenant_id), canvas_id=agent_id, custom_header=custom_header)
+ canvas.clear_history()
except Exception as exc:
return server_error_response(exc)
turn_id = get_uuid()