Skip to content

Commit

Permalink
feat: agent order independence in config (#65)
Browse files Browse the repository at this point in the history
Co-authored-by: chenweize1998 <chenweize1998@gmail.com>
  • Loading branch information
1rubbishyuan and chenweize1998 authored Oct 16, 2023
1 parent 5292621 commit 5b5f7fe
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 3 additions & 3 deletions agentverse/tasksolving.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ def from_task(cls, task: str, tasks_dir: str):
# Build agents for all pipeline (task)
agents = {}
for i, agent_config in enumerate(task_config["agents"]):
agent_type = AGENT_TYPES(i)
if i == 2 and agent_config.get("agent_type", "") == "critic":
if agent_config.get("agent_type", "") == "critic":
agent = load_agent(agent_config)
agents[agent_type] = [
agents[AGENT_TYPES.CRITIC] = [
copy.deepcopy(agent)
for _ in range(task_config.get("cnt_agents", 1) - 1)
]
else:
agent_type = AGENT_TYPES.from_string(agent_config.get("agent_type", ""))
agents[agent_type] = load_agent(agent_config)

env_config["agents"] = agents
Expand Down
15 changes: 15 additions & 0 deletions agentverse/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@ class AGENT_TYPES(Enum):
EVALUATION = 4
MANAGER = 5

@staticmethod
def from_string(agent_type: str):
str_to_enum_dict = {
"role_assigner": AGENT_TYPES.ROLE_ASSIGNMENT,
"solver": AGENT_TYPES.SOLVER,
"critic": AGENT_TYPES.CRITIC,
"executor": AGENT_TYPES.EXECUTION,
"evaluator": AGENT_TYPES.EVALUATION,
"manager": AGENT_TYPES.MANAGER,
}
assert (
agent_type in str_to_enum_dict
), f"Unknown agent type: {agent_type}. Check your config file."
return str_to_enum_dict.get(agent_type.lower())


class Singleton(abc.ABCMeta, type):
"""
Expand Down

0 comments on commit 5b5f7fe

Please sign in to comment.