Skip to content

Commit

Permalink
Instantiate agents if they have not been initialized in agency chart
Browse files Browse the repository at this point in the history
  • Loading branch information
VRSEN committed Sep 2, 2024
1 parent 2107467 commit 4a674d6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 10 additions & 0 deletions agency_swarm/agency/agency.py
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,17 @@ def _parse_agency_chart(self, agency_chart):

if len(agency_chart) == 0:
raise Exception("Agency chart cannot be empty.")

# instantiate agents if they are classes
for i, node in enumerate(agency_chart):
if inspect.isclass(node) and issubclass(node, Agent):
agency_chart[i] = node()
elif isinstance(node, list):
for j, agent in enumerate(node):
if inspect.isclass(agent) and issubclass(agent, Agent):
node[j] = agent()

# add agents to the agency
for node in agency_chart:
if isinstance(node, Agent):
if not self.ceo:
Expand Down
6 changes: 2 additions & 4 deletions tests/test_agency.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,12 +345,10 @@ def test_6_load_from_db(self):
"type": "json_object",
}

ceo = CEO()

# check that agents are loaded
agency = Agency([
ceo,
[ceo, agent1],
CEO,
[CEO, agent1],
[agent1, agent2]],
shared_instructions="This is a shared instruction",
settings_path="./settings2.json",
Expand Down

0 comments on commit 4a674d6

Please sign in to comment.