You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/concepts/tasks.mdx
+28-20Lines changed: 28 additions & 20 deletions
Original file line number
Diff line number
Diff line change
@@ -192,29 +192,38 @@ data_analysis_task = Task(
192
192
```
193
193
194
194
### Subtasks
195
+
Subtasks allow you to break down complex tasks into smaller steps and manage the workflow more effectively. Subtasks can be defined either by creating tasks with the context of another task, or by passing a task as a `parent` parameter to the subtask.
195
196
196
-
Subtasks can be defined using the `subtasks` property of the `Task` class. By organizing tasks into subtasks, you can break down complex tasks into smaller, more focused units of work.
197
+
<CodeGroup>
198
+
```python Context manager
199
+
from controlflow import Task
197
200
198
-
```python
199
-
data_processing_task = Task(
200
-
objective="Process the raw data and prepare it for analysis",
201
-
subtasks=[
202
-
Task(
203
-
objective="Load the raw data from the source",
204
-
result_type=pd.DataFrame,
205
-
),
206
-
Task(
207
-
objective="Clean and preprocess the loaded data",
208
-
result_type=pd.DataFrame,
209
-
),
210
-
Task(
211
-
objective="Perform feature engineering on the preprocessed data",
212
-
result_type=pd.DataFrame,
213
-
),
214
-
],
215
-
result_type=pd.DataFrame,
201
+
with Task(objective="Prepare data", result_type=list) as parent_task:
202
+
child_task_1 = Task('Load data from the source', result_type=list)
Copy file name to clipboardExpand all lines: docs/reference/task-class.mdx
+3-5Lines changed: 3 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -70,10 +70,8 @@ Dependencies are defined as a list of `Task` instances. When a task is executed,
70
70
By specifying dependencies, you can create a structured workflow where tasks are executed in a specific order based on their dependencies. This helps ensure that tasks have access to the necessary data or results from previous tasks before they start.
71
71
</ParamField>
72
72
73
-
<ParamFieldpath="subtasks"type="list[Task]">
74
-
The `subtasks` property allows you to define a hierarchical structure of tasks by specifying subtasks for a given task. Subtasks are smaller, more focused tasks that contribute to the completion of the parent task.
73
+
<ParamFieldpath="parent"type="Optional[Task]">
74
+
The `parent` property allows you to specify a parent task for the current task. It establishes a hierarchical relationship between tasks, where the parent task is responsible for managing and coordinating the execution of its child tasks.
75
75
76
-
Subtasks are defined as a list of `Task` instances. When a task is executed, its subtasks are also executed as part of the overall task execution process. The parent task is considered complete only when all its subtasks have been successfully completed.
77
-
78
-
By organizing tasks into subtasks, you can break down complex tasks into smaller, more manageable units of work. This promotes modularity, reusability, and easier maintenance of the task hierarchy.
76
+
By organizing tasks into subtasks, you can break down complex tasks into smaller, more manageable units of work. This promotes modularity, reusability, and easier maintenance of the task hierarchy. When a task is created with a parent task, it automatically becomes a subtask of the parent task. The parent task is considered complete only when all its subtasks have been successfully completed.
0 commit comments