File size: 6,140 Bytes
2dccc9b
 
ee7aded
2dccc9b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8f80245
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2dccc9b
 
 
8f80245
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2dccc9b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8f80245
 
 
 
 
2dccc9b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8f80245
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2dccc9b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8f80245
 
 
 
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
# Table of Contents

* [Structure of ReplanningFlow](#structure-of-replanningflow)
* [run\_replanning](#run_replanning)
* [ReplanningAskUserFlow](#ReplanningAskUserFlow)
  * [ReplanningAskUserFlow](#ReplanningAskUserFlow.ReplanningAskUserFlow)
    * [run](#ReplanningAskUserFlow.ReplanningAskUserFlow.run)
* [NewPlanGenFlow](#NewPlanGenFlow)
  * [NewPlanGenFlow](#NewPlanGenFlow.NewPlanGenFlow)
    * [\_\_init\_\_](#NewPlanGenFlow.NewPlanGenFlow.__init__)
* [ReplanningFlow](#ReplanningFlow)
  * [ReplanningFlow](#ReplanningFlow.ReplanningFlow)
    * [detect\_finish\_or\_continue](#ReplanningFlow.ReplanningFlow.detect_finish_or_continue)
* [\_\_init\_\_](#__init__)



# Structure of ReplanningFlow

```
goal (info on the old plan), plan (old plan), plan_file_location
                |
                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.
  - The PlanGenerator of write_plan is replaced with [NewPlanGenFlow](https://huggingface.co/aiflows/ReplanningFlowModule/blob/main/NewPlanGenFlow.py) to re-plan instead of write plan.

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




<a id="run_replanning"></a>

# run\_replanning

<a id="ReplanningAskUserFlow"></a>

# ReplanningAskUserFlow

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

## ReplanningAskUserFlow Objects

```python
class ReplanningAskUserFlow(HumanStandardInputFlow)
```

Refer to: https://huggingface.co/aiflows/ExtendLibraryFlowModule/blob/main/ExtLibAskUserFlow.py

*Input Interface*:
- `question`

*Output Interface*:
- `feedback`
- `new_plan`

*Configuration Parameters*:
- `request_multi_line_input_flag`: if True, the user can input multiple lines of text. Default: False
- `end_of_input_string`: the string that the user can input to indicate that the input is finished. Default: EOI
- `query_message_prompt_template`: the template of the message that is sent to the user to ask for input.

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

#### run

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

Run the flow module.

**Arguments**:

- `input_data`: the input data

**Returns**:

the output data

<a id="NewPlanGenFlow"></a>

# NewPlanGenFlow

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

## NewPlanGenFlow Objects

```python
class NewPlanGenFlow(PlanGeneratorAtomicFlow)
```

This flow module is responsible for generating a new plan based on the previous plan and the given requirements.
This flow is inherited from PlanGeneratorAtomicFlow. (https://huggingface.co/aiflows/PlanGeneratorFlowModule)

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

*Input Interface Initialized*:
- `goal`
- `old_plan`

*Output Interface*:
- `new_plan`

*Configuration Parameters*:
- `system_message_prompt_template`: The template of the system message.
- `init_human_message_prompt_template`: The template of the init user message.
- `human_message_prompt_template`: The template of the user message.

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

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

```python
def __init__(**kwargs)
```

Initialization of the flow module.

**Arguments**:

- `kwargs`: The configuration parameters of the flow module.

<a id="ReplanningFlow"></a>

# ReplanningFlow

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

## ReplanningFlow Objects

```python
class ReplanningFlow(PlanWriterFlow)
```

This flow inherits from PlanWriterFlow.
 By changing prompts and injecting proper information to the controller and the PlanGenerator, we are able to achieve the replanning.

*Input Interface*:
- `goal` (str): information on the old plan (e.g. what is wrong)
- `plan` (str): the old plan
- `plan_file_location` (str): the location of the old plan file

*Output Interface*:
- `plan` (str): the new plan
- `status`: "finished" or "unfinished"
- `summary` (str): summary of the flow, will be written to the log file of the caller flow.
- `result` (str): result of the flow, will be passed to the controller of the caller flow.

<a id="ReplanningFlow.ReplanningFlow.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 replanning flow receives a message from the PlanGenerator.

It checks the command in the message and decides whether to finish the flow or continue the flow.

**Arguments**:

- `output_payload`: the message received from the PlanGenerator
- `src_flow`: the PlanGenerator

**Returns**:

the message to be sent to the controller of the caller flow

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

# \_\_init\_\_