Generate Deep Research tasks based on expert backgrounds.
| 17 | |
| 18 | |
| 19 | class TaskGenerator: |
| 20 | """Generate Deep Research tasks based on expert backgrounds.""" |
| 21 | |
| 22 | def __init__( |
| 23 | self, |
| 24 | api_client: APIClient, |
| 25 | cache_file: Optional[str] = None, |
| 26 | max_workers: int = 25, |
| 27 | ) -> None: |
| 28 | """ |
| 29 | Initialize the task generator. |
| 30 | |
| 31 | Args: |
| 32 | api_client: API client instance |
| 33 | cache_file: Cache file path |
| 34 | max_workers: Maximum parallel threads |
| 35 | """ |
| 36 | self.api_client = api_client |
| 37 | self.cache_file = cache_file |
| 38 | self.max_workers = max_workers |
| 39 | |
| 40 | def generate(self, experts: List[Dict[str, Any]]) -> List[Dict[str, Any]]: |
| 41 | """ |
| 42 | Generate tasks for all experts. |
| 43 | |
| 44 | Args: |
| 45 | experts: List of expert info |
| 46 | |
| 47 | Returns: |
| 48 | List of tasks, each containing expert and domain fields |
| 49 | """ |
| 50 | # Check cache |
| 51 | if self.cache_file: |
| 52 | cached = load_if_exists(self.cache_file, default=None) |
| 53 | if cached is not None: |
| 54 | logger.info(f"Using cached task data: {len(cached)} tasks") |
| 55 | return cached |
| 56 | |
| 57 | logger.info(f"Generating tasks in parallel ({len(experts)} experts)...") |
| 58 | |
| 59 | all_tasks: List[Dict[str, Any]] = [] |
| 60 | workers = min(self.max_workers, len(experts)) |
| 61 | |
| 62 | with ThreadPoolExecutor(max_workers=workers) as executor: |
| 63 | future_to_expert = { |
| 64 | executor.submit(self._generate_for_expert, expert): expert |
| 65 | for expert in experts |
| 66 | } |
| 67 | |
| 68 | completed = 0 |
| 69 | for future in as_completed(future_to_expert): |
| 70 | completed += 1 |
| 71 | expert = future_to_expert[future] |
| 72 | |
| 73 | try: |
| 74 | result = future.result() |
| 75 | if result: |
| 76 | all_tasks.extend(result) |
no outgoing calls
no test coverage detected