From b978f94fa64fa19889eba7a6f4cb3e83b7847038 Mon Sep 17 00:00:00 2001 From: Wang Qi Date: Mon, 10 Aug 2026 20:02:24 +0800 Subject: [PATCH] Fix: restrict max_retries as non-negative integer (#18051) --- agent/component/base.py | 5 +++++ agent/component/llm.py | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/agent/component/base.py b/agent/component/base.py index 8c51d75550..6139ef14e9 100644 --- a/agent/component/base.py +++ b/agent/component/base.py @@ -260,6 +260,11 @@ class ComponentParamBase(ABC): if not param: raise ValueError(description + " does not support empty value.") + @staticmethod + def check_nonnegative_integer(param, description): + if type(param).__name__ not in ["int", "long"] or param < 0: + raise ValueError(description + " {} not supported, should be 0 or positive integer".format(param)) + @staticmethod def check_positive_integer(param, description): if type(param).__name__ not in ["int", "long"] or param <= 0: diff --git a/agent/component/llm.py b/agent/component/llm.py index cefe358709..1bb44f1319 100644 --- a/agent/component/llm.py +++ b/agent/component/llm.py @@ -58,6 +58,10 @@ class LLMParam(ComponentParamBase): self.check_decimal_float(float(self.top_p), "[Agent] Top P") self.check_empty(self.llm_id, "[Agent] LLM") self.check_empty(self.prompts, "[Agent] User prompt") + self.check_nonnegative_integer(self.max_retries, "[Agent] Max retries") + if hasattr(self, "max_rounds"): + self.check_defined_type(self.max_rounds, "[Agent] Max rounds", ["int"]) + self.check_nonnegative_number(self.max_rounds, "[Agent] Max rounds") def gen_conf(self): conf = {}