pull/766/merge
nathanogaga118 6 months ago committed by GitHub
commit 346701153a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

File diff suppressed because it is too large Load Diff

@ -97,11 +97,16 @@ class AgentRegistry:
agent (Agent): The agent to add. agent (Agent): The agent to add.
Raises: Raises:
ValueError: If the agent_name already exists in the registry. ValueError: If the agent_name already exists in the registry or is invalid.
ValidationError: If the input data is invalid. ValidationError: If the input data is invalid.
""" """
name = agent.agent_name name = agent.agent_name
# Input validation for agent_name
if not name or not isinstance(name, str):
logger.error("Invalid agent name provided.")
raise ValueError("Invalid agent name provided.")
self.agent_to_py_model(agent) self.agent_to_py_model(agent)
with self.lock: with self.lock:
@ -242,7 +247,7 @@ class AgentRegistry:
with self.lock: with self.lock:
agents = list(self.agents.values()) agents = list(self.agents.values())
logger.info("Returning all agents.") logger.info("Returning all agents.")
return agents returnagents
except Exception as e: except Exception as e:
logger.error(f"Error: {e}") logger.error(f"Error: {e}")
raise e raise e

@ -45,6 +45,11 @@ def parse_code_completion(agent_response, question):
Returns: Returns:
tuple: A tuple containing the parsed Python code and a boolean indicating success. tuple: A tuple containing the parsed Python code and a boolean indicating success.
""" """
# Input validation
if not isinstance(agent_response, str) or not isinstance(question, str):
logger.error("Invalid inputs provided to parse_code_completion.")
return "", False
python_code = extract_last_python_code_block(agent_response) python_code = extract_last_python_code_block(agent_response)
if python_code is None: if python_code is None:
if agent_response.count("impl]") == 0: if agent_response.count("impl]") == 0:
@ -117,7 +122,7 @@ class MajorityVoting:
agents (list): A list of agents to be used in the majority voting system. agents (list): A list of agents to be used in the majority voting system.
output_parser (function, optional): A function used to parse the output of the agents. output_parser (function, optional): A function used to parse the output of the agents.
If not provided, the default majority voting function is used. If not provided, the default majority voting function is used.
autosave (bool, optional): A boolean indicating whether to autosave the conversation to a file. autosave (bool, optional ): A boolean indicating whether to autosave the conversation to a file.
verbose (bool, optional): A boolean indicating whether to enable verbose logging. verbose (bool, optional): A boolean indicating whether to enable verbose logging.
Examples: Examples:
>>> from swarms.structs.agent import Agent >>> from swarms.structs.agent import Agent
@ -181,6 +186,11 @@ class MajorityVoting:
List[Any]: The majority vote. List[Any]: The majority vote.
""" """
# Input validation
if not isinstance(task, str) or not task.strip():
logger.error("Invalid task provided to run.")
return []
# Route to each agent # Route to each agent
with concurrent.futures.ThreadPoolExecutor() as executor: with concurrent.futures.ThreadPoolExecutor() as executor:
logger.info("Running agents concurrently") logger.info("Running agents concurrently")

Loading…
Cancel
Save