Hierarchical Agent Systems
Hierarchical systems mirror organizational structures for complex task management.
Task
Implement a 3-level hierarchy:
- Strategic (L0): Goal decomposition into high-level tasks.
- Tactical (L1): Break strategic tasks into actionable plans.
- Operational (L2): Execute individual actions.
Task Requirements:
- Strategic agent decomposes goal → L1 tasks.
- Tactical agent plans each L1 task → L2 tasks.
- Operational agents execute L2 tasks in parallel.
- Results bubble up the hierarchy.
Constraints
- Each level only communicates with adjacent levels.
- Failed L2 tasks must propagate to L1 for replanning.
- Return complete task tree with results.
Examples
Example 1:
Input:
system.run('Create a marketing campaign')Output:
{'status': 'complete', 'strategic_tasks': 2, 'tactical_tasks': 6, 'operational_tasks': 18, 'results': {...}}Explanation: Goal decomposed across 3 levels; all executed and results aggregated.
Starter Code
from typing import List, Dict, Any, Optional
from dataclasses import dataclass, field
@dataclass
class HierarchicalTask:
task_id: str
description: str
level: int # 0=strategic, 1=tactical, 2=operational
parent_id: Optional[str] = None
children_ids: List[str] = field(default_factory=list)
agent_level: str = 'operational' # which level agent handles this
class StrategicAgent: # Level 0 - big picture
def decompose(self, goal: str) -> List[HierarchicalTask]:
pass
class TacticalAgent: # Level 1 - planning
def plan(self, tasks: List[HierarchicalTask]) -> List[HierarchicalTask]:
pass
class OperationalAgent: # Level 2 - execution
def execute(self, task: HierarchicalTask) -> Dict:
pass
class HierarchicalAgentSystem:
def __init__(self, strategic, tactical, operational):
self.strategic = strategic
self.tactical = tactical
self.operational = operational
self.task_tree: Dict[str, HierarchicalTask] = {}
def run(self, goal: str) -> Dict:
pass
Python3
ReadyLines: 1Characters: 0
Ready