File size: 7,727 Bytes
c25e495
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b7c0c96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c25e495
 
b7c0c96
 
 
 
 
 
c25e495
b7c0c96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c25e495
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b7c0c96
 
 
 
 
 
 
 
 
 
 
 
 
 
9785d29
b7c0c96
 
 
 
 
 
 
 
 
 
c25e495
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b7c0c96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c25e495
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b7c0c96
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
# Table of Contents

* [Structure of PlanWriterFlow](#structure-of-planwriterflow)
* [run\_planwriter](#run_planwriter)
* [PlanWriterAskUserFlow](#PlanWriterAskUserFlow)
  * [PlanWriterAskUserFlow](#PlanWriterAskUserFlow.PlanWriterAskUserFlow)
    * [run](#PlanWriterAskUserFlow.PlanWriterAskUserFlow.run)
* [PlanWriterFlow](#PlanWriterFlow)
  * [PlanWriterFlow](#PlanWriterFlow.PlanWriterFlow)
    * [detect\_finish\_or\_continue](#PlanWriterFlow.PlanWriterFlow.detect_finish_or_continue)
    * [run](#PlanWriterFlow.PlanWriterFlow.run)
* [\_\_init\_\_](#__init__)
* [PlanWriterCtrlFlow](#PlanWriterCtrlFlow)
  * [PlanWriterCtrlFlow](#PlanWriterCtrlFlow.PlanWriterCtrlFlow)
    * [\_\_init\_\_](#PlanWriterCtrlFlow.PlanWriterCtrlFlow.__init__)
    * [instantiate\_from\_config](#PlanWriterCtrlFlow.PlanWriterCtrlFlow.instantiate_from_config)
    * [run](#PlanWriterCtrlFlow.PlanWriterCtrlFlow.run)



# Structure of PlanWriterFlow

```
               goal
                |
                v
        +---------------+
        |  Controller   | --------<<<<-----------+
        +---------------+                        |
                |                                |
                | (command, command args)        |
                |                                |
                v                                |
        +------------------+                     |
        |   Executor       |  Each branch is an  |
        | (Tree Structure) |  executor           |
        +------------------+                     |
                |                                ^
                | (summary)                      |
                |                                |
                v                                |             
                |                                |
                +-> goes back to the Controller>-+

```

Structure of the Executors:
```
         +-------------------+
         |   Branching       |
         |    Executor       |
         +-------------------+
        /                    \
       /                      \
      /                        \
     /                          \
write_plan                    ask_user

```

About the branches:
- [ask_user](https://huggingface.co/aiflows/PlanWriterFlowModule/blob/main/PlanWriterAskUserFlow.py): Ask user for info / confirmation, etc.
- [write_plan](https://huggingface.co/aiflows/InteractivePlanGenFlowModule): Generates plan (user edit is allowed) and fetches user feedback.

How it works:
Controller calls write_plan until user is satisfied in the feedback, finish.





<a id="run_planwriter"></a>

# run\_planwriter

<a id="PlanWriterAskUserFlow"></a>

# PlanWriterAskUserFlow

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

## PlanWriterAskUserFlow Objects

```python
class PlanWriterAskUserFlow(HumanStandardInputFlow)
```

Refer to: https://huggingface.co/aiflows/ExtendLibraryFlowModule/blob/main/ExtLibAskUserFlow.py
This flow is used to ask the user a question and get a response.

*Input Interface*:
- `question`

*Output Interface*:
- `feedback`
- `plan`

*Configuration Parameters*:
- `query_message_prompt_template`: The message template to prompt the user for input.
- `request_multi_line_input_flag`: Whether to request multi-line input from the user.
- `end_of_input_string`: The string to enter to indicate the end of input.

<a id="PlanWriterAskUserFlow.PlanWriterAskUserFlow.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 to the flow module.

**Returns**:

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

<a id="PlanWriterFlow"></a>

# PlanWriterFlow

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

## PlanWriterFlow Objects

```python
class PlanWriterFlow(ContentWriterFlow)
```

This flow inherits from ContentWriterFlow.
In the subflow of the executor, we specify the InteractivePlanGenFlow (https://huggingface.co/aiflows/InteractivePlanGenFlowModule)

*Input Interface*:
- `goal`

*Output Interface*:
- `plan`
- `result`
- `summary`
- `status`

*Configuration Parameters*:
- Also refer to superclass ContentWriterFlow (https://huggingface.co/aiflows/ContentWriterFlowModule)
- `input_interface`: the input interface of the flow
- `output_interface`: the output interface of the flow
- `subflows_config`: the configuration of the subflows
- `early_exit_key`: the key in the flow state that indicates the early exit condition
- `topology`: the topology of the flow

<a id="PlanWriterFlow.PlanWriterFlow.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 function is called when the subflow finishes running.

configured in the topology of the subflow config.

**Arguments**:

- `output_payload` (`Dict[str, Any]`): the output payload of the subflow
- `src_flow` (`Flow`): the subflow that generates the output payload

**Returns**:

`Dict[str, Any]`: the processed output payload

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

#### run

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

This function runs 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="__init__"></a>

# \_\_init\_\_

<a id="PlanWriterCtrlFlow"></a>

# PlanWriterCtrlFlow

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

## PlanWriterCtrlFlow Objects

```python
class PlanWriterCtrlFlow(ChatAtomicFlow)
```

Refer to: https://huggingface.co/aiflows/JarvisFlowModule/blob/main/Controller_JarvisFlow.py
This flow is a controller flow that controls the PlanWriterFlow.

*Input Interface Non Initialized*:
- `goal`: str

*Input Interface Initialized*:
- `feedback`: str
- `goal`: str
- `plan`: str

*Output Interface*:
- `command`: str
- `command_args`: Dict[str, Any]

*Configuration Parameters*:
- `input_interface_non_initialized`: List[str] = ["goal"]
- `input_interface_initialized`: List[str] = ["feedback", "goal", "plan"]
- `output_interface`: List[str] = ["command", "command_args"]
- `backend`: Dict[str, Any] : backend of the LLM
- `commands`: List[Dict[str, Any]] : commands that the LLM can execute
- `system_message_prompt_template`: str : the template of the system message prompt
- `init_human_message_prompt_template`: str : the template of the initial human message prompt
- `human_message_prompt_template`: str : the template of the human message prompt
- `previous_messages`: Dict[str, Any] : the previous messages of the conversation (sliding window)

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

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

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

This function initializes the flow.

**Arguments**:

- `commands` (`List[Command]`): List[Command] : commands that the LLM can execute
- `kwargs` (`Dict[str, Any]`): other parameters

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

#### instantiate\_from\_config

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

This function instantiates the flow from the config.

**Arguments**:

- `config` (`Dict[str, Any]`): the config of the flow

**Returns**:

`ChatAtomicFlow`: the instantiated flow

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

#### run

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

This function runs the flow.

**Arguments**:

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

**Returns**:

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