Skip to content

< all problems50 · Level 05, Agents

Fan Out to Workers and Merge

medium · implement · Agents

Some tasks are several independent questions in one. Split the task, answer each piece on its own, then merge.

Implement orchestrate(llm, task, max_workers=4) returning {"subtasks": [...], "answer": str, "calls": int}.

  1. Plan. Ask the model to split task into independent subtasks, as a JSON list of strings. Cap at max_workers; if the reply is unparseable, treat the whole task as one subtask rather than failing.
  2. Work. Ask the model to do each subtask. One call each, no shared context between them.
  3. Merge. One final call with every worker's output, asking for a single combined answer.

calls must therefore be len(subtasks) + 2. The tests check that arithmetic against the model's own call count, so no extra calls.