mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-06-29 15:31:05 +08:00
### What problem does this PR solve? Two bugs in the Agent Categorize component: 1. The backend rejected `message_history_window_size = 0` while frontend allowed it, causing API errors. 2. When calling the agent API without a `session_id`, a new session was created but retained history from previous conversations. ### Type of change - [x] Bug Fix ### How has this been tested? - Issue 1: `CategorizeParam().check()` now accepts `0` and rejects negative values. - Issue 2: `canvas.clear_history()` is called for new sessions (no `session_id`), ensuring fresh conversation state. Verified via UI and API that a second call without `session_id` does not remember the first conversation. ### Related Issue Closes #15897 Co-authored-by: RAGFlow Dev <dev@ragflow.local> Co-authored-by: Wang Qi <wangq8@outlook.com>
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user