Skip to content

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

Feat: add `sync_dsl` parameter to support synchronizing modifications to existing sessions (#5843)

hy898ba1e6c183a3
diff --git a/api/apps/sdk/session.py b/api/apps/sdk/session.py
index 8fb70ec353..08dc23593e 100644
--- a/api/apps/sdk/session.py
+++ b/api/apps/sdk/session.py
@@ -365,6 +365,18 @@ def agent_completions(tenant_id, agent_id):
conv = API4ConversationService.query(id=req["session_id"], dialog_id=agent_id)
if not conv:
return get_error_data_result(f"You don't own the session {req['session_id']}")
+ # If an update to UserCanvas is detected, update the API4Conversation.dsl
+ sync_dsl = req.get("sync_dsl", False)
+ if sync_dsl is True and cvs[0].update_time > conv[0].update_time:
+ current_dsl = conv[0].dsl
+ new_dsl = json.loads(dsl)
+ state_fields = ["history", "messages", "path", "reference"]
+ states = {field: current_dsl.get(field, []) for field in state_fields}
+ current_dsl.update(new_dsl)
+ current_dsl.update(states)
+ API4ConversationService.update_by_id(req["session_id"], {
+ "dsl": current_dsl
+ })
else:
req["question"] = ""
if req.get("stream", True):
diff --git a/docs/references/http_api_reference.md b/docs/references/http_api_reference.md
index 40b1727174..216a1c7130 100644
--- a/docs/references/http_api_reference.md
+++ b/docs/references/http_api_reference.md
@@ -2513,6 +2513,7 @@ Asks a specified agent a question to start an AI-powered conversation.
- `"stream"`: `boolean`
- `"session_id"`: `string`
- `"user_id"`: `string`(optional)
+ - `"sync_dsl"`: `boolean` (optional)
- other parameters: `string`
##### Request example
If the **Begin** component does not take parameters, the following code will create a session.
@@ -2565,6 +2566,8 @@ curl --request POST \
The ID of the session. If it is not provided, a new session will be generated.
- `"user_id"`: (*Body parameter*), `string`
The optional user-defined ID. Valid *only* when no `session_id` is provided.
+- `"sync_dsl"`: (*Body parameter*), `boolean`
+ Whether to synchronize the changes to existing sessions when an agent is modified, defaults to `false`.
- Other parameters: (*Body Parameter*)
Parameters specified in the **Begin** component.