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 = {}