diff --git a/playground/structs/agent_rearrange.py b/playground/structs/agent_rearrange.py new file mode 100644 index 00000000..87d8eb2b --- /dev/null +++ b/playground/structs/agent_rearrange.py @@ -0,0 +1,73 @@ +from swarms import Agent, AgentRearrange, rearrange, Anthropic + + + +# Initialize the director agent + +director = Agent( + agent_name="Director", + system_prompt="Directs the tasks for the workers", + llm=Anthropic(), + max_loops=1, + dashboard=False, + streaming_on=True, + verbose=True, + stopping_token="", + state_save_file_type="json", + saved_state_path="director.json", +) + + +# Initialize worker 1 + +worker1 = Agent( + agent_name="Worker1", + system_prompt="Generates a transcript for a youtube video on what swarms are", + llm=Anthropic(), + max_loops=1, + dashboard=False, + streaming_on=True, + verbose=True, + stopping_token="", + state_save_file_type="json", + saved_state_path="worker1.json", +) + + +# Initialize worker 2 +worker2 = Agent( + agent_name="Worker2", + system_prompt="Summarizes the transcript generated by Worker1", + llm=Anthropic(), + max_loops=1, + dashboard=False, + streaming_on=True, + verbose=True, + stopping_token="", + state_save_file_type="json", + saved_state_path="worker2.json", +) + + +# Create a list of agents +agents = [director, worker1, worker2] + +# Define the flow pattern +flow = "Director -> Worker1 -> Worker2" + +# Using AgentRearrange class +agent_system = AgentRearrange(agents=agents, flow=flow) +output = agent_system.run( + "Create a format to express and communicate swarms of llms in a structured manner for youtube" +) +print(output) + + +# Using rearrange function +output = rearrange( + agents, + flow, + "Create a format to express and communicate swarms of llms in a structured manner for youtube", +) + +print(output) diff --git a/pyproject.toml b/pyproject.toml index 045b134e..7440fe33 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "swarms" -version = "4.9.8" +version = "5.0.0" description = "Swarms - Pytorch" license = "MIT" authors = ["Kye Gomez "] diff --git a/swarms/__init__.py b/swarms/__init__.py index 2fea14ee..23b8d3d5 100644 --- a/swarms/__init__.py +++ b/swarms/__init__.py @@ -13,4 +13,4 @@ from swarms.prompts import * # noqa: E402, F403 from swarms.structs import * # noqa: E402, F403 from swarms.telemetry import * # noqa: E402, F403 from swarms.tools import * # noqa: E402, F403 -from swarms.utils import * # noqa: E402, F403 \ No newline at end of file +from swarms.utils import * # noqa: E402, F403 diff --git a/swarms/structs/__init__.py b/swarms/structs/__init__.py index 0707263e..63304194 100644 --- a/swarms/structs/__init__.py +++ b/swarms/structs/__init__.py @@ -155,5 +155,5 @@ __all__ = [ "pydantic_type_to_yaml_schema", "YamlModel", "MessagePool", - "rearrange" + "rearrange", ] diff --git a/swarms/structs/agent.py b/swarms/structs/agent.py index 629ca0f8..0156e9a4 100644 --- a/swarms/structs/agent.py +++ b/swarms/structs/agent.py @@ -314,11 +314,10 @@ class Agent: self.execute_tool = execute_tool self.planning = planning self.planning_prompt = planning_prompt - + + # Name self.name = agent_name - - # Description self.description = agent_description # Agentic stuff self.reply = "" @@ -334,14 +333,6 @@ class Agent: if self.multi_modal: self.sop = MULTI_MODAL_AUTO_AGENT_SYSTEM_PROMPT_1 - # If the user inputs a list of strings for the sop then join them and set the sop - if self.sop_list: - self.sop = "\n".join(self.sop_list) - self.short_memory.add(role=self.user_name, content=self.sop) - - if self.sop is not None: - self.short_memory.add(role=self.user_name, content=self.sop) - # Memory self.feedback = [] @@ -451,7 +442,7 @@ class Agent: # Add the tool schema to the short memory logger.info("Adding tool schema to short memory") self.short_memory.add( - role=self.user_name, content=tool_schema_str + role=self.user_name, content=tool_schemas ) # If the algorithm of thoughts is enabled then set the sop to the algorithm of thoughts @@ -466,6 +457,15 @@ class Agent: logger.info(f"Beginning of Agent {self.agent_name} History") logger.info(self.short_memory.return_history_as_string()) logger.info(f"End of Agent {self.agent_name} History") + + # If the user inputs a list of strings for the sop then join them and set the sop + if self.sop_list: + self.sop = "\n".join(self.sop_list) + self.short_memory.add(role=self.user_name, content=self.sop) + + if self.sop is not None: + self.short_memory.add(role=self.user_name, content=self.sop) + def set_system_prompt(self, system_prompt: str): """Set the system prompt"""