Upstream dependencies
Upstream dependencies are the most straightforward way to specify that one task must wait for another to complete before it can begin. This is done using thedepends_on
parameter when creating a task.
analyze_sources
will not start until gather_sources
has completed successfully.
Subtasks
Subtasks create a hierarchical dependency structure. A parent task can not be completed until all of its subtasks have finished. This hierarchical structure enables you to create detailed, step-by-step workflows that an AI agent can follow, ensuring thorough and accurate task completion.Imperative creation
You can create subtasks imperatively by passing the parent task as an argument when creating a new task:Context managers
Another 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.Automatic Execution of Dependencies
A key feature of ControlFlow’s dependency management is that you don’t need to explicitly run dependent tasks. When you run a task, ControlFlow automatically executes all of its dependencies, including:- Tasks specified in the
depends_on
parameter - Subtasks (for parent tasks)
write_report
will automatically trigger the execution of analyze_sources
, which in turn will trigger gather_sources
. You don’t need to explicitly run or return gather_sources
or analyze_sources
.
To learn more, see running tasks.