Skip to content

Commit

Permalink
Fix created agent paths in genesis #115
Browse files Browse the repository at this point in the history
  • Loading branch information
VRSEN committed Apr 30, 2024
1 parent acf3447 commit aa66218
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,18 @@ def run(self):

# # create or append to init file
path = self.shared_state.get("agency_path")
folder_name = self.agent_name.lower().replace(" ", "_")
class_name = self.agent_name.replace(" ", "").strip()
if not os.path.isfile("__init__.py"):
with open("__init__.py", "w") as f:
f.write(f"from .{folder_name} import {class_name}")
f.write(f"from .{class_name} import {class_name}")
else:
with open("__init__.py", "a") as f:
f.write(f"\nfrom .{folder_name} import {class_name}")
f.write(f"\nfrom .{class_name} import {class_name}")

# add agent on second line to agency.py
with open("agency.py", "r") as f:
lines = f.readlines()
lines.insert(1, f"from {self.agent_name} import {self.agent_name}\n")
lines.insert(1, f"from {class_name} import {class_name}\n")

with open("agency.py", "w") as f:
f.writelines(lines)
Expand Down
9 changes: 4 additions & 5 deletions agency_swarm/util/cli/create_agent_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@ def create_agent_template(agent_name=None,
agent_description = input("Enter agent description: ")

class_name = agent_name.replace(" ", "").strip()
folder_name = agent_name # .lower().replace(" ", "_").strip()

# create folder
path = os.path.join(path, folder_name) + "/"
path = os.path.join(path, class_name) + "/"
if os.path.isdir(path):
raise Exception("Folder already exists.")
os.mkdir(path)

# create agent file
with open(path + folder_name + ".py", "w") as f:
with open(path + class_name + ".py", "w") as f:
f.write(agent_template.format(
class_name=class_name,
agent_name=agent_name,
Expand All @@ -34,7 +33,7 @@ def create_agent_template(agent_name=None,
))

with open(path + "__init__.py", "w") as f:
f.write(f"from .{folder_name} import {class_name}")
f.write(f"from .{class_name} import {class_name}")

# create instructions file
instructions_path = "instructions.md" if not use_txt else "instructions.txt"
Expand All @@ -57,7 +56,7 @@ def create_agent_template(agent_name=None,
f.write(example_tool_template)

print("Agent folder created successfully.")
print(f"Import it with: from {folder_name} import {class_name}")
print(f"Import it with: from {class_name} import {class_name}")


agent_template = """from agency_swarm.agents import Agent
Expand Down

0 comments on commit aa66218

Please sign in to comment.