Skip to content

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

Fix add agent update validation check (#18056)

Wang Qia0438517bc23
diff --git a/agent/canvas.py b/agent/canvas.py
index 8c34c55a51..4ccec4ae5a 100644
--- a/agent/canvas.py
+++ b/agent/canvas.py
@@ -101,20 +101,27 @@ class Graph:
def load(self):
self.components = self.dsl["components"]
- cpn_nms = set([])
+ for cpn in self.components.values():
+ cpn["obj"]["params"]["custom_header"] = self.custom_header
+
+ component_params = self.validate_component_parameters(self.dsl)
for k, cpn in self.components.items():
- cpn_nms.add(cpn["obj"]["component_name"])
+ cpn["obj"] = component_class(cpn["obj"]["component_name"])(self, k, component_params[k])
+
+ self.path = self.dsl["path"]
+
+ @staticmethod
+ def validate_component_parameters(dsl):
+ component_params = {}
+ for k, cpn in dsl["components"].items():
param = component_class(cpn["obj"]["component_name"] + "Param")()
- cpn["obj"]["params"]["custom_header"] = self.custom_header
param.update(cpn["obj"]["params"])
try:
param.check()
except Exception as e:
- raise ValueError(self.get_component_name(k) + f": {e}")
-
- cpn["obj"] = component_class(cpn["obj"]["component_name"])(self, k, param)
-
- self.path = self.dsl["path"]
+ raise ValueError(Graph._get_component_name(dsl, k) + f": {e}")
+ component_params[k] = param
+ return component_params
def __str__(self):
self.dsl["path"] = self.path
@@ -175,12 +182,16 @@ class Graph:
except Exception:
pass
- def get_component_name(self, cid):
- for n in self.dsl.get("graph", {}).get("nodes", []):
+ @staticmethod
+ def _get_component_name(dsl, cid):
+ for n in dsl.get("graph", {}).get("nodes", []):
if cid == n["id"]:
return n["data"]["name"]
return ""
+ def get_component_name(self, cid):
+ return self._get_component_name(self.dsl, cid)
+
def run(self, **kwargs):
raise NotImplementedError()
diff --git a/api/apps/restful_apis/agent_api.py b/api/apps/restful_apis/agent_api.py
index c886ce6a6c..3b93217a6e 100644
--- a/api/apps/restful_apis/agent_api.py
+++ b/api/apps/restful_apis/agent_api.py
@@ -1177,7 +1177,10 @@ async def update_agent(agent_id, tenant_id):
if req.get("dsl") is not None:
try:
+ from agent.canvas import Canvas
+
req["dsl"] = CanvasReplicaService.normalize_dsl(req["dsl"])
+ Canvas.validate_component_parameters(req["dsl"])
except ValueError as exc:
return get_json_result(
data=False,