Break complex or open-ended tasks into smaller, manageable steps.
When you run a parent task, all of its subtasks are automatically executed because they become dependencies of the parent. You don’t need to also explicitly run the subtasks or return them from the flow.
Creating Subtasks with Context Managers
One way to create subtasks is by using a context manager. This approach allows you to dynamically generate and execute subtasks within the scope of a parent task.Creating Subtasks Imperatively
You can also create subtasks imperatively by passing the parent task as an argument when creating a new task.Generating Subtasks Automatically
For more complex scenarios where you need to automatically generate subtasks based on the parent task’s objective, ControlFlow provides agenerate_subtasks()
method. This powerful feature allows for dynamic task planning and is especially useful for breaking down complex tasks into more manageable steps.
For more information on how to use generate_subtasks()
, please refer to the Task Planning pattern.