Skip to content

Commit 353bcf3

Browse files
authored
Merge pull request #56 from jlowin/tasks
Fix subtask docs
2 parents c80ef91 + 948e5e9 commit 353bcf3

File tree

2 files changed

+31
-25
lines changed

2 files changed

+31
-25
lines changed

docs/concepts/tasks.mdx

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -192,29 +192,38 @@ data_analysis_task = Task(
192192
```
193193

194194
### 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.
195196

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
197200

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)
203+
child_task_2 = Task(
204+
'Clean and preprocess the loaded data',
205+
result_type=list,
206+
context=dict(data=child_task_1),
207+
)
208+
```
209+
210+
```python Parent parameter
211+
from controlflow import Task
212+
213+
parent_task = Task(objective="Prepare data", result_type=list)
214+
child_task_1 = Task(
215+
'Load data from the source',
216+
result_type=list,
217+
parent=parent_task,
218+
)
219+
child_task_2 = Task(
220+
'Clean and preprocess the loaded data',
221+
result_type=list,
222+
context=dict(data=child_task_1),
223+
parent=parent_task,
216224
)
217225
```
226+
</CodeGroup>
218227

219228
## Executing Tasks
220229

@@ -223,7 +232,6 @@ Tasks can be executed using the `run()` method, which coordinates the execution
223232
```python
224233
data_processing_task = Task(
225234
objective="Process the raw data and prepare it for analysis",
226-
subtasks=[...],
227235
result_type=pd.DataFrame,
228236
)
229237

docs/reference/task-class.mdx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,8 @@ Dependencies are defined as a list of `Task` instances. When a task is executed,
7070
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.
7171
</ParamField>
7272

73-
<ParamField path="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+
<ParamField path="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.
7575

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.
7977
</ParamField>

0 commit comments

Comments
 (0)