Skip to content

Commit

Permalink
Prevent genesis ceo from creating multiple agent folders #52
Browse files Browse the repository at this point in the history
  • Loading branch information
VRSEN committed Jan 31, 2024
1 parent 2c598e2 commit c8068fb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
2 changes: 1 addition & 1 deletion agency_swarm/agents/genesis/GenesisCEO/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
1. Pick a good name for the agency and communicate it to the user.
2. Ask user about their goals for this agency, its mission and its processes, like what APIs would the agents need to utilize.
3. Propose an initial structure for the agency, including the roles of the agents and their communication flows. Focus on creating at most 2 agents, plus CEO, unless instructed otherwise by the user. Output the code snippet like below.
4. Upon confirmation use `CreateAgencyFolder` tool to create a folder for the agency.
4. Upon confirmation use `CreateAgencyFolder` tool to create a folder for the agency. If any modifications are required please use this tool again with the same agency name and it will overwrite the existing folder.
5. Tell AgentCreator to create these agents one by one, starting with the CEO. Each agent should be sent in a separate message using the `SendMessage` tool. If one of the agents needs to utilize a specific API, as instructed by the user, please make sure to communicate this as well.
6. Once all agents are created, please use the `FinalizeAgency` tool, and tell the user that he can now navigate to the agency folder and start it with `python agency.py` command.

Expand Down
35 changes: 32 additions & 3 deletions agency_swarm/tools/genesis/CreateAgencyFolder.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
from pydantic import Field
import shutil

from pydantic import Field, field_validator

from agency_swarm import BaseTool

import os

current_agency_name = None

class CreateAgencyFolder(BaseTool):
"""
This tool creates an agency folder.
This tool creates or modifies an agency folder. You can use it again with the same agency_name to modify a previously created agency, if the user wants to change the agency chart or the manifesto.
"""
agency_name: str = Field(
..., description="Name of the agency to be created.",
Expand All @@ -24,14 +27,23 @@ class CreateAgencyFolder(BaseTool):

def run(self):
folder_path = "./" + self.agency_name + "/"

global current_agency_name
if current_agency_name is not None:
if os.getcwd().strip("/").strip("\\").endswith(current_agency_name):
os.chdir("..")
shutil.rmtree(current_agency_name)

current_agency_name = self.agency_name

# create folder
os.mkdir(folder_path)

os.chdir(folder_path)

# check that agency chart is valid
if not self.agency_chart.startswith("[") or not self.agency_chart.endswith("]"):
raise ValueError("Agency chart must be a list of lists.")
raise ValueError("Agency chart must be a list of lists, except for the first agents.")

# add new lines after every comma, except for those inside second brackets
# must transform from "[ceo, [ceo, dev], [ceo, va], [dev, va] ]"
Expand All @@ -56,4 +68,21 @@ def run(self):

return f"Agency folder has been created in {folder_path}."

@field_validator('agency_name', mode='after')
@classmethod
def check_agency_name(cls, v):
global current_agency_name

if os.path.exists("./" + v):
raise ValueError("Agency with this name already exists.")

if current_agency_name is not None:
if current_agency_name != v:
raise ValueError("You can only create 1 agency at a time. Please tell the user to restart the system if he wants to create a new agency or use the same agency_name to modify an exisiting agency.")

if not os.getcwd().strip("/").endswith(current_agency_name):
raise ValueError("Please tell the user to restart the system if he wants to create a new agency.")

return v


0 comments on commit c8068fb

Please sign in to comment.