add more comments & docs
Browse files- CoderFlow.py +4 -0
- Controller_CoderFlow.py +83 -1
- CtrlExMem_CoderFlow.py +17 -2
- Planner_CoderFlow.py +19 -1
- README.md +189 -23
- UpdatePlanAtomicFlow.py +23 -1
CoderFlow.py
CHANGED
@@ -20,6 +20,10 @@ class CoderFlow(AbstractBossFlow):
|
|
20 |
- `result` (str): The result of the flow, the result will be returned to the caller (i.e. JarvisFlow).
|
21 |
- `summary` (str): The summary of the flow, the summary will be logged into the logs of the caller flow (i.e. JarvisFlow).
|
22 |
|
|
|
|
|
|
|
|
|
23 |
Typical workflow of Coder:
|
24 |
0. JarvisFlow calls Coder with a goal.
|
25 |
1. MemoryReading reads plans, logs and code library.
|
|
|
20 |
- `result` (str): The result of the flow, the result will be returned to the caller (i.e. JarvisFlow).
|
21 |
- `summary` (str): The summary of the flow, the summary will be logged into the logs of the caller flow (i.e. JarvisFlow).
|
22 |
|
23 |
+
*Configuration Parameters*: (Also see super class: AbstractBossFlow)
|
24 |
+
- `memory_files` (dict): The memory files of the flow. The memory files are the files that the flow reads and writes. Typically it should contain plan, logs, and code_library.
|
25 |
+
|
26 |
+
|
27 |
Typical workflow of Coder:
|
28 |
0. JarvisFlow calls Coder with a goal.
|
29 |
1. MemoryReading reads plans, logs and code library.
|
Controller_CoderFlow.py
CHANGED
@@ -15,11 +15,50 @@ class Command:
|
|
15 |
input_args: List[str]
|
16 |
|
17 |
class Controller_CoderFlow(ChatAtomicFlow):
|
18 |
-
"""Refer to: https://huggingface.co/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
def __init__(
|
20 |
self,
|
21 |
commands: List[Command],
|
22 |
**kwargs):
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
super().__init__(**kwargs)
|
24 |
self.system_message_prompt_template = self.system_message_prompt_template.partial(
|
25 |
commands=self._build_commands_manual(commands),
|
@@ -42,6 +81,12 @@ class Controller_CoderFlow(ChatAtomicFlow):
|
|
42 |
|
43 |
@staticmethod
|
44 |
def _build_commands_manual(commands: List[Command]) -> str:
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
ret = ""
|
46 |
for i, command in enumerate(commands):
|
47 |
command_input_json_schema = json.dumps(
|
@@ -50,12 +95,30 @@ class Controller_CoderFlow(ChatAtomicFlow):
|
|
50 |
return ret
|
51 |
|
52 |
def _get_content_file_location(self, input_data, content_name):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
# get the location of the file that contains the content: plan, logs, code_library
|
54 |
assert "memory_files" in input_data, "memory_files not passed to Coder/Controller"
|
55 |
assert content_name in input_data["memory_files"], f"{content_name} not in memory files"
|
56 |
return input_data["memory_files"][content_name]
|
57 |
|
58 |
def _get_content(self, input_data, content_name):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
# get the content of the file that contains the content: plan, logs, code_library
|
60 |
assert content_name in input_data, f"{content_name} not passed to Coder/Controller"
|
61 |
content = input_data[content_name]
|
@@ -65,6 +128,13 @@ class Controller_CoderFlow(ChatAtomicFlow):
|
|
65 |
|
66 |
@classmethod
|
67 |
def instantiate_from_config(cls, config):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
flow_config = deepcopy(config)
|
69 |
|
70 |
kwargs = {"flow_config": flow_config}
|
@@ -87,6 +157,12 @@ class Controller_CoderFlow(ChatAtomicFlow):
|
|
87 |
return cls(**kwargs)
|
88 |
|
89 |
def _update_prompts_and_input(self, input_data: Dict[str, Any]):
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
if 'goal' in input_data:
|
91 |
input_data['goal'] += self.hint_for_model
|
92 |
if 'result' in input_data:
|
@@ -105,6 +181,12 @@ class Controller_CoderFlow(ChatAtomicFlow):
|
|
105 |
)
|
106 |
|
107 |
def run(self, input_data: Dict[str, Any]) -> Dict[str, Any]:
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
self._update_prompts_and_input(input_data)
|
109 |
|
110 |
# ~~~when conversation is initialized, append the updated system prompts to the chat history ~~~
|
|
|
15 |
input_args: List[str]
|
16 |
|
17 |
class Controller_CoderFlow(ChatAtomicFlow):
|
18 |
+
"""Refer to: https://huggingface.co/aiflows/JarvisFlowModule/blob/main/Controller_JarvisFlow.py
|
19 |
+
This flow is used to control the coder flow.
|
20 |
+
|
21 |
+
*Input Interface Non Initialized*:
|
22 |
+
- `goal`
|
23 |
+
- `plan`
|
24 |
+
- `code_library`
|
25 |
+
- `logs`
|
26 |
+
- `memory_files`
|
27 |
+
|
28 |
+
*Input Interface Initialized*:
|
29 |
+
- `goal`
|
30 |
+
- `plan`
|
31 |
+
- `code_library`
|
32 |
+
- `logs`
|
33 |
+
- `memory_files`
|
34 |
+
- `result`
|
35 |
+
|
36 |
+
*Output Interface*:
|
37 |
+
- `command`
|
38 |
+
- `command_args`
|
39 |
+
|
40 |
+
*Configuration Parameters*:
|
41 |
+
- `Input Interface Non Initialized`: Input interface before the conversation is initialized.
|
42 |
+
- `Input Interface Initialized`: Input interface after the conversation is initialized.
|
43 |
+
- `Output Interface`: Output interface.
|
44 |
+
- `backend`: The backend of the LLM.
|
45 |
+
- `command`: A list of available commands for the controller to call.
|
46 |
+
- `system_message_prompt_template`: The template of the system message prompt.
|
47 |
+
- `init_human_message_prompt_template`: The template of the initial human message prompt.
|
48 |
+
- `human_message_prompt_template`: The template of the human message prompt.
|
49 |
+
- `previous_messages`: The sliding window of previous messages.
|
50 |
+
|
51 |
+
"""
|
52 |
def __init__(
|
53 |
self,
|
54 |
commands: List[Command],
|
55 |
**kwargs):
|
56 |
+
"""Initialize the flow.
|
57 |
+
:param commands: A list of available commands for the controller to call.
|
58 |
+
:type commands: List[Command]
|
59 |
+
:param kwargs: Refer to the configuration parameters.
|
60 |
+
:type kwargs: Dict[str, Any]
|
61 |
+
"""
|
62 |
super().__init__(**kwargs)
|
63 |
self.system_message_prompt_template = self.system_message_prompt_template.partial(
|
64 |
commands=self._build_commands_manual(commands),
|
|
|
81 |
|
82 |
@staticmethod
|
83 |
def _build_commands_manual(commands: List[Command]) -> str:
|
84 |
+
"""Build the manual for the commands.
|
85 |
+
:param commands: A list of available commands for the controller to call.
|
86 |
+
:type commands: List[Command]
|
87 |
+
:return: The manual for the commands.
|
88 |
+
:rtype: str
|
89 |
+
"""
|
90 |
ret = ""
|
91 |
for i, command in enumerate(commands):
|
92 |
command_input_json_schema = json.dumps(
|
|
|
95 |
return ret
|
96 |
|
97 |
def _get_content_file_location(self, input_data, content_name):
|
98 |
+
"""Get the location of the file that contains the content: plan, logs, code_library
|
99 |
+
:param input_data: The input data.
|
100 |
+
:type input_data: Dict[str, Any]
|
101 |
+
:param content_name: The name of the content.
|
102 |
+
:type content_name: str
|
103 |
+
:raises AssertionError: If the content is not in the memory files.
|
104 |
+
:return: The location of the file that contains the content.
|
105 |
+
:rtype: str
|
106 |
+
"""
|
107 |
# get the location of the file that contains the content: plan, logs, code_library
|
108 |
assert "memory_files" in input_data, "memory_files not passed to Coder/Controller"
|
109 |
assert content_name in input_data["memory_files"], f"{content_name} not in memory files"
|
110 |
return input_data["memory_files"][content_name]
|
111 |
|
112 |
def _get_content(self, input_data, content_name):
|
113 |
+
"""Get the content of the file that contains the content: plan, logs, code_library
|
114 |
+
:param input_data: The input data.
|
115 |
+
:type input_data: Dict[str, Any]
|
116 |
+
:param content_name: The name of the content.
|
117 |
+
:type content_name: str
|
118 |
+
:raises AssertionError: If the content is not in the memory files.
|
119 |
+
:return: The content of the file that contains the content.
|
120 |
+
:rtype: str
|
121 |
+
"""
|
122 |
# get the content of the file that contains the content: plan, logs, code_library
|
123 |
assert content_name in input_data, f"{content_name} not passed to Coder/Controller"
|
124 |
content = input_data[content_name]
|
|
|
128 |
|
129 |
@classmethod
|
130 |
def instantiate_from_config(cls, config):
|
131 |
+
"""Instantiate the flow from the configuration.
|
132 |
+
:param config: The configuration.
|
133 |
+
:type config: Dict[str, Any]
|
134 |
+
:return: The instantiated flow.
|
135 |
+
:rtype: Controller_CoderFlow
|
136 |
+
"""
|
137 |
+
|
138 |
flow_config = deepcopy(config)
|
139 |
|
140 |
kwargs = {"flow_config": flow_config}
|
|
|
157 |
return cls(**kwargs)
|
158 |
|
159 |
def _update_prompts_and_input(self, input_data: Dict[str, Any]):
|
160 |
+
"""Update the prompts and input data.
|
161 |
+
:param input_data: The input data.
|
162 |
+
:type input_data: Dict[str, Any]
|
163 |
+
:raises AssertionError: If the input data is not valid.
|
164 |
+
"""
|
165 |
+
|
166 |
if 'goal' in input_data:
|
167 |
input_data['goal'] += self.hint_for_model
|
168 |
if 'result' in input_data:
|
|
|
181 |
)
|
182 |
|
183 |
def run(self, input_data: Dict[str, Any]) -> Dict[str, Any]:
|
184 |
+
"""Run the flow.
|
185 |
+
:param input_data: The input data.
|
186 |
+
:type input_data: Dict[str, Any]
|
187 |
+
:return: The output data.
|
188 |
+
:rtype: Dict[str, Any]
|
189 |
+
"""
|
190 |
self._update_prompts_and_input(input_data)
|
191 |
|
192 |
# ~~~when conversation is initialized, append the updated system prompts to the chat history ~~~
|
CtrlExMem_CoderFlow.py
CHANGED
@@ -5,7 +5,7 @@ from aiflows.base_flows import CircularFlow
|
|
5 |
|
6 |
class CtrlExMem_CoderFlow(CtrlExMemFlow):
|
7 |
"""This class inherits from the CtrlExMemFlow class from AbstractBossFlowModule.
|
8 |
-
See: https://huggingface.co/
|
9 |
|
10 |
*Input Interface*:
|
11 |
- `plan`
|
@@ -17,9 +17,17 @@ class CtrlExMem_CoderFlow(CtrlExMemFlow):
|
|
17 |
*Output Interface*
|
18 |
- `result` (str): The result of the flow, the result will be returned to the caller.
|
19 |
- `summary` (str): The summary of the flow, the summary will be logged into the logs of the caller flow.
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
"""
|
22 |
def _on_reach_max_round(self):
|
|
|
|
|
23 |
self._state_update_dict({
|
24 |
"result": "the maximum amount of rounds was reached before the coder flow has done the job",
|
25 |
"summary": "CoderFlow: the maximum amount of rounds was reached before the flow has done the job",
|
@@ -28,6 +36,13 @@ class CtrlExMem_CoderFlow(CtrlExMemFlow):
|
|
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 |
return {
|
|
|
5 |
|
6 |
class CtrlExMem_CoderFlow(CtrlExMemFlow):
|
7 |
"""This class inherits from the CtrlExMemFlow class from AbstractBossFlowModule.
|
8 |
+
See: https://huggingface.co/aiflows/AbstractBossFlowModule/blob/main/CtrlExMemFlow.py
|
9 |
|
10 |
*Input Interface*:
|
11 |
- `plan`
|
|
|
17 |
*Output Interface*
|
18 |
- `result` (str): The result of the flow, the result will be returned to the caller.
|
19 |
- `summary` (str): The summary of the flow, the summary will be logged into the logs of the caller flow.
|
20 |
+
|
21 |
+
*Configuration Parameters*:
|
22 |
+
- See the configuration parameters of the CtrlExMemFlow class from AbstractBoss (https://huggingface.co/aiflows/AbstractBossFlowModule/blob/main/CtrlExMemFlow.py).
|
23 |
+
- `input_interface`: the input interface of the flow
|
24 |
+
- `output_interface`: the output interface of the flow
|
25 |
+
- `subflows_config`: the configuration of the subflows
|
26 |
+
|
27 |
"""
|
28 |
def _on_reach_max_round(self):
|
29 |
+
"""This method is called when the flow reaches the maximum amount of rounds.
|
30 |
+
"""
|
31 |
self._state_update_dict({
|
32 |
"result": "the maximum amount of rounds was reached before the coder flow has done the job",
|
33 |
"summary": "CoderFlow: the maximum amount of rounds was reached before the flow has done the job",
|
|
|
36 |
|
37 |
@CircularFlow.output_msg_payload_processor
|
38 |
def detect_finish_or_continue(self, output_payload: Dict[str, Any], src_flow) -> Dict[str, Any]:
|
39 |
+
"""This method is called when the flow receives a message from a subflow.
|
40 |
+
This method will check the message and decide whether the flow should continue or finish.
|
41 |
+
:param output_payload: the output payload of the subflow
|
42 |
+
:param src_flow: the source flow of the message
|
43 |
+
:return: the output payload of the flow
|
44 |
+
:rtype: Dict[str, Any]
|
45 |
+
"""
|
46 |
command = output_payload["command"]
|
47 |
if command == "finish":
|
48 |
return {
|
Planner_CoderFlow.py
CHANGED
@@ -6,7 +6,25 @@ from aiflows.base_flows import CircularFlow
|
|
6 |
|
7 |
|
8 |
class Planner_CoderFlow(PlanWriterFlow):
|
9 |
-
"""Planner of the coder flow, it inherits from PlanWriterFlow, see: https://huggingface.co/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
"""
|
11 |
def _on_reach_max_round(self):
|
12 |
self._state_update_dict({
|
|
|
6 |
|
7 |
|
8 |
class Planner_CoderFlow(PlanWriterFlow):
|
9 |
+
"""Planner of the coder flow, it inherits from PlanWriterFlow, see: https://huggingface.co/aiflows/PlanWriterFlowModule
|
10 |
+
This flow is responsible for generating the plan for the coder flow.
|
11 |
+
|
12 |
+
*Input Interface*
|
13 |
+
- `goal`
|
14 |
+
- `memory_files`
|
15 |
+
- `code_library`
|
16 |
+
|
17 |
+
*Output Interface*
|
18 |
+
- `plan`
|
19 |
+
- `summary`
|
20 |
+
- `status`
|
21 |
+
|
22 |
+
*Configuration Parameters*:
|
23 |
+
- Look at the configuration parameters of PlanWriterFlowModule for detailed info. (https://huggingface.co/aiflows/PlanWriterFlowModule)
|
24 |
+
- `input_interface`: the input interface of the flow, default: `["goal", "memory_files", "code_library"]`
|
25 |
+
- `output_interface`: the output interface of the flow, default: `["plan", "summary", "status"]`
|
26 |
+
- `subflows_config`: configuration of the subflows.
|
27 |
+
- `topology`: topology of the subflows.
|
28 |
"""
|
29 |
def _on_reach_max_round(self):
|
30 |
self._state_update_dict({
|
README.md
CHANGED
@@ -1,4 +1,28 @@
|
|
1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
```
|
4 |
goal, memory_files (dict)
|
@@ -84,30 +108,16 @@ Memory files of Coder:
|
|
84 |
- library.py
|
85 |
|
86 |
About the branches:
|
87 |
-
- [ExtendLibrary](https://huggingface.co/
|
88 |
-
- [ask_user](https://huggingface.co/
|
89 |
-
- [re_plan](https://huggingface.co/
|
90 |
-
- [update_plan](https://huggingface.co/
|
91 |
-
- [run_code](https://huggingface.co/
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
-
# Table of Contents
|
97 |
|
98 |
-
* [CtrlExMem\_CoderFlow](#CtrlExMem_CoderFlow)
|
99 |
-
* [CtrlExMem\_CoderFlow](#CtrlExMem_CoderFlow.CtrlExMem_CoderFlow)
|
100 |
-
* [run\_coder](#run_coder)
|
101 |
-
* [Planner\_CoderFlow](#Planner_CoderFlow)
|
102 |
-
* [Planner\_CoderFlow](#Planner_CoderFlow.Planner_CoderFlow)
|
103 |
-
* [Controller\_CoderFlow](#Controller_CoderFlow)
|
104 |
-
* [Controller\_CoderFlow](#Controller_CoderFlow.Controller_CoderFlow)
|
105 |
-
* [UpdatePlanAtomicFlow](#UpdatePlanAtomicFlow)
|
106 |
-
* [UpdatePlanAtomicFlow](#UpdatePlanAtomicFlow.UpdatePlanAtomicFlow)
|
107 |
-
* [CoderFlow](#CoderFlow)
|
108 |
-
* [CoderFlow](#CoderFlow.CoderFlow)
|
109 |
-
* [run](#CoderFlow.CoderFlow.run)
|
110 |
-
* [\_\_init\_\_](#__init__)
|
111 |
|
112 |
<a id="CtrlExMem_CoderFlow"></a>
|
113 |
|
@@ -122,7 +132,7 @@ class CtrlExMem_CoderFlow(CtrlExMemFlow)
|
|
122 |
```
|
123 |
|
124 |
This class inherits from the CtrlExMemFlow class from AbstractBossFlowModule.
|
125 |
-
See: https://huggingface.co/
|
126 |
|
127 |
*Input Interface*:
|
128 |
- `plan`
|
@@ -135,6 +145,35 @@ See: https://huggingface.co/Tachi67/AbstractBossFlowModule/blob/main/CtrlExMemFl
|
|
135 |
- `result` (str): The result of the flow, the result will be returned to the caller.
|
136 |
- `summary` (str): The summary of the flow, the summary will be logged into the logs of the caller flow.
|
137 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
138 |
<a id="run_coder"></a>
|
139 |
|
140 |
# run\_coder
|
@@ -151,7 +190,25 @@ See: https://huggingface.co/Tachi67/AbstractBossFlowModule/blob/main/CtrlExMemFl
|
|
151 |
class Planner_CoderFlow(PlanWriterFlow)
|
152 |
```
|
153 |
|
154 |
-
Planner of the coder flow, it inherits from PlanWriterFlow, see: https://huggingface.co/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
155 |
|
156 |
<a id="Controller_CoderFlow"></a>
|
157 |
|
@@ -165,7 +222,90 @@ Planner of the coder flow, it inherits from PlanWriterFlow, see: https://hugging
|
|
165 |
class Controller_CoderFlow(ChatAtomicFlow)
|
166 |
```
|
167 |
|
168 |
-
Refer to: https://huggingface.co/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
169 |
|
170 |
<a id="UpdatePlanAtomicFlow"></a>
|
171 |
|
@@ -189,6 +329,28 @@ plan it has. However one setback is that this process in then not deterministic.
|
|
189 |
*Output Interface*
|
190 |
- `result`: the result of the update plan operation
|
191 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
192 |
<a id="CoderFlow"></a>
|
193 |
|
194 |
# CoderFlow
|
@@ -216,6 +378,10 @@ The Coder flow has the similar structure as the Jarvis flow (inherited from Abst
|
|
216 |
- `result` (str): The result of the flow, the result will be returned to the caller (i.e. JarvisFlow).
|
217 |
- `summary` (str): The summary of the flow, the summary will be logged into the logs of the caller flow (i.e. JarvisFlow).
|
218 |
|
|
|
|
|
|
|
|
|
219 |
Typical workflow of Coder:
|
220 |
0. JarvisFlow calls Coder with a goal.
|
221 |
1. MemoryReading reads plans, logs and code library.
|
|
|
1 |
+
# Table of Contents
|
2 |
+
|
3 |
+
* [Structure of Coder](#structure-of-coder)
|
4 |
+
* [CtrlExMem\_CoderFlow](#CtrlExMem_CoderFlow)
|
5 |
+
* [CtrlExMem\_CoderFlow](#CtrlExMem_CoderFlow.CtrlExMem_CoderFlow)
|
6 |
+
* [detect\_finish\_or\_continue](#CtrlExMem_CoderFlow.CtrlExMem_CoderFlow.detect_finish_or_continue)
|
7 |
+
* [run\_coder](#run_coder)
|
8 |
+
* [Planner\_CoderFlow](#Planner_CoderFlow)
|
9 |
+
* [Planner\_CoderFlow](#Planner_CoderFlow.Planner_CoderFlow)
|
10 |
+
* [Controller\_CoderFlow](#Controller_CoderFlow)
|
11 |
+
* [Controller\_CoderFlow](#Controller_CoderFlow.Controller_CoderFlow)
|
12 |
+
* [\_\_init\_\_](#Controller_CoderFlow.Controller_CoderFlow.__init__)
|
13 |
+
* [instantiate\_from\_config](#Controller_CoderFlow.Controller_CoderFlow.instantiate_from_config)
|
14 |
+
* [run](#Controller_CoderFlow.Controller_CoderFlow.run)
|
15 |
+
* [UpdatePlanAtomicFlow](#UpdatePlanAtomicFlow)
|
16 |
+
* [UpdatePlanAtomicFlow](#UpdatePlanAtomicFlow.UpdatePlanAtomicFlow)
|
17 |
+
* [run](#UpdatePlanAtomicFlow.UpdatePlanAtomicFlow.run)
|
18 |
+
* [CoderFlow](#CoderFlow)
|
19 |
+
* [CoderFlow](#CoderFlow.CoderFlow)
|
20 |
+
* [run](#CoderFlow.CoderFlow.run)
|
21 |
+
* [\_\_init\_\_](#__init__)
|
22 |
+
|
23 |
+
|
24 |
+
|
25 |
+
# Structure of Coder
|
26 |
|
27 |
```
|
28 |
goal, memory_files (dict)
|
|
|
108 |
- library.py
|
109 |
|
110 |
About the branches:
|
111 |
+
- [ExtendLibrary](https://huggingface.co/aiflows/ExtendLibraryFlowModule): Writes and tests code functions in an interactive fashion, finally saves the written function to the code library.
|
112 |
+
- [ask_user](https://huggingface.co/aiflows/ExtendLibraryFlowModule/blob/main/ExtLibAskUserFlow.py): Ask user for info / confirmation, etc.
|
113 |
+
- [re_plan](https://huggingface.co/aiflows/ReplanningFlowModule): One branch of the executors, when something goes wrong, re-draft the plan.
|
114 |
+
- [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.
|
115 |
+
- [run_code](https://huggingface.co/aiflows/RunCodeFlowModule): Runs the code written by the Controller, will first open up a temp file with the code for user confirmation and editing, then the code is passed to the [InterpreterFlow](https://huggingface.co/aiflows/InterpreterFlowModule).
|
116 |
|
117 |
|
118 |
|
119 |
|
|
|
120 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
|
122 |
<a id="CtrlExMem_CoderFlow"></a>
|
123 |
|
|
|
132 |
```
|
133 |
|
134 |
This class inherits from the CtrlExMemFlow class from AbstractBossFlowModule.
|
135 |
+
See: https://huggingface.co/aiflows/AbstractBossFlowModule/blob/main/CtrlExMemFlow.py
|
136 |
|
137 |
*Input Interface*:
|
138 |
- `plan`
|
|
|
145 |
- `result` (str): The result of the flow, the result will be returned to the caller.
|
146 |
- `summary` (str): The summary of the flow, the summary will be logged into the logs of the caller flow.
|
147 |
|
148 |
+
*Configuration Parameters*:
|
149 |
+
- See the configuration parameters of the CtrlExMemFlow class from AbstractBoss (https://huggingface.co/aiflows/AbstractBossFlowModule/blob/main/CtrlExMemFlow.py).
|
150 |
+
- `input_interface`: the input interface of the flow
|
151 |
+
- `output_interface`: the output interface of the flow
|
152 |
+
- `subflows_config`: the configuration of the subflows
|
153 |
+
|
154 |
+
<a id="CtrlExMem_CoderFlow.CtrlExMem_CoderFlow.detect_finish_or_continue"></a>
|
155 |
+
|
156 |
+
#### detect\_finish\_or\_continue
|
157 |
+
|
158 |
+
```python
|
159 |
+
@CircularFlow.output_msg_payload_processor
|
160 |
+
def detect_finish_or_continue(output_payload: Dict[str, Any],
|
161 |
+
src_flow) -> Dict[str, Any]
|
162 |
+
```
|
163 |
+
|
164 |
+
This method is called when the flow receives a message from a subflow.
|
165 |
+
|
166 |
+
This method will check the message and decide whether the flow should continue or finish.
|
167 |
+
|
168 |
+
**Arguments**:
|
169 |
+
|
170 |
+
- `output_payload`: the output payload of the subflow
|
171 |
+
- `src_flow`: the source flow of the message
|
172 |
+
|
173 |
+
**Returns**:
|
174 |
+
|
175 |
+
`Dict[str, Any]`: the output payload of the flow
|
176 |
+
|
177 |
<a id="run_coder"></a>
|
178 |
|
179 |
# run\_coder
|
|
|
190 |
class Planner_CoderFlow(PlanWriterFlow)
|
191 |
```
|
192 |
|
193 |
+
Planner of the coder flow, it inherits from PlanWriterFlow, see: https://huggingface.co/aiflows/PlanWriterFlowModule
|
194 |
+
This flow is responsible for generating the plan for the coder flow.
|
195 |
+
|
196 |
+
*Input Interface*
|
197 |
+
- `goal`
|
198 |
+
- `memory_files`
|
199 |
+
- `code_library`
|
200 |
+
|
201 |
+
*Output Interface*
|
202 |
+
- `plan`
|
203 |
+
- `summary`
|
204 |
+
- `status`
|
205 |
+
|
206 |
+
*Configuration Parameters*:
|
207 |
+
- Look at the configuration parameters of PlanWriterFlowModule for detailed info. (https://huggingface.co/aiflows/PlanWriterFlowModule)
|
208 |
+
- `input_interface`: the input interface of the flow, default: `["goal", "memory_files", "code_library"]`
|
209 |
+
- `output_interface`: the output interface of the flow, default: `["plan", "summary", "status"]`
|
210 |
+
- `subflows_config`: configuration of the subflows.
|
211 |
+
- `topology`: topology of the subflows.
|
212 |
|
213 |
<a id="Controller_CoderFlow"></a>
|
214 |
|
|
|
222 |
class Controller_CoderFlow(ChatAtomicFlow)
|
223 |
```
|
224 |
|
225 |
+
Refer to: https://huggingface.co/aiflows/JarvisFlowModule/blob/main/Controller_JarvisFlow.py
|
226 |
+
This flow is used to control the coder flow.
|
227 |
+
|
228 |
+
*Input Interface Non Initialized*:
|
229 |
+
- `goal`
|
230 |
+
- `plan`
|
231 |
+
- `code_library`
|
232 |
+
- `logs`
|
233 |
+
- `memory_files`
|
234 |
+
|
235 |
+
*Input Interface Initialized*:
|
236 |
+
- `goal`
|
237 |
+
- `plan`
|
238 |
+
- `code_library`
|
239 |
+
- `logs`
|
240 |
+
- `memory_files`
|
241 |
+
- `result`
|
242 |
+
|
243 |
+
*Output Interface*:
|
244 |
+
- `command`
|
245 |
+
- `command_args`
|
246 |
+
|
247 |
+
*Configuration Parameters*:
|
248 |
+
- `Input Interface Non Initialized`: Input interface before the conversation is initialized.
|
249 |
+
- `Input Interface Initialized`: Input interface after the conversation is initialized.
|
250 |
+
- `Output Interface`: Output interface.
|
251 |
+
- `backend`: The backend of the LLM.
|
252 |
+
- `command`: A list of available commands for the controller to call.
|
253 |
+
- `system_message_prompt_template`: The template of the system message prompt.
|
254 |
+
- `init_human_message_prompt_template`: The template of the initial human message prompt.
|
255 |
+
- `human_message_prompt_template`: The template of the human message prompt.
|
256 |
+
- `previous_messages`: The sliding window of previous messages.
|
257 |
+
|
258 |
+
<a id="Controller_CoderFlow.Controller_CoderFlow.__init__"></a>
|
259 |
+
|
260 |
+
#### \_\_init\_\_
|
261 |
+
|
262 |
+
```python
|
263 |
+
def __init__(commands: List[Command], **kwargs)
|
264 |
+
```
|
265 |
+
|
266 |
+
Initialize the flow.
|
267 |
+
|
268 |
+
**Arguments**:
|
269 |
+
|
270 |
+
- `commands` (`List[Command]`): A list of available commands for the controller to call.
|
271 |
+
- `kwargs` (`Dict[str, Any]`): Refer to the configuration parameters.
|
272 |
+
|
273 |
+
<a id="Controller_CoderFlow.Controller_CoderFlow.instantiate_from_config"></a>
|
274 |
+
|
275 |
+
#### instantiate\_from\_config
|
276 |
+
|
277 |
+
```python
|
278 |
+
@classmethod
|
279 |
+
def instantiate_from_config(cls, config)
|
280 |
+
```
|
281 |
+
|
282 |
+
Instantiate the flow from the configuration.
|
283 |
+
|
284 |
+
**Arguments**:
|
285 |
+
|
286 |
+
- `config` (`Dict[str, Any]`): The configuration.
|
287 |
+
|
288 |
+
**Returns**:
|
289 |
+
|
290 |
+
`Controller_CoderFlow`: The instantiated flow.
|
291 |
+
|
292 |
+
<a id="Controller_CoderFlow.Controller_CoderFlow.run"></a>
|
293 |
+
|
294 |
+
#### run
|
295 |
+
|
296 |
+
```python
|
297 |
+
def run(input_data: Dict[str, Any]) -> Dict[str, Any]
|
298 |
+
```
|
299 |
+
|
300 |
+
Run the flow.
|
301 |
+
|
302 |
+
**Arguments**:
|
303 |
+
|
304 |
+
- `input_data` (`Dict[str, Any]`): The input data.
|
305 |
+
|
306 |
+
**Returns**:
|
307 |
+
|
308 |
+
`Dict[str, Any]`: The output data.
|
309 |
|
310 |
<a id="UpdatePlanAtomicFlow"></a>
|
311 |
|
|
|
329 |
*Output Interface*
|
330 |
- `result`: the result of the update plan operation
|
331 |
|
332 |
+
*Configuration Parameters*:
|
333 |
+
- `input_interface`: the input interface of the flow, default: `["updated_plan"]`
|
334 |
+
- `output_interface`: the output interface of the flow, default: `["result"]`
|
335 |
+
|
336 |
+
<a id="UpdatePlanAtomicFlow.UpdatePlanAtomicFlow.run"></a>
|
337 |
+
|
338 |
+
#### run
|
339 |
+
|
340 |
+
```python
|
341 |
+
def run(input_data: Dict[str, Any])
|
342 |
+
```
|
343 |
+
|
344 |
+
The run function of the flow.
|
345 |
+
|
346 |
+
**Arguments**:
|
347 |
+
|
348 |
+
- `input_data` (`Dict[str, Any]`): the input data to the flow
|
349 |
+
|
350 |
+
**Returns**:
|
351 |
+
|
352 |
+
`Dict[str, Any]`: the output data of the flow
|
353 |
+
|
354 |
<a id="CoderFlow"></a>
|
355 |
|
356 |
# CoderFlow
|
|
|
378 |
- `result` (str): The result of the flow, the result will be returned to the caller (i.e. JarvisFlow).
|
379 |
- `summary` (str): The summary of the flow, the summary will be logged into the logs of the caller flow (i.e. JarvisFlow).
|
380 |
|
381 |
+
*Configuration Parameters*: (Also see super class: AbstractBossFlow)
|
382 |
+
- `memory_files` (dict): The memory files of the flow. The memory files are the files that the flow reads and writes. Typically it should contain plan, logs, and code_library.
|
383 |
+
|
384 |
+
|
385 |
Typical workflow of Coder:
|
386 |
0. JarvisFlow calls Coder with a goal.
|
387 |
1. MemoryReading reads plans, logs and code library.
|
UpdatePlanAtomicFlow.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
#TODO: generalize updateplanatomicflow with the one in extendlibrary
|
2 |
from typing import Dict, Any
|
3 |
from aiflows.base_flows.atomic import AtomicFlow
|
4 |
class UpdatePlanAtomicFlow(AtomicFlow):
|
@@ -11,12 +10,29 @@ class UpdatePlanAtomicFlow(AtomicFlow):
|
|
11 |
|
12 |
*Output Interface*
|
13 |
- `result`: the result of the update plan operation
|
|
|
|
|
|
|
|
|
|
|
14 |
"""
|
15 |
def _check_input(self, input_data: Dict[str, Any]):
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
assert "memory_files" in input_data, "memory_files not passed to UpdatePlanAtomicFlow.yaml"
|
17 |
assert "plan" in input_data["memory_files"], "plan not in memory_files"
|
18 |
|
19 |
def _call(self, input_data: Dict[str, Any]):
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
try:
|
21 |
plan_file_location = input_data["memory_files"]["plan"]
|
22 |
plan_to_write = input_data["updated_plan"]
|
@@ -36,5 +52,11 @@ class UpdatePlanAtomicFlow(AtomicFlow):
|
|
36 |
self,
|
37 |
input_data: Dict[str, Any]
|
38 |
):
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
self._check_input(input_data)
|
40 |
return self._call(input_data)
|
|
|
|
|
1 |
from typing import Dict, Any
|
2 |
from aiflows.base_flows.atomic import AtomicFlow
|
3 |
class UpdatePlanAtomicFlow(AtomicFlow):
|
|
|
10 |
|
11 |
*Output Interface*
|
12 |
- `result`: the result of the update plan operation
|
13 |
+
|
14 |
+
*Configuration Parameters*:
|
15 |
+
- `input_interface`: the input interface of the flow, default: `["updated_plan"]`
|
16 |
+
- `output_interface`: the output interface of the flow, default: `["result"]`
|
17 |
+
|
18 |
"""
|
19 |
def _check_input(self, input_data: Dict[str, Any]):
|
20 |
+
"""Check if the input data is valid.
|
21 |
+
:param input_data: the input data to the flow
|
22 |
+
:type input_data: Dict[str, Any]
|
23 |
+
:raises AssertionError: if the input data is not valid
|
24 |
+
:raises AssertionError: if the input data does not contain the required keys
|
25 |
+
"""
|
26 |
assert "memory_files" in input_data, "memory_files not passed to UpdatePlanAtomicFlow.yaml"
|
27 |
assert "plan" in input_data["memory_files"], "plan not in memory_files"
|
28 |
|
29 |
def _call(self, input_data: Dict[str, Any]):
|
30 |
+
"""The main function of the flow.
|
31 |
+
:param input_data: the input data to the flow
|
32 |
+
:type input_data: Dict[str, Any]
|
33 |
+
:return: the output data of the flow
|
34 |
+
:rtype: Dict[str, Any]
|
35 |
+
"""
|
36 |
try:
|
37 |
plan_file_location = input_data["memory_files"]["plan"]
|
38 |
plan_to_write = input_data["updated_plan"]
|
|
|
52 |
self,
|
53 |
input_data: Dict[str, Any]
|
54 |
):
|
55 |
+
"""The run function of the flow.
|
56 |
+
:param input_data: the input data to the flow
|
57 |
+
:type input_data: Dict[str, Any]
|
58 |
+
:return: the output data of the flow
|
59 |
+
:rtype: Dict[str, Any]
|
60 |
+
"""
|
61 |
self._check_input(input_data)
|
62 |
return self._call(input_data)
|