---
title: Planning
---

<Tip>
Automatically generate subtasks to break complex tasks into manageable steps.
</Tip>

ControlFlow has many features that help you structure your AI workflows into small, well-defined tasks. However, sometimes it will be impractical or even impossible to identify all the necessary tasks upfront. In these cases, you can use ControlFlow's planning capabilities to automatically generate subtasks based on the main task's objective.

By calling the `generate_subtasks()` method on a task, you can instruct an AI agent to come up with a plan for achieving the main task. The agent will generate a series of subtasks, each representing a step in the plan, and set up the necessary dependencies between them.



```python
import controlflow as cf

task = cf.Task(
    objective="Compare the height of the tallest building "
    "in North America to the tallest building in Europe",
)

task.generate_subtasks()

print([f'{i+1}: {t.objective}' for i, t in enumerate(task.subtasks)])
```

Running the above code will print something like:

```python
[
    "1: Identify the Tallest Building in North America",
    "2: Identify the Tallest Building in Europe",
    "3: Obtain Height of the Tallest Building in North America",
    "4: Obtain Height of the Tallest Building in Europe",
    "5: Compare the Heights",
]
 ```
If you investigate more closely, you'll see that the subtasks have proper dependencies. In the above example, #3 depends on #1, #4 depends on #2, and #5 depends on #3 and #4. And of course, the parent task depends on all of them. 

ControlFlow's orchestration engine will not allow the parent task to be considered complete until all of its subtasks have been successfully executed, which is why this is an effective way to structure complex workflows.

<Tip>
Subtask generation isn't magic: it's a ControlFlow flow!
</Tip>

## Customizing subtask generation
You can influence subtask generation in a few ways.

### Planning agent

By default, subtasks are generated by the first agent assigned to the parent task. You can customize this by passing an `agent` argument to `generate_subtasks()`.


### Instructions

You can provide natural language `instructions` to help the agent generate subtasks. This is especially useful when the task is ambiguous or requires domain-specific knowledge.
