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 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23c9a86
 
 
 
 
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
# Table of Contents

* [Structure of ExtendLibraryFlow](#structure-of-extendlibraryflow)
* [SaveCodeAtomicFlow](#SaveCodeAtomicFlow)
  * [SaveCodeAtomicFlow](#SaveCodeAtomicFlow.SaveCodeAtomicFlow)
    * [run](#SaveCodeAtomicFlow.SaveCodeAtomicFlow.run)
* [ExtLibAskUserFlow](#ExtLibAskUserFlow)
  * [ExtLibAskUserFlow](#ExtLibAskUserFlow.ExtLibAskUserFlow)
    * [run](#ExtLibAskUserFlow.ExtLibAskUserFlow.run)
* [ExtendLibraryFlow](#ExtendLibraryFlow)
  * [ExtendLibraryFlow](#ExtendLibraryFlow.ExtendLibraryFlow)
    * [run](#ExtendLibraryFlow.ExtendLibraryFlow.run)
* [UpdatePlanAtomicFlow](#UpdatePlanAtomicFlow)
  * [UpdatePlanAtomicFlow](#UpdatePlanAtomicFlow.UpdatePlanAtomicFlow)
    * [run](#UpdatePlanAtomicFlow.UpdatePlanAtomicFlow.run)
* [run\_ExtendLibrary](#run_ExtendLibrary)
* [CtrlExMem\_ExtLib](#CtrlExMem_ExtLib)
  * [CtrlExMem\_ExtLib](#CtrlExMem_ExtLib.CtrlExMem_ExtLib)
    * [detect\_finish\_or\_continue](#CtrlExMem_ExtLib.CtrlExMem_ExtLib.detect_finish_or_continue)
* [ControllerFlow\_ExtLib](#ControllerFlow_ExtLib)
  * [ControllerFlow\_ExtLib](#ControllerFlow_ExtLib.ControllerFlow_ExtLib)
    * [\_\_init\_\_](#ControllerFlow_ExtLib.ControllerFlow_ExtLib.__init__)
    * [instantiate\_from\_config](#ControllerFlow_ExtLib.ControllerFlow_ExtLib.instantiate_from_config)
    * [run](#ControllerFlow_ExtLib.ControllerFlow_ExtLib.run)
* [\_\_init\_\_](#__init__)



# Structure of ExtendLibraryFlow

```
     goal, memory_files (dict)
             |
             v
    +-------------------+
    |  MemoryReading    |  Reads in the content of the memory files
    |    Flow           |
    +-------------------+
             |
             | (memory_content)
             |
             v
    +-------------------+
    |    PlanWriter     |  Writes a step-by-step plan to achieve the goal
    +-------------------+
             |
             | (plan)
             |
             v
    +-------------------+
    |   CtrlExMemFlow   |  Illustrated below. Carries out the plan in an controller-executor fashion,
    |                   |  with memory management mechanisms.
    +-------------------+
             |
    (summary, result)

```

Here is the structure of the `CtrlExMemFlow`:
```
    plan, memory_files, memory_content, goal
                |
                v
        +---------------+
        |  Controller   | --------<<<<-----------+
        +---------------+                        |
                |                                |
                | (command, command args)        |
                |                                |
                v                                |
        +------------------+                     |
        |   Executor       |  Each branch is an  |
        | (Tree Structure) |  executor           |
        +------------------+                     |
                |                                ^
                | (execution results)            ^
                |                                ^
                v                                ^
        +---------------+                        ^
        | MemWriteFlow  |  Updates memory files  ^
        +---------------+                        ^
                |                                ^
                | (summary)                      |
                |                                |
                v                                |
        +---------------+                        |
        | MemReadFlow   |  Reads updated memory  |
        +---------------+                        |
                |                                |
                | (updated memory content)       |
                |                                |
                +-> goes back to the Controller>-+

```
Structure of the Executors:
```
                 +-------------------+
                 |   Branching       |
                 |    Executor       |
                 +-------------------+
        /          |     |          |      \
       /           |     |          |       \
      /            |     |          |        \
     /             |     |          |         \
write_code    ask_user re_plan update_plan   save_code

```

Memory files of ExtendLibraryFlow:
- `plan_extlib.txt`
- `logs_extlib.txt`
- `library.py`

About the branches:
- [write_code](https://huggingface.co/aiflows/CodeWriterFlowModule): Generates code in an interactive way, the user is able to edit or provide feedback during the process of writing code.
- [ask_user](https://huggingface.co/aiflows/ExtendLibraryFlowModule/blob/main/ExtLibAskUserFlow.py): Ask user for info / confirmation, etc.
- [re_plan](https://huggingface.co/aiflows/ReplanningFlowModule): One branch of the executors, when something goes wrong, re-draft the plan.
- [update_plan](https://huggingface.co/aiflows/JarvisFlowModule/blob/main/UpdatePlanAtomicFlow.py): One branch of the executors, when the controller realizes that one (or some, depending on the LLM's response) step of the plan is (are) done, it generates a new plan that marks the step(s) as done.
- [save_code](https://huggingface.co/aiflows/ExtendLibraryFlowModule/blob/main/SaveCodeAtomicFlow.py): Writes the written & tested code to the code library.




<a id="SaveCodeAtomicFlow"></a>

# SaveCodeAtomicFlow

<a id="SaveCodeAtomicFlow.SaveCodeAtomicFlow"></a>

## SaveCodeAtomicFlow Objects

```python
class SaveCodeAtomicFlow(AtomicFlow)
```

This flow appends the code to the code library file.

*Input Interface*:
- `code` (str): the code to be appended to the code library
- `memory_files` (dict): the dictionary of memory files

*Output Interface*:
- `result` (str): the result of the flow, to be returned to the controller of the caller
- `summary` (str): the summary of the flow, to be appended to logs

*Configuration Parameters*:
- `input_interface`: the input interface of the flow
- `output_interface`: the output interface of the flow

<a id="SaveCodeAtomicFlow.SaveCodeAtomicFlow.run"></a>

#### run

```python
def run(input_data: Dict[str, Any])
```

Run the flow

**Arguments**:

- `input_data` (`dict`): the input data

**Returns**:

`dict`: the output data

<a id="ExtLibAskUserFlow"></a>

# ExtLibAskUserFlow

<a id="ExtLibAskUserFlow.ExtLibAskUserFlow"></a>

## ExtLibAskUserFlow Objects

```python
class ExtLibAskUserFlow(HumanStandardInputFlow)
```

This class is used to ask for user feedback whenever the controller is unsure of something, or need confirmation, etc.

*Input Interface*:
- `question`: The question asked by the controller

*Expected Behaviour*:
- The question is displayed, and the user gives feedback by input string.

*Output Interface*:
- `result`: The input of the user.
- `summary`: The summary that will be written by the caller.

*Configuration Parameters*:
- `query_message_prompt_template`: The template of the message that is displayed to the user.
- `request_multi_line_input`: Whether the user should be able to input multiple lines. Default: False.
- `end_of_input_string`: The string that the user can input to indicate that he/she is done with the input. Default: EOI

<a id="ExtLibAskUserFlow.ExtLibAskUserFlow.run"></a>

#### run

```python
def run(input_data: Dict[str, Any]) -> Dict[str, Any]
```

Run the flow module.

**Arguments**:

- `input_data` (`Dict[str, Any]`): The input data.

**Returns**:

`Dict[str, Any]`: The output data.

<a id="ExtendLibraryFlow"></a>

# ExtendLibraryFlow

<a id="ExtendLibraryFlow.ExtendLibraryFlow"></a>

## ExtendLibraryFlow Objects

```python
class ExtendLibraryFlow(AbstractBossFlow)
```

ExtendLibraryFlow is one branch executor of CoderFlow. At a higher level, it takes the goal
from the Coder, writes functions in an interactive way, test the code and append the newly written function to
the code library.

Workflow of ExtendLibrary:
0. Coder calls ExtendLibrary with a goal.
1. MemoryReading reads logs, plan, and code library.
2. Planner makes a plan based on the goal.
3. Write code in an interactive fashion.
4. Test code.
5. Finish, writes code to the library.
Step 3-5 is done via prompting the controller.

ExtendLibraryFlow inherits from AbstractBossFlow, visit https://huggingface.co/aiflows/AbstractBossFlowModule/

*Input Interface (expected input)*
- `goal` (str): The goal from the caller (source flow, i.e. CoderFlow)

*Output Interface (expected output)*
- `result` (str): The result of the flow, the result will be returned to the caller (i.e. CoderFlow).
- `summary` (str): The summary of the flow, the summary will be logged into the logs of the caller flow (i.e. CoderFlow).

*Configuration Parameters*:
- `memory_files`: The memory files to be read by the flow. By convention, the memory files should contain plan, logs, and code library.
- `input_interface`: The input interface of the flow. By default, they should be `goal`.
- `output_interface`: The output interface of the flow. By default, they should be `result` and `summary`.
- `subflows_config`: Configurations w/ the subflows.

<a id="ExtendLibraryFlow.ExtendLibraryFlow.run"></a>

#### run

```python
def run(input_data: Dict[str, Any]) -> Dict[str, Any]
```

Run the flow.

**Arguments**:

- `input_data` (`Dict[str, Any]`): The input data of the flow.

**Returns**:

`Dict[str, Any]`: The output data of the flow.

<a id="UpdatePlanAtomicFlow"></a>

# UpdatePlanAtomicFlow

<a id="UpdatePlanAtomicFlow.UpdatePlanAtomicFlow"></a>

## UpdatePlanAtomicFlow Objects

```python
class UpdatePlanAtomicFlow(AtomicFlow)
```

Refer to: https://huggingface.co/aiflows/CoderFlowModule/blob/main/UpdatePlanAtomicFlow.py
This flow updates the plan file with the updated plan.

*Input Interface*:
- `updated_plan` (str): the updated plan

*Output Interface*:
- `result` (str): the result of the flow, to be returned to the controller of the caller

*Configuration Parameters*:
- `input_interface`: the input interface of the flow
- `output_interface`: the output interface of the flow

<a id="UpdatePlanAtomicFlow.UpdatePlanAtomicFlow.run"></a>

#### run

```python
def run(input_data: Dict[str, Any])
```

Run the flow

**Arguments**:

- `input_data` (`dict`): the input data

**Returns**:

`dict`: the output data

<a id="run_ExtendLibrary"></a>

# run\_ExtendLibrary

<a id="CtrlExMem_ExtLib"></a>

# CtrlExMem\_ExtLib

<a id="CtrlExMem_ExtLib.CtrlExMem_ExtLib"></a>

## CtrlExMem\_ExtLib Objects

```python
class CtrlExMem_ExtLib(CtrlExMemFlow)
```

This class inherits from the CtrlExMemFlow class from AbstractBossFlowModule.

See: https://huggingface.co/aiflows/AbstractBossFlowModule/blob/main/CtrlExMemFlow.py

*Input Interface*:
- `plan`
- `logs`
- `memory_files`
- `goal`

*Output Interface*
- `result` (str): The result of the flow, the result will be returned to the caller.
- `summary` (str): The summary of the flow, the summary will be logged into the logs of the caller flow.

<a id="CtrlExMem_ExtLib.CtrlExMem_ExtLib.detect_finish_or_continue"></a>

#### detect\_finish\_or\_continue

```python
@CircularFlow.output_msg_payload_processor
def detect_finish_or_continue(output_payload: Dict[str, Any],
                              src_flow) -> Dict[str, Any]
```

This method is called when the flow receives a message from the child flow.

**Arguments**:

- `output_payload` (`Dict[str, Any]`): The output payload of the child flow.
- `src_flow` (`AbstractBossFlowModule`): The child flow.

**Returns**:

`Dict[str, Any]`: The processed output payload.

<a id="ControllerFlow_ExtLib"></a>

# ControllerFlow\_ExtLib

<a id="ControllerFlow_ExtLib.ControllerFlow_ExtLib"></a>

## ControllerFlow\_ExtLib Objects

```python
class ControllerFlow_ExtLib(ChatAtomicFlow)
```

Refer to: https://huggingface.co/aiflows/JarvisFlowModule/blob/main/Controller_JarvisFlow.py for a detailed doc.
This flow inherits from ChatAtomicFlow and is used as a controller of the ExtendLibraryFlow.

*Input Interface Non Initialized*:
- `goal`
- `memory_files`
- `plan`
- `logs`

*Input Interface Initialized*:
- `goal`
- `memory_files`
- `plan`
- `logs`
- `result`

*Output Interface*:
- `command`
- `command_args`

*Configuration Parameters*:
- `input_interface_non_initialized`: a list of input interface names when the conversation starts.
- `input_interface_initialized`: a list of input interface names when the conversation is initialized.
- `output_interface`: the output of the controller, it is the command and the command arguments.
- `commands`: a list of commands that the controller can call. Each command has a name, a description, and a list of input arguments.
- `system_message_prompt_template`: the system message prompt template.
- `init_human_message_prompt_template`: the initial human (user) message prompt template.
- `human_message_prompt_template`: the human (user) message prompt template.
- `previous_messages`: the sliding window of previous messages.

<a id="ControllerFlow_ExtLib.ControllerFlow_ExtLib.__init__"></a>

#### \_\_init\_\_

```python
def __init__(commands: List[Command], **kwargs)
```

The constructor of the ControllerFlow_ExtLib class.

**Arguments**:

- `commands`: a list of commands that the controller can call. Each command has a name, a description, and a list of input arguments.
- `kwargs`: the configuration parameters of the ControllerFlow_ExtLib class.

<a id="ControllerFlow_ExtLib.ControllerFlow_ExtLib.instantiate_from_config"></a>

#### instantiate\_from\_config

```python
@classmethod
def instantiate_from_config(cls, config)
```

Instantiate the flow from a configuration.

**Arguments**:

- `config` (`Dict[str, Any]`): the configuration.

**Returns**:

`ControllerFlow_ExtLib`: the instantiated flow.

<a id="ControllerFlow_ExtLib.ControllerFlow_ExtLib.run"></a>

#### run

```python
def run(input_data: Dict[str, Any]) -> Dict[str, Any]
```

Run the flow.

**Arguments**:

- `input_data` (`Dict[str, Any]`): the input data.

**Returns**:

`Dict[str, Any]`: the output of the flow.

<a id="__init__"></a>

# \_\_init\_\_