File tree 1 file changed +10
-2
lines changed
1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -137,8 +137,10 @@ def __init__(
137
137
)
138
138
139
139
self ._name = name
140
- if self ._name .isidentifier () is False :
141
- raise ValueError ("The agent name must be a valid Python identifier." )
140
+
141
+ if ConversableAgent ._validate_name (name ) is False :
142
+ raise ValueError (f"Invalid name: '{ name } '. Only letters, numbers, '_' and '-' are allowed." )
143
+
142
144
# a dictionary of conversations, default value is list
143
145
if chat_messages is None :
144
146
self ._oai_messages = defaultdict (list )
@@ -258,6 +260,12 @@ def __init__(
258
260
"a_process_message_before_send" : [],
259
261
}
260
262
263
+ @staticmethod
264
+ def _validate_name (name : str ) -> bool :
265
+ """Validate the name of the agent."""
266
+ pattern = r'^[a-zA-Z0-9_-]+$'
267
+ return bool (re .match (pattern , name ))
268
+
261
269
def _validate_llm_config (self , llm_config ):
262
270
assert llm_config in (None , False ) or isinstance (
263
271
llm_config , dict
You can’t perform that action at this time.
0 commit comments