Implement a coordinator agent for multi-agent systems:
register_specialist(name, capabilities, agent_fn): Add specialist- capabilities: list of strings (e.g., ['math', 'code'])
route_task(task_description): Select best specialist- Match task keywords to capabilities
- Return confidence score and rationale
coordinate(complex_task): Orchestrate multiple specialists- Split task by 'and', 'then'
- Route each to appropriate specialist
- Aggregate results
Routing Logic: Score = count of overlapping keywords between task and capabilities
Coordination: Execute subtasks sequentially, pass context between them.
Examples
Example 1:
Input:
coord = CoordinatorAgent(); coord.register_specialist('math', ['math', 'calc'], lambda x: x); r = coord.route_task('calculate 2+2'); r['specialist']Output:
'math'Explanation: Task contains 'calculate', matches math capability
Starter Code
class CoordinatorAgent:
"""
Coordinator agent that manages multiple specialist agents.
"""
def __init__(self):
self.specialists = {} # name -> agent_config
self.task_history = []
def register_specialist(self, name, capabilities, agent_fn):
"""Register a specialist agent"""
# Your implementation here
pass
def route_task(self, task_description):
"""
Route task to most appropriate specialist.
Returns {'specialist': name, 'confidence': float, 'rationale': str}
"""
# Your implementation here
pass
def coordinate(self, complex_task):
"""
Break complex task and coordinate specialists.
Returns {'subtasks': [...], 'results': {...}, 'integrated_result': ...}
"""
# Your implementation here
pass
def _match_capabilities(self, task, capabilities):
"""Score how well capabilities match task"""
# Your implementation here
passPython3
ReadyLines: 1Characters: 0
Ready