Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check that agent name is valid #4158

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions autogen/agentchat/conversable_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ def __init__(
)

self._name = name

if ConversableAgent._validate_name(name) is False:
raise ValueError(f"Invalid name: '{name}'. Only letters, numbers, '_' and '-' are allowed.")

# a dictionary of conversations, default value is list
if chat_messages is None:
self._oai_messages = defaultdict(list)
Expand Down Expand Up @@ -256,6 +260,12 @@ def __init__(
"a_process_message_before_send": [],
}

@staticmethod
def _validate_name(name: str) -> bool:
"""Validate the name of the agent."""
pattern = r'^[a-zA-Z0-9_-]+$'
return bool(re.match(pattern, name))

def _validate_llm_config(self, llm_config):
assert llm_config in (None, False) or isinstance(
llm_config, dict
Expand Down
Loading