| 29 | |
| 30 | |
| 31 | class AssignmentConfig(BaseModel): |
| 32 | assignments: List[Assignment] |
| 33 | concurrency: ConcurrencyConfig |
| 34 | definition: DefinitionConfig |
| 35 | output: str = None |
| 36 | |
| 37 | @validator("assignments", pre=True) |
| 38 | def assignments_validation(cls, v): |
| 39 | assert isinstance(v, list), f"'assignments' must be a list, but got {type(v)}" |
| 40 | ret = [] |
| 41 | for item in v: |
| 42 | assert isinstance( |
| 43 | item, dict |
| 44 | ), f"Each item in 'assignments' must be a dict, but got {type(item)}" |
| 45 | agent = item.get("agent", None) |
| 46 | if agent is None: |
| 47 | raise ValueError("'agent' must be specified") |
| 48 | if isinstance(agent, str): |
| 49 | agent = [agent] |
| 50 | task = item.get("task") |
| 51 | if task is None: |
| 52 | raise ValueError("'task' must be specified") |
| 53 | if isinstance(task, str): |
| 54 | task = [task] |
| 55 | for a in agent: |
| 56 | for t in task: |
| 57 | ret.append(Assignment(agent=a, task=t)) |
| 58 | return ret |
| 59 | |
| 60 | @validator("output", pre=True) |
| 61 | def output_validation(cls, v): |
| 62 | predefined_structure = get_predefined_structure() |
| 63 | if v is None: |
| 64 | v = "output/{TIMESTAMP}" |
| 65 | assert isinstance(v, str), f"'output' must be a string, but got {type(v)}" |
| 66 | return v.format(**predefined_structure) |
| 67 | |
| 68 | @classmethod |
| 69 | def post_validate(cls, instance: "AssignmentConfig"): |
| 70 | |
| 71 | REMOVE_UNUSED_IN_DEFINITION = True |
| 72 | REMOVE_UNUSED_IN_CONCURRENCY = True |
| 73 | |
| 74 | # Step 1. Check if all agents and tasks are defined, and remove unused agents and tasks |
| 75 | |
| 76 | agent_in_assignment = set() |
| 77 | task_in_assignment = set() |
| 78 | for assignment in instance.assignments: |
| 79 | assert ( |
| 80 | assignment.agent in instance.definition.agent |
| 81 | ), f"Agent {assignment.agent} is not defined." |
| 82 | agent_in_assignment.add(assignment.agent) |
| 83 | assert ( |
| 84 | assignment.task in instance.definition.task |
| 85 | ), f"Task {assignment.task} is not defined." |
| 86 | task_in_assignment.add(assignment.task) |
| 87 | |
| 88 | for agent in agent_in_assignment: |
nothing calls this directly
no outgoing calls
no test coverage detected