File size: 6,146 Bytes
d8d14f1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# BaseWorkflow

The `BaseWorkflow` class serves as a foundational structure for defining and managing workflows. It allows users to add, remove, update, and manage tasks and agents within a workflow, offering flexibility and extensibility for various applications.

### Key Concepts

- **Agents**: Entities participating in the workflow.
- **Tasks**: Units of work to be executed within the workflow.
- **Models**: Computational models used within the workflow.
- **Workflow State**: The state of the workflow, which can be saved and restored.

## Attributes

### Arguments

| Argument | Type | Default | Description |
|----------|------|---------|-------------|
| `agents` | `List[Agent]` | `None` | A list of agents participating in the workflow. |
| `task_pool` | `List[Task]` | `None` | A list of tasks in the workflow. |
| `models` | `List[Any]` | `None` | A list of models used in the workflow. |
| `*args` | | | Variable length argument list. |
| `**kwargs` | | | Arbitrary keyword arguments. |

### Attributes

| Attribute | Type | Description |
|-----------|------|-------------|
| `agents` | `List[Agent]` | A list of agents participating in the workflow. |
| `task_pool` | `List[Task]` | A list of tasks in the workflow. |
| `models` | `List[Any]` | A list of models used in the workflow. |

## Methods

### add_task

Adds a task or a list of tasks to the task pool.

**Arguments:**

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `task` | `Task` | `None` | A single task to add. |
| `tasks` | `List[Task]` | `None` | A list of tasks to add. |

**Raises:**

- `ValueError`: If neither task nor tasks are provided.

**Examples:**

```python
workflow = BaseWorkflow()
task1 = Task(description="Task 1")
task2 = Task(description="Task 2")

# Adding a single task
workflow.add_task(task=task1)

# Adding multiple tasks
workflow.add_task(tasks=[task1, task2])
```

### add_agent

Adds an agent to the workflow.

**Arguments:**

| Parameter | Type | Description |
|-----------|------|-------------|
| `agent` | `Agent` | The agent to add to the workflow. |

**Examples:**

```python
workflow = BaseWorkflow()
agent = Agent(name="Agent 1")

# Adding an agent to the workflow
workflow.add_agent(agent=agent)
```

### run

Abstract method to run the workflow.

### __sequential_loop

Abstract method for the sequential loop.

### __log

Logs a message if verbose mode is enabled.

**Arguments:**

| Parameter | Type | Description |
|-----------|------|-------------|
| `message` | `str` | The message to log. |

### __str__

Returns a string representation of the workflow.

### __repr__

Returns a string representation of the workflow for debugging.

### reset

Resets the workflow by clearing the results of each task.

**Examples:**

```python
workflow = BaseWorkflow()
workflow.reset()
```

### get_task_results

Returns the results of each task in the workflow.

**Returns:**

| Return Type | Description |
|-------------|-------------|
| `Dict[str, Any]` | The results of each task in the workflow. |

**Examples:**

```python
workflow = BaseWorkflow()
results = workflow.get_task_results()
```

### remove_task

Removes a task from the workflow.

**Arguments:**

| Parameter | Type | Description |
|-----------|------|-------------|
| `task` | `str` | The description of the task to remove. |

**Examples:**

```python
workflow = BaseWorkflow()
workflow.remove_task(task="Task 1")
```

### update_task

Updates the arguments of a task in the workflow.

**Arguments:**

| Parameter | Type | Description |
|-----------|------|-------------|
| `task` | `str` | The description of the task to update. |
| `**updates` | | The updates to apply to the task. |

**Raises:**

- `ValueError`: If the task is not found in the workflow.

**Examples:**

```python
workflow = BaseWorkflow()
task = Task(description="Task 1", kwargs={"param": 1})

# Adding a task to the workflow
workflow.add_task(task=task)

# Updating the task
workflow.update_task("Task 1", param=2)
```

### delete_task

Deletes a task from the workflow.

**Arguments:**

| Parameter | Type | Description |
|-----------|------|-------------|
| `task` | `str` | The description of the task to delete. |

**Raises:**

- `ValueError`: If the task is not found in the workflow.

**Examples:**

```python
workflow = BaseWorkflow()
task = Task(description="Task 1")

# Adding a task to the workflow
workflow.add_task(task=task)

# Deleting the task
workflow.delete_task("Task 1")
```

### save_workflow_state

Saves the workflow state to a json file.

**Arguments:**

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `filepath` | `Optional[str]` | `"sequential_workflow_state.json"` | The path to save the workflow state to. |

**Examples:**

```python
workflow = BaseWorkflow()
workflow.save_workflow_state(filepath="workflow_state.json")
```

### add_objective_to_workflow

Adds an objective to the workflow.

**Arguments:**

| Parameter | Type | Description |
|-----------|------|-------------|
| `task` | `str` | The description of the task. |
| `**kwargs` | | Additional keyword arguments for the task. |

**Examples:**

```python
workflow = BaseWorkflow()
workflow.add_objective_to_workflow(task="New Objective", agent=agent, args=[], kwargs={})
```

### load_workflow_state

Loads the workflow state from a json file and restores the workflow state.

**Arguments:**

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `filepath` | `str` | `None` | The path to load the workflow state from. |

**Examples:**

```python
workflow = BaseWorkflow()
workflow.load_workflow_state(filepath="workflow_state.json")
```

### workflow_dashboard

Displays a dashboard for the workflow.

**Arguments:**

| Parameter | Type | Description |
|-----------|------|-------------|
| `**kwargs` | | Additional keyword arguments to pass to the dashboard. |

**Examples:**

```python
workflow = BaseWorkflow()
workflow.workflow_dashboard()
```

### workflow_bootup

Initializes the workflow.

**Examples:**

```python
workflow = BaseWorkflow()
workflow.workflow_bootup()
```