add more comments & docs; link change
Browse files- NewPlanGenFlow.py +25 -3
- README.md +116 -13
- ReplanningAskUserFlow.py +19 -1
- ReplanningFlow.py +7 -0
- temp.md +48 -0
NewPlanGenFlow.py
CHANGED
|
@@ -1,11 +1,33 @@
|
|
| 1 |
-
import json
|
| 2 |
-
from copy import deepcopy
|
| 3 |
-
from typing import Any, Dict
|
| 4 |
from flow_modules.aiflows.PlanGeneratorFlowModule import PlanGeneratorAtomicFlow
|
| 5 |
|
| 6 |
|
| 7 |
class NewPlanGenFlow(PlanGeneratorAtomicFlow):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
def __init__(self, **kwargs):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
super().__init__(**kwargs)
|
| 10 |
self.hint_for_model = """
|
| 11 |
Make sure your response is in the following format:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from flow_modules.aiflows.PlanGeneratorFlowModule import PlanGeneratorAtomicFlow
|
| 2 |
|
| 3 |
|
| 4 |
class NewPlanGenFlow(PlanGeneratorAtomicFlow):
|
| 5 |
+
"""
|
| 6 |
+
This flow module is responsible for generating a new plan based on the previous plan and the given requirements.
|
| 7 |
+
This flow is inherited from PlanGeneratorAtomicFlow. (https://huggingface.co/aiflows/PlanGeneratorFlowModule)
|
| 8 |
+
|
| 9 |
+
*Input Interface Non Initialized*:
|
| 10 |
+
- `goal`
|
| 11 |
+
- `old_plan`
|
| 12 |
+
|
| 13 |
+
*Input Interface Initialized*:
|
| 14 |
+
- `goal`
|
| 15 |
+
- `old_plan`
|
| 16 |
+
|
| 17 |
+
*Output Interface*:
|
| 18 |
+
- `new_plan`
|
| 19 |
+
|
| 20 |
+
*Configuration Parameters*:
|
| 21 |
+
- `system_message_prompt_template`: The template of the system message.
|
| 22 |
+
- `init_human_message_prompt_template`: The template of the init user message.
|
| 23 |
+
- `human_message_prompt_template`: The template of the user message.
|
| 24 |
+
|
| 25 |
+
"""
|
| 26 |
def __init__(self, **kwargs):
|
| 27 |
+
"""
|
| 28 |
+
Initialization of the flow module.
|
| 29 |
+
:param kwargs: The configuration parameters of the flow module.
|
| 30 |
+
"""
|
| 31 |
super().__init__(**kwargs)
|
| 32 |
self.hint_for_model = """
|
| 33 |
Make sure your response is in the following format:
|
README.md
CHANGED
|
@@ -1,4 +1,21 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
```
|
| 4 |
goal (info on the old plan), plan (old plan), plan_file_location
|
|
@@ -39,23 +56,15 @@ write_plan ask_user
|
|
| 39 |
```
|
| 40 |
|
| 41 |
About the branches:
|
| 42 |
-
- [ask_user](https://huggingface.co/
|
| 43 |
-
- [write_plan](https://huggingface.co/
|
| 44 |
-
- The PlanGenerator of write_plan is replaced with [NewPlanGenFlow](https://huggingface.co/
|
| 45 |
|
| 46 |
How it works:
|
| 47 |
Controller calls write_plan until user is satisfied in the feedback, finish.
|
| 48 |
|
| 49 |
|
| 50 |
-
# Table of Contents
|
| 51 |
|
| 52 |
-
* [run\_replanning](#run_replanning)
|
| 53 |
-
* [ReplanningAskUserFlow](#ReplanningAskUserFlow)
|
| 54 |
-
* [ReplanningAskUserFlow](#ReplanningAskUserFlow.ReplanningAskUserFlow)
|
| 55 |
-
* [NewPlanGenFlow](#NewPlanGenFlow)
|
| 56 |
-
* [ReplanningFlow](#ReplanningFlow)
|
| 57 |
-
* [ReplanningFlow](#ReplanningFlow.ReplanningFlow)
|
| 58 |
-
* [\_\_init\_\_](#__init__)
|
| 59 |
|
| 60 |
<a id="run_replanning"></a>
|
| 61 |
|
|
@@ -73,12 +82,83 @@ Controller calls write_plan until user is satisfied in the feedback, finish.
|
|
| 73 |
class ReplanningAskUserFlow(HumanStandardInputFlow)
|
| 74 |
```
|
| 75 |
|
| 76 |
-
Refer to: https://huggingface.co/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
<a id="NewPlanGenFlow"></a>
|
| 79 |
|
| 80 |
# NewPlanGenFlow
|
| 81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
<a id="ReplanningFlow"></a>
|
| 83 |
|
| 84 |
# ReplanningFlow
|
|
@@ -105,6 +185,29 @@ This flow inherits from PlanWriterFlow.
|
|
| 105 |
- `summary` (str): summary of the flow, will be written to the log file of the caller flow.
|
| 106 |
- `result` (str): result of the flow, will be passed to the controller of the caller flow.
|
| 107 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
<a id="__init__"></a>
|
| 109 |
|
| 110 |
# \_\_init\_\_
|
|
|
|
| 1 |
+
# Table of Contents
|
| 2 |
+
|
| 3 |
+
* [Structure of ReplanningFlow](#Structure-of-ReplanningFlow)
|
| 4 |
+
* [run\_replanning](#run_replanning)
|
| 5 |
+
* [ReplanningAskUserFlow](#ReplanningAskUserFlow)
|
| 6 |
+
* [ReplanningAskUserFlow](#ReplanningAskUserFlow.ReplanningAskUserFlow)
|
| 7 |
+
* [run](#ReplanningAskUserFlow.ReplanningAskUserFlow.run)
|
| 8 |
+
* [NewPlanGenFlow](#NewPlanGenFlow)
|
| 9 |
+
* [NewPlanGenFlow](#NewPlanGenFlow.NewPlanGenFlow)
|
| 10 |
+
* [\_\_init\_\_](#NewPlanGenFlow.NewPlanGenFlow.__init__)
|
| 11 |
+
* [ReplanningFlow](#ReplanningFlow)
|
| 12 |
+
* [ReplanningFlow](#ReplanningFlow.ReplanningFlow)
|
| 13 |
+
* [detect\_finish\_or\_continue](#ReplanningFlow.ReplanningFlow.detect_finish_or_continue)
|
| 14 |
+
* [\_\_init\_\_](#__init__)
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
# Structure of ReplanningFlow
|
| 19 |
|
| 20 |
```
|
| 21 |
goal (info on the old plan), plan (old plan), plan_file_location
|
|
|
|
| 56 |
```
|
| 57 |
|
| 58 |
About the branches:
|
| 59 |
+
- [ask_user](https://huggingface.co/aiflows/PlanWriterFlowModule/blob/main/PlanWriterAskUserFlow.py): Ask user for info / confirmation, etc.
|
| 60 |
+
- [write_plan](https://huggingface.co/aiflows/InteractivePlanGenFlowModule): Generates plan (user edit is allowed) and fetches user feedback.
|
| 61 |
+
- 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.
|
| 62 |
|
| 63 |
How it works:
|
| 64 |
Controller calls write_plan until user is satisfied in the feedback, finish.
|
| 65 |
|
| 66 |
|
|
|
|
| 67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
<a id="run_replanning"></a>
|
| 70 |
|
|
|
|
| 82 |
class ReplanningAskUserFlow(HumanStandardInputFlow)
|
| 83 |
```
|
| 84 |
|
| 85 |
+
Refer to: https://huggingface.co/aiflows/ExtendLibraryFlowModule/blob/main/ExtLibAskUserFlow.py
|
| 86 |
+
|
| 87 |
+
*Input Interface*:
|
| 88 |
+
- `question`
|
| 89 |
+
|
| 90 |
+
*Output Interface*:
|
| 91 |
+
- `feedback`
|
| 92 |
+
- `new_plan`
|
| 93 |
+
|
| 94 |
+
*Configuration Parameters*:
|
| 95 |
+
- `request_multi_line_input_flag`: if True, the user can input multiple lines of text. Default: False
|
| 96 |
+
- `end_of_input_string`: the string that the user can input to indicate that the input is finished. Default: EOI
|
| 97 |
+
- `query_message_prompt_template`: the template of the message that is sent to the user to ask for input.
|
| 98 |
+
|
| 99 |
+
<a id="ReplanningAskUserFlow.ReplanningAskUserFlow.run"></a>
|
| 100 |
+
|
| 101 |
+
#### run
|
| 102 |
+
|
| 103 |
+
```python
|
| 104 |
+
def run(input_data: Dict[str, Any]) -> Dict[str, Any]
|
| 105 |
+
```
|
| 106 |
+
|
| 107 |
+
Run the flow module.
|
| 108 |
+
|
| 109 |
+
**Arguments**:
|
| 110 |
+
|
| 111 |
+
- `input_data`: the input data
|
| 112 |
+
|
| 113 |
+
**Returns**:
|
| 114 |
+
|
| 115 |
+
the output data
|
| 116 |
|
| 117 |
<a id="NewPlanGenFlow"></a>
|
| 118 |
|
| 119 |
# NewPlanGenFlow
|
| 120 |
|
| 121 |
+
<a id="NewPlanGenFlow.NewPlanGenFlow"></a>
|
| 122 |
+
|
| 123 |
+
## NewPlanGenFlow Objects
|
| 124 |
+
|
| 125 |
+
```python
|
| 126 |
+
class NewPlanGenFlow(PlanGeneratorAtomicFlow)
|
| 127 |
+
```
|
| 128 |
+
|
| 129 |
+
This flow module is responsible for generating a new plan based on the previous plan and the given requirements.
|
| 130 |
+
This flow is inherited from PlanGeneratorAtomicFlow. (https://huggingface.co/aiflows/PlanGeneratorFlowModule)
|
| 131 |
+
|
| 132 |
+
*Input Interface Non Initialized*:
|
| 133 |
+
- `goal`
|
| 134 |
+
- `old_plan`
|
| 135 |
+
|
| 136 |
+
*Input Interface Initialized*:
|
| 137 |
+
- `goal`
|
| 138 |
+
- `old_plan`
|
| 139 |
+
|
| 140 |
+
*Output Interface*:
|
| 141 |
+
- `new_plan`
|
| 142 |
+
|
| 143 |
+
*Configuration Parameters*:
|
| 144 |
+
- `system_message_prompt_template`: The template of the system message.
|
| 145 |
+
- `init_human_message_prompt_template`: The template of the init user message.
|
| 146 |
+
- `human_message_prompt_template`: The template of the user message.
|
| 147 |
+
|
| 148 |
+
<a id="NewPlanGenFlow.NewPlanGenFlow.__init__"></a>
|
| 149 |
+
|
| 150 |
+
#### \_\_init\_\_
|
| 151 |
+
|
| 152 |
+
```python
|
| 153 |
+
def __init__(**kwargs)
|
| 154 |
+
```
|
| 155 |
+
|
| 156 |
+
Initialization of the flow module.
|
| 157 |
+
|
| 158 |
+
**Arguments**:
|
| 159 |
+
|
| 160 |
+
- `kwargs`: The configuration parameters of the flow module.
|
| 161 |
+
|
| 162 |
<a id="ReplanningFlow"></a>
|
| 163 |
|
| 164 |
# ReplanningFlow
|
|
|
|
| 185 |
- `summary` (str): summary of the flow, will be written to the log file of the caller flow.
|
| 186 |
- `result` (str): result of the flow, will be passed to the controller of the caller flow.
|
| 187 |
|
| 188 |
+
<a id="ReplanningFlow.ReplanningFlow.detect_finish_or_continue"></a>
|
| 189 |
+
|
| 190 |
+
#### detect\_finish\_or\_continue
|
| 191 |
+
|
| 192 |
+
```python
|
| 193 |
+
@CircularFlow.output_msg_payload_processor
|
| 194 |
+
def detect_finish_or_continue(output_payload: Dict[str, Any],
|
| 195 |
+
src_flow) -> Dict[str, Any]
|
| 196 |
+
```
|
| 197 |
+
|
| 198 |
+
This function is called when the replanning flow receives a message from the PlanGenerator.
|
| 199 |
+
|
| 200 |
+
It checks the command in the message and decides whether to finish the flow or continue the flow.
|
| 201 |
+
|
| 202 |
+
**Arguments**:
|
| 203 |
+
|
| 204 |
+
- `output_payload`: the message received from the PlanGenerator
|
| 205 |
+
- `src_flow`: the PlanGenerator
|
| 206 |
+
|
| 207 |
+
**Returns**:
|
| 208 |
+
|
| 209 |
+
the message to be sent to the controller of the caller flow
|
| 210 |
+
|
| 211 |
<a id="__init__"></a>
|
| 212 |
|
| 213 |
# \_\_init\_\_
|
ReplanningAskUserFlow.py
CHANGED
|
@@ -10,9 +10,27 @@ log = logging.get_logger(f"aiflows.{__name__}")
|
|
| 10 |
|
| 11 |
|
| 12 |
class ReplanningAskUserFlow(HumanStandardInputFlow):
|
| 13 |
-
"""Refer to: https://huggingface.co/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
def run(self,
|
| 15 |
input_data: Dict[str, Any]) -> Dict[str, Any]:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
query_message = self._get_message(self.query_message_prompt_template, input_data)
|
| 18 |
state_update_message = UpdateMessage_Generic(
|
|
|
|
| 10 |
|
| 11 |
|
| 12 |
class ReplanningAskUserFlow(HumanStandardInputFlow):
|
| 13 |
+
"""Refer to: https://huggingface.co/aiflows/ExtendLibraryFlowModule/blob/main/ExtLibAskUserFlow.py
|
| 14 |
+
|
| 15 |
+
*Input Interface*:
|
| 16 |
+
- `question`
|
| 17 |
+
|
| 18 |
+
*Output Interface*:
|
| 19 |
+
- `feedback`
|
| 20 |
+
- `new_plan`
|
| 21 |
+
|
| 22 |
+
*Configuration Parameters*:
|
| 23 |
+
- `request_multi_line_input_flag`: if True, the user can input multiple lines of text. Default: False
|
| 24 |
+
- `end_of_input_string`: the string that the user can input to indicate that the input is finished. Default: EOI
|
| 25 |
+
- `query_message_prompt_template`: the template of the message that is sent to the user to ask for input.
|
| 26 |
+
|
| 27 |
+
"""
|
| 28 |
def run(self,
|
| 29 |
input_data: Dict[str, Any]) -> Dict[str, Any]:
|
| 30 |
+
"""Run the flow module.
|
| 31 |
+
:param input_data: the input data
|
| 32 |
+
:return: the output data
|
| 33 |
+
"""
|
| 34 |
|
| 35 |
query_message = self._get_message(self.query_message_prompt_template, input_data)
|
| 36 |
state_update_message = UpdateMessage_Generic(
|
ReplanningFlow.py
CHANGED
|
@@ -19,6 +19,7 @@ class ReplanningFlow(PlanWriterFlow):
|
|
| 19 |
- `result` (str): result of the flow, will be passed to the controller of the caller flow.
|
| 20 |
"""
|
| 21 |
def _on_reach_max_round(self):
|
|
|
|
| 22 |
self._state_update_dict({
|
| 23 |
"plan": "The maximum amount of rounds was reached before the model generated the plan.",
|
| 24 |
"status": "unfinished",
|
|
@@ -28,6 +29,12 @@ class ReplanningFlow(PlanWriterFlow):
|
|
| 28 |
|
| 29 |
@CircularFlow.output_msg_payload_processor
|
| 30 |
def detect_finish_or_continue(self, output_payload: Dict[str, Any], src_flow) -> Dict[str, Any]:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
command = output_payload["command"]
|
| 32 |
if command == "finish":
|
| 33 |
# ~~~ fetch temp file location, plan content, memory file (of upper level flow e.g. ExtLib) from flow state
|
|
|
|
| 19 |
- `result` (str): result of the flow, will be passed to the controller of the caller flow.
|
| 20 |
"""
|
| 21 |
def _on_reach_max_round(self):
|
| 22 |
+
"""This function is called when the replanning flow reaches the maximum amount of rounds."""
|
| 23 |
self._state_update_dict({
|
| 24 |
"plan": "The maximum amount of rounds was reached before the model generated the plan.",
|
| 25 |
"status": "unfinished",
|
|
|
|
| 29 |
|
| 30 |
@CircularFlow.output_msg_payload_processor
|
| 31 |
def detect_finish_or_continue(self, output_payload: Dict[str, Any], src_flow) -> Dict[str, Any]:
|
| 32 |
+
"""This function is called when the replanning flow receives a message from the PlanGenerator.
|
| 33 |
+
It checks the command in the message and decides whether to finish the flow or continue the flow.
|
| 34 |
+
:param output_payload: the message received from the PlanGenerator
|
| 35 |
+
:param src_flow: the PlanGenerator
|
| 36 |
+
:return: the message to be sent to the controller of the caller flow
|
| 37 |
+
"""
|
| 38 |
command = output_payload["command"]
|
| 39 |
if command == "finish":
|
| 40 |
# ~~~ fetch temp file location, plan content, memory file (of upper level flow e.g. ExtLib) from flow state
|
temp.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Structure of ReplanningFlow
|
| 2 |
+
|
| 3 |
+
```
|
| 4 |
+
goal (info on the old plan), plan (old plan), plan_file_location
|
| 5 |
+
|
|
| 6 |
+
v
|
| 7 |
+
+---------------+
|
| 8 |
+
| Controller | --------<<<<-----------+
|
| 9 |
+
+---------------+ |
|
| 10 |
+
| |
|
| 11 |
+
| (command, command args) |
|
| 12 |
+
| |
|
| 13 |
+
v |
|
| 14 |
+
+------------------+ |
|
| 15 |
+
| Executor | Each branch is an |
|
| 16 |
+
| (Tree Structure) | executor |
|
| 17 |
+
+------------------+ |
|
| 18 |
+
| ^
|
| 19 |
+
| (summary) |
|
| 20 |
+
| |
|
| 21 |
+
v |
|
| 22 |
+
| |
|
| 23 |
+
+-> goes back to the Controller>-+
|
| 24 |
+
|
| 25 |
+
```
|
| 26 |
+
|
| 27 |
+
Structure of the Executors:
|
| 28 |
+
```
|
| 29 |
+
+-------------------+
|
| 30 |
+
| Branching |
|
| 31 |
+
| Executor |
|
| 32 |
+
+-------------------+
|
| 33 |
+
/ \
|
| 34 |
+
/ \
|
| 35 |
+
/ \
|
| 36 |
+
/ \
|
| 37 |
+
write_plan ask_user
|
| 38 |
+
|
| 39 |
+
```
|
| 40 |
+
|
| 41 |
+
About the branches:
|
| 42 |
+
- [ask_user](https://huggingface.co/aiflows/PlanWriterFlowModule/blob/main/PlanWriterAskUserFlow.py): Ask user for info / confirmation, etc.
|
| 43 |
+
- [write_plan](https://huggingface.co/aiflows/InteractivePlanGenFlowModule): Generates plan (user edit is allowed) and fetches user feedback.
|
| 44 |
+
- 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.
|
| 45 |
+
|
| 46 |
+
How it works:
|
| 47 |
+
Controller calls write_plan until user is satisfied in the feedback, finish.
|
| 48 |
+
|