Tachi67 commited on
Commit
343bc6e
·
verified ·
1 Parent(s): 6704fa0

add more comments & docs, typo fix

Browse files
Controller_JarvisFlow.py CHANGED
@@ -14,7 +14,6 @@ class Command:
14
  description: str
15
  input_args: List[str]
16
 
17
- # TODO: controller should be generalized
18
  class Controller_JarvisFlow(ChatAtomicFlow):
19
  """This class is a controller for JarvisFlow, it takes the plan generated by the planner, logs of previous executions,
20
  depending on the initial goal or the subsequent feedback from the branching executors (and the human), to decide which
@@ -50,7 +49,12 @@ class Controller_JarvisFlow(ChatAtomicFlow):
50
  self,
51
  commands: List[Command],
52
  **kwargs):
53
- """Initialize the flow, inject the commands into the system message prompt template."""
 
 
 
 
 
54
  super().__init__(**kwargs)
55
  self.system_message_prompt_template = self.system_message_prompt_template.partial(
56
  commands=self._build_commands_manual(commands),
@@ -70,12 +74,31 @@ class Controller_JarvisFlow(ChatAtomicFlow):
70
  """
71
 
72
  def _get_content_file_location(self, input_data, content_name):
 
 
 
 
 
 
 
 
 
 
73
  # get the location of the file that contains the content: plan, logs, code_library
74
  assert "memory_files" in input_data, "memory_files not passed to Jarvis/Controller"
75
  assert content_name in input_data["memory_files"], f"{content_name} not in memory files"
76
  return input_data["memory_files"][content_name]
77
 
78
  def _get_content(self, input_data, content_name):
 
 
 
 
 
 
 
 
 
79
  # get the content of the file that contains the content: plan, logs, code_library
80
  assert content_name in input_data, f"{content_name} not passed to Jarvis/Controller"
81
  content = input_data[content_name]
@@ -84,7 +107,12 @@ class Controller_JarvisFlow(ChatAtomicFlow):
84
  return content
85
  @staticmethod
86
  def _build_commands_manual(commands: List[Command]) -> str:
87
- """Build the manual for the commands."""
 
 
 
 
 
88
  ret = ""
89
  for i, command in enumerate(commands):
90
  command_input_json_schema = json.dumps(
@@ -95,7 +123,12 @@ class Controller_JarvisFlow(ChatAtomicFlow):
95
 
96
  @classmethod
97
  def instantiate_from_config(cls, config):
98
- """Setting up the flow from the config file. In particular, setting up the prompts, backend, and commands."""
 
 
 
 
 
99
  flow_config = deepcopy(config)
100
 
101
  kwargs = {"flow_config": flow_config}
@@ -118,7 +151,10 @@ class Controller_JarvisFlow(ChatAtomicFlow):
118
  return cls(**kwargs)
119
 
120
  def _update_prompts_and_input(self, input_data: Dict[str, Any]):
121
- """Hinting the model to output in json format, updating the plan, logs to the system prompts."""
 
 
 
122
  if 'goal' in input_data:
123
  input_data['goal'] += self.hint_for_model
124
  if 'result' in input_data:
@@ -133,6 +169,12 @@ class Controller_JarvisFlow(ChatAtomicFlow):
133
  )
134
 
135
  def run(self, input_data: Dict[str, Any]) -> Dict[str, Any]:
 
 
 
 
 
 
136
  self._update_prompts_and_input(input_data)
137
 
138
  # ~~~when conversation is initialized, append the updated system prompts to the chat history ~~~
 
14
  description: str
15
  input_args: List[str]
16
 
 
17
  class Controller_JarvisFlow(ChatAtomicFlow):
18
  """This class is a controller for JarvisFlow, it takes the plan generated by the planner, logs of previous executions,
19
  depending on the initial goal or the subsequent feedback from the branching executors (and the human), to decide which
 
49
  self,
50
  commands: List[Command],
51
  **kwargs):
52
+ """Initialize the flow, inject the commands into the system message prompt template.
53
+ :param commands: a list of commands that the controller can call.
54
+ :type commands: List[Command]
55
+ :param kwargs: other parameters.
56
+ :type kwargs: Dict[str, Any]
57
+ """
58
  super().__init__(**kwargs)
59
  self.system_message_prompt_template = self.system_message_prompt_template.partial(
60
  commands=self._build_commands_manual(commands),
 
74
  """
75
 
76
  def _get_content_file_location(self, input_data, content_name):
77
+ """
78
+ Get the location of the file that contains the content: plan, logs, code_library
79
+ :param input_data: the input data to the flow
80
+ :type input_data: Dict[str, Any]
81
+ :param content_name: the name of the content
82
+ :type content_name: str
83
+ :raises AssertionError: if the content is not in the memory_files
84
+ :raises AssertionError: if memory_files is not passed to the flow
85
+ :return: the location of the file that contains the content
86
+ """
87
  # get the location of the file that contains the content: plan, logs, code_library
88
  assert "memory_files" in input_data, "memory_files not passed to Jarvis/Controller"
89
  assert content_name in input_data["memory_files"], f"{content_name} not in memory files"
90
  return input_data["memory_files"][content_name]
91
 
92
  def _get_content(self, input_data, content_name):
93
+ """
94
+ Get the content of the file that contains the content: plan, logs, code_library
95
+ :param input_data: the input data to the flow
96
+ :type input_data: Dict[str, Any]
97
+ :param content_name: the name of the content
98
+ :type content_name: str
99
+ :raises AssertionError: if the content is not in the input_data
100
+ :return: the content of the file that contains the content
101
+ """
102
  # get the content of the file that contains the content: plan, logs, code_library
103
  assert content_name in input_data, f"{content_name} not passed to Jarvis/Controller"
104
  content = input_data[content_name]
 
107
  return content
108
  @staticmethod
109
  def _build_commands_manual(commands: List[Command]) -> str:
110
+ """Build the manual for the commands.
111
+ :param commands: a list of commands that the controller can call.
112
+ :type commands: List[Command]
113
+ :return: the manual for the commands.
114
+ :rtype: str
115
+ """
116
  ret = ""
117
  for i, command in enumerate(commands):
118
  command_input_json_schema = json.dumps(
 
123
 
124
  @classmethod
125
  def instantiate_from_config(cls, config):
126
+ """Setting up the flow from the config file. In particular, setting up the prompts, backend, and commands.
127
+ :param config: the config file.
128
+ :type config: Dict[str, Any]
129
+ :return: the instantiated flow.
130
+ :rtype: Controller_JarvisFlow
131
+ """
132
  flow_config = deepcopy(config)
133
 
134
  kwargs = {"flow_config": flow_config}
 
151
  return cls(**kwargs)
152
 
153
  def _update_prompts_and_input(self, input_data: Dict[str, Any]):
154
+ """Hinting the model to output in json format, updating the plan, logs to the system prompts.
155
+ :param input_data: the input data to the flow.
156
+ :type input_data: Dict[str, Any]
157
+ """
158
  if 'goal' in input_data:
159
  input_data['goal'] += self.hint_for_model
160
  if 'result' in input_data:
 
169
  )
170
 
171
  def run(self, input_data: Dict[str, Any]) -> Dict[str, Any]:
172
+ """Run the flow, update the system prompts, and run the model.
173
+ :param input_data: the input data to the flow.
174
+ :type input_data: Dict[str, Any]
175
+ :return: the output of the flow.
176
+ :rtype: Dict[str, Any]
177
+ """
178
  self._update_prompts_and_input(input_data)
179
 
180
  # ~~~when conversation is initialized, append the updated system prompts to the chat history ~~~
CtrlExMem_JarvisFlow.py CHANGED
@@ -6,7 +6,23 @@ from aiflows.base_flows import CircularFlow
6
 
7
  class CtrlExMem_JarvisFlow(CtrlExMemFlow):
8
  """This class inherits from the CtrlExMemFlow class from AbstractBossFlowModule.
9
- See: https://huggingface.co/Tachi67/AbstractBossFlowModule/blob/main/CtrlExMemFlow.py
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
  Take notice that:
12
  1. In the controller, we only keep the previous 3 messages for memory management, that will be:
@@ -27,6 +43,8 @@ class CtrlExMem_JarvisFlow(CtrlExMemFlow):
27
  does not forget important information.
28
  """
29
  def _on_reach_max_round(self):
 
 
30
  self._state_update_dict({
31
  "result": "the maximum amount of rounds was reached before the Jarvis flow has done the job",
32
  "summary": "JarvisFlow: the maximum amount of rounds was reached before the flow has done the job",
@@ -35,6 +53,15 @@ class CtrlExMem_JarvisFlow(CtrlExMemFlow):
35
 
36
  @CircularFlow.output_msg_payload_processor
37
  def detect_finish_or_continue(self, output_payload: Dict[str, Any], src_flow) -> Dict[str, Any]:
 
 
 
 
 
 
 
 
 
38
  command = output_payload["command"]
39
  if command == "finish":
40
  return {
 
6
 
7
  class CtrlExMem_JarvisFlow(CtrlExMemFlow):
8
  """This class inherits from the CtrlExMemFlow class from AbstractBossFlowModule.
9
+ See: https://huggingface.co/aiflows/AbstractBossFlowModule/blob/main/CtrlExMemFlow.py
10
+
11
+ *Input Interface*:
12
+ - `plan`
13
+ - `memory_files`
14
+ - `logs`
15
+ - `goal`
16
+
17
+ *Output Interface*:
18
+ - `result`
19
+ - `summary`
20
+
21
+ *Configuration Parameters*:
22
+ - `input_interface`: the input interface of the flow
23
+ - `output_interface`: the output interface of the flow
24
+ - `subflows_config`: the subflows configuration of the flow
25
+ - `topology`: the topology of the subflows
26
 
27
  Take notice that:
28
  1. In the controller, we only keep the previous 3 messages for memory management, that will be:
 
43
  does not forget important information.
44
  """
45
  def _on_reach_max_round(self):
46
+ """This function is called when the maximum amount of rounds is reached before the Jarvis flow has done the job.
47
+ """
48
  self._state_update_dict({
49
  "result": "the maximum amount of rounds was reached before the Jarvis flow has done the job",
50
  "summary": "JarvisFlow: the maximum amount of rounds was reached before the flow has done the job",
 
53
 
54
  @CircularFlow.output_msg_payload_processor
55
  def detect_finish_or_continue(self, output_payload: Dict[str, Any], src_flow) -> Dict[str, Any]:
56
+ """This function is called when the JarvisFlow receives a message from one of its branches. This function
57
+ processes the message and decides whether the JarvisFlow should continue or finish.
58
+ :param output_payload: the output payload of the branch
59
+ :type output_payload: Dict[str, Any]
60
+ :param src_flow: the source flow of the message
61
+ :type src_flow: str
62
+ :return: the updated output payload
63
+ :rtype: Dict[str, Any]
64
+ """
65
  command = output_payload["command"]
66
  if command == "finish":
67
  return {
FinalAns_Jarvis.py CHANGED
@@ -12,10 +12,28 @@ log = logging.get_logger(f"aiflows.{__name__}")
12
  class FinalAns_Jarvis(HumanStandardInputFlow):
13
  """This class inherits from the HumanStandardInputFlow class.
14
  It is used to give the final answer to the user.
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  """
16
  def run(self,
17
  input_data: Dict[str, Any]) -> Dict[str, Any]:
18
-
 
 
 
 
 
19
  query_message = self._get_message(self.query_message_prompt_template, input_data)
20
  state_update_message = UpdateMessage_Generic(
21
  created_by=self.flow_config['name'],
 
12
  class FinalAns_Jarvis(HumanStandardInputFlow):
13
  """This class inherits from the HumanStandardInputFlow class.
14
  It is used to give the final answer to the user.
15
+
16
+ *Input Interface*:
17
+ - `answer`: The answer to the question asked by the user.
18
+
19
+ *Output Interface*:
20
+ - `result`: User's response to the final answer.
21
+ - `summary`: A summary of the action.
22
+
23
+ *Configuration parameters*:
24
+ - `query_message_prompt_template`: The template of the message that is shown to the user.
25
+ - `request_multi_line_input_flag`: A flag that indicates whether the user can give a multi-line input.
26
+ - `end_of_input_string`: The string that indicates the end of the input.
27
+
28
  """
29
  def run(self,
30
  input_data: Dict[str, Any]) -> Dict[str, Any]:
31
+ """The run method of the class.
32
+ :param input_data: The input data of the flow.
33
+ :type input_data: Dict[str, Any]
34
+ :return: The output data of the flow.
35
+ :rtype: Dict[str, Any]
36
+ """
37
  query_message = self._get_message(self.query_message_prompt_template, input_data)
38
  state_update_message = UpdateMessage_Generic(
39
  created_by=self.flow_config['name'],
IntermediateAns_Jarvis.py CHANGED
@@ -13,6 +13,19 @@ class IntermediateAns_Jarvis(HumanStandardInputFlow):
13
  """This class inherits from the HumanStandardInputFlow class.
14
  It is used to give an intermediate answer to the user. The user is then able to provide feedback on the intermediate result.
15
  Depending on the user's feedback, the controller will decide to do different things (e.g. continue, re-plan, etc.)
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  """
17
  def run(self,
18
  input_data: Dict[str, Any]) -> Dict[str, Any]:
 
13
  """This class inherits from the HumanStandardInputFlow class.
14
  It is used to give an intermediate answer to the user. The user is then able to provide feedback on the intermediate result.
15
  Depending on the user's feedback, the controller will decide to do different things (e.g. continue, re-plan, etc.)
16
+
17
+ *Input Interface*:
18
+ - `answer`: The intermediate answer to the question asked by the user.
19
+
20
+ *Output Interface*:
21
+ - `result`: User's response to the intermediate answer.
22
+ - `summary`: A summary of the action.
23
+
24
+ *Configuration parameters*:
25
+ - `query_message_prompt_template`: The template of the message that is shown to the user.
26
+ - `request_multi_line_input_flag`: A flag that indicates whether the user can give a multi-line input.
27
+ - `end_of_input_string`: The string that indicates the end of the input.
28
+
29
  """
30
  def run(self,
31
  input_data: Dict[str, Any]) -> Dict[str, Any]:
JarvisFlow.py CHANGED
@@ -2,7 +2,7 @@ from flow_modules.aiflows.AbstractBossFlowModule import AbstractBossFlow
2
 
3
  class JarvisFlow(AbstractBossFlow):
4
  """JarvisFlow is a flow module for the boss Jarvis. It inherits from AbstractBossFlow. (
5
- https://huggingface.co/Tachi67/AbstractBossFlowModule/tree/main). Jarvis is a general purpose agent empowered by
6
  multiple large language models and tools including a code interpreter, to take task commands in natural language,
7
  and make plans, write and run code in an interactive fashion to finish the task.
8
 
@@ -20,13 +20,13 @@ class JarvisFlow(AbstractBossFlow):
20
  and memfile_path is the path to the corresponding memory file. Configure this either in the .yaml file, or override
21
  the `memory_files` entry when running the flow.
22
  - `subflows_config` (dict): configs for subflows.
23
- - `MemoryReading`: Module used to read in memory (https://huggingface.co/Tachi67/MemoryReadingFlowModule), output interface
24
  configured so that it outputs the neeed memory.
25
  - `Planner`: Module used to interactively write plans for Jarvis, the planner is implemented in the JarvisFlow.
26
  - `CtrlExMem`: Module used to execute the plan in a controller-executor manner, and update the memory. It is implemented
27
  in the JarvisFlow.
28
 
29
- **The code interpreter of Jarvis (https://huggingface.co/Tachi67/InterpreterFlowModule) relies on open-interpreter (https://github.com/KillianLucas/open-interpreter)
30
  We are extracting the specific code from open-interpreter because the litellm version of open-interpreter is not compatible with that of the current version of aiflows(v.0.1.7).**
31
  """
32
  pass
 
2
 
3
  class JarvisFlow(AbstractBossFlow):
4
  """JarvisFlow is a flow module for the boss Jarvis. It inherits from AbstractBossFlow. (
5
+ https://huggingface.co/aiflows/AbstractBossFlowModule/tree/main). Jarvis is a general purpose agent empowered by
6
  multiple large language models and tools including a code interpreter, to take task commands in natural language,
7
  and make plans, write and run code in an interactive fashion to finish the task.
8
 
 
20
  and memfile_path is the path to the corresponding memory file. Configure this either in the .yaml file, or override
21
  the `memory_files` entry when running the flow.
22
  - `subflows_config` (dict): configs for subflows.
23
+ - `MemoryReading`: Module used to read in memory (https://huggingface.co/aiflows/MemoryReadingFlowModule), output interface
24
  configured so that it outputs the neeed memory.
25
  - `Planner`: Module used to interactively write plans for Jarvis, the planner is implemented in the JarvisFlow.
26
  - `CtrlExMem`: Module used to execute the plan in a controller-executor manner, and update the memory. It is implemented
27
  in the JarvisFlow.
28
 
29
+ **The code interpreter of Jarvis (https://huggingface.co/aiflows/InterpreterFlowModule) relies on open-interpreter (https://github.com/KillianLucas/open-interpreter)
30
  We are extracting the specific code from open-interpreter because the litellm version of open-interpreter is not compatible with that of the current version of aiflows(v.0.1.7).**
31
  """
32
  pass
Planner_JarvisFlow.py CHANGED
@@ -4,7 +4,7 @@ from flow_modules.aiflows.PlanWriterFlowModule import PlanWriterFlow
4
  from aiflows.base_flows import CircularFlow
5
 
6
  class Planner_JarvisFlow(PlanWriterFlow):
7
- """This flow inherits from PlanWriterFlow (https://huggingface.co/Tachi67/PlanWriterFlowModule), and is used to generate a plan for Jarvis.
8
  *Input Interface*:
9
  - `goal` (str): the goal of the planner, the goal comes from the user's query when calling Jarvis.
10
  - `memory_files` (dict): a dictionary of memory files, the keys are the names of the memory files, the values are the locations of the memory files.
@@ -13,10 +13,26 @@ class Planner_JarvisFlow(PlanWriterFlow):
13
  - `plan` (str): the generated plan, the plan string will be written to the plan file and returned to the flow state of the Jarvis flow.
14
  - `summary` (str): the summary of the planner.
15
  - `status` (str): the status of the planner, can be "finished" or "unfinished".
 
 
 
 
 
 
 
 
 
16
  """
17
- # TODO: generalize this flow to avoid code duplication
18
  @CircularFlow.output_msg_payload_processor
19
  def detect_finish_or_continue(self, output_payload: Dict[str, Any], src_flow) -> Dict[str, Any]:
 
 
 
 
 
 
 
 
20
  command = output_payload["command"]
21
  if command == "finish":
22
  # ~~~ fetch temp file location, plan content, memory file (of upper level flow e.g. ExtLib) from flow state
 
4
  from aiflows.base_flows import CircularFlow
5
 
6
  class Planner_JarvisFlow(PlanWriterFlow):
7
+ """This flow inherits from PlanWriterFlow (https://huggingface.co/aiflows/PlanWriterFlowModule), and is used to generate a plan for Jarvis.
8
  *Input Interface*:
9
  - `goal` (str): the goal of the planner, the goal comes from the user's query when calling Jarvis.
10
  - `memory_files` (dict): a dictionary of memory files, the keys are the names of the memory files, the values are the locations of the memory files.
 
13
  - `plan` (str): the generated plan, the plan string will be written to the plan file and returned to the flow state of the Jarvis flow.
14
  - `summary` (str): the summary of the planner.
15
  - `status` (str): the status of the planner, can be "finished" or "unfinished".
16
+
17
+ *Configuration Parameters*:
18
+ - Also refer to PlanWriterFlow (https://huggingface.co/aiflows/PlanWriterFlowModule/blob/main/PlanWriterFlow.py) for more configuration parameters.
19
+ - `input_interface`: the input interface of the flow.
20
+ - `output_interface`: the output interface of the flow.
21
+ - `subflows_config`: the configuration of the subflows of the flow.
22
+ - `early_exit_key`: the key of the early exit signal in the output payload.
23
+ - `topology`: the topology of the subflows.
24
+
25
  """
 
26
  @CircularFlow.output_msg_payload_processor
27
  def detect_finish_or_continue(self, output_payload: Dict[str, Any], src_flow) -> Dict[str, Any]:
28
+ """This function is used to detect whether the planner should finish or continue.
29
+ :param output_payload: the output payload of the flow.
30
+ :type output_payload: Dict[str, Any]
31
+ :param src_flow: the flow that generates the output payload.
32
+ :type src_flow: Flow
33
+ :return: the output payload of the flow.
34
+ :rtype: Dict[str, Any]
35
+ """
36
  command = output_payload["command"]
37
  if command == "finish":
38
  # ~~~ fetch temp file location, plan content, memory file (of upper level flow e.g. ExtLib) from flow state
README.md CHANGED
@@ -1,5 +1,6 @@
1
  **For a detailed introduction to Jarvis, including Jarvis structures, an example run, etc, visit: https://huggingface.co/aiflows/JarvisFlowModule/blob/main/Introduction_to_Jarvis.md**
2
 
 
3
  # Table of Contents
4
 
5
  * [JarvisFlow](#JarvisFlow)
@@ -8,18 +9,23 @@
8
  * [Controller\_JarvisFlow](#Controller_JarvisFlow.Controller_JarvisFlow)
9
  * [\_\_init\_\_](#Controller_JarvisFlow.Controller_JarvisFlow.__init__)
10
  * [instantiate\_from\_config](#Controller_JarvisFlow.Controller_JarvisFlow.instantiate_from_config)
 
11
  * [UpdatePlanAtomicFlow](#UpdatePlanAtomicFlow)
12
  * [UpdatePlanAtomicFlow](#UpdatePlanAtomicFlow.UpdatePlanAtomicFlow)
 
13
  * [Planner\_JarvisFlow](#Planner_JarvisFlow)
14
  * [Planner\_JarvisFlow](#Planner_JarvisFlow.Planner_JarvisFlow)
 
15
  * [run\_Jarvis](#run_Jarvis)
16
  * [CtrlExMem\_JarvisFlow](#CtrlExMem_JarvisFlow)
17
  * [CtrlExMem\_JarvisFlow](#CtrlExMem_JarvisFlow.CtrlExMem_JarvisFlow)
 
18
  * [\_\_init\_\_](#__init__)
19
  * [IntermediateAns\_Jarvis](#IntermediateAns_Jarvis)
20
  * [IntermediateAns\_Jarvis](#IntermediateAns_Jarvis.IntermediateAns_Jarvis)
21
  * [FinalAns\_Jarvis](#FinalAns_Jarvis)
22
  * [FinalAns\_Jarvis](#FinalAns_Jarvis.FinalAns_Jarvis)
 
23
 
24
  <a id="JarvisFlow"></a>
25
 
@@ -34,7 +40,7 @@ class JarvisFlow(AbstractBossFlow)
34
  ```
35
 
36
  JarvisFlow is a flow module for the boss Jarvis. It inherits from AbstractBossFlow. (
37
- https://huggingface.co/Tachi67/AbstractBossFlowModule/tree/main). Jarvis is a general purpose agent empowered by
38
  multiple large language models and tools including a code interpreter, to take task commands in natural language,
39
  and make plans, write and run code in an interactive fashion to finish the task.
40
 
@@ -52,13 +58,13 @@ to make the execution more robust and reliable.
52
  and memfile_path is the path to the corresponding memory file. Configure this either in the .yaml file, or override
53
  the `memory_files` entry when running the flow.
54
  - `subflows_config` (dict): configs for subflows.
55
- - `MemoryReading`: Module used to read in memory (https://huggingface.co/Tachi67/MemoryReadingFlowModule), output interface
56
  configured so that it outputs the neeed memory.
57
  - `Planner`: Module used to interactively write plans for Jarvis, the planner is implemented in the JarvisFlow.
58
  - `CtrlExMem`: Module used to execute the plan in a controller-executor manner, and update the memory. It is implemented
59
  in the JarvisFlow.
60
 
61
- **The code interpreter of Jarvis (https://huggingface.co/Tachi67/InterpreterFlowModule) relies on open-interpreter (https://github.com/KillianLucas/open-interpreter)
62
  We are extracting the specific code from open-interpreter because the litellm version of open-interpreter is not compatible with that of the current version of aiflows(v.0.1.7).**
63
 
64
  <a id="Controller_JarvisFlow"></a>
@@ -113,6 +119,11 @@ def __init__(commands: List[Command], **kwargs)
113
 
114
  Initialize the flow, inject the commands into the system message prompt template.
115
 
 
 
 
 
 
116
  <a id="Controller_JarvisFlow.Controller_JarvisFlow.instantiate_from_config"></a>
117
 
118
  #### instantiate\_from\_config
@@ -124,6 +135,32 @@ def instantiate_from_config(cls, config)
124
 
125
  Setting up the flow from the config file. In particular, setting up the prompts, backend, and commands.
126
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
127
  <a id="UpdatePlanAtomicFlow"></a>
128
 
129
  # UpdatePlanAtomicFlow
@@ -136,10 +173,38 @@ Setting up the flow from the config file. In particular, setting up the prompts,
136
  class UpdatePlanAtomicFlow(AtomicFlow)
137
  ```
138
 
139
- This class is used to update the plan file with the updated plan, called by the controlller,
140
  when it realizes one step of the plan is done, and provide the updated plan, it is exactly the same
141
  as the old plan, except the step that is done is marked as done.
142
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
  <a id="Planner_JarvisFlow"></a>
144
 
145
  # Planner\_JarvisFlow
@@ -152,7 +217,7 @@ as the old plan, except the step that is done is marked as done.
152
  class Planner_JarvisFlow(PlanWriterFlow)
153
  ```
154
 
155
- This flow inherits from PlanWriterFlow (https://huggingface.co/Tachi67/PlanWriterFlowModule), and is used to generate a plan for Jarvis.
156
  *Input Interface*:
157
  - `goal` (str): the goal of the planner, the goal comes from the user's query when calling Jarvis.
158
  - `memory_files` (dict): a dictionary of memory files, the keys are the names of the memory files, the values are the locations of the memory files.
@@ -162,6 +227,35 @@ This flow inherits from PlanWriterFlow (https://huggingface.co/Tachi67/PlanWrite
162
  - `summary` (str): the summary of the planner.
163
  - `status` (str): the status of the planner, can be "finished" or "unfinished".
164
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165
  <a id="run_Jarvis"></a>
166
 
167
  # run\_Jarvis
@@ -179,7 +273,23 @@ class CtrlExMem_JarvisFlow(CtrlExMemFlow)
179
  ```
180
 
181
  This class inherits from the CtrlExMemFlow class from AbstractBossFlowModule.
182
- See: https://huggingface.co/Tachi67/AbstractBossFlowModule/blob/main/CtrlExMemFlow.py
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
183
 
184
  Take notice that:
185
  1. In the controller, we only keep the previous 3 messages for memory management, that will be:
@@ -199,6 +309,29 @@ Take notice that:
199
  This is basically how the memory management works, to allow for more space for llm execution, and make sure the llm
200
  does not forget important information.
201
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
202
  <a id="__init__"></a>
203
 
204
  # \_\_init\_\_
@@ -219,6 +352,18 @@ This class inherits from the HumanStandardInputFlow class.
219
  It is used to give an intermediate answer to the user. The user is then able to provide feedback on the intermediate result.
220
  Depending on the user's feedback, the controller will decide to do different things (e.g. continue, re-plan, etc.)
221
 
 
 
 
 
 
 
 
 
 
 
 
 
222
  <a id="FinalAns_Jarvis"></a>
223
 
224
  # FinalAns\_Jarvis
@@ -234,3 +379,33 @@ class FinalAns_Jarvis(HumanStandardInputFlow)
234
  This class inherits from the HumanStandardInputFlow class.
235
  It is used to give the final answer to the user.
236
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  **For a detailed introduction to Jarvis, including Jarvis structures, an example run, etc, visit: https://huggingface.co/aiflows/JarvisFlowModule/blob/main/Introduction_to_Jarvis.md**
2
 
3
+
4
  # Table of Contents
5
 
6
  * [JarvisFlow](#JarvisFlow)
 
9
  * [Controller\_JarvisFlow](#Controller_JarvisFlow.Controller_JarvisFlow)
10
  * [\_\_init\_\_](#Controller_JarvisFlow.Controller_JarvisFlow.__init__)
11
  * [instantiate\_from\_config](#Controller_JarvisFlow.Controller_JarvisFlow.instantiate_from_config)
12
+ * [run](#Controller_JarvisFlow.Controller_JarvisFlow.run)
13
  * [UpdatePlanAtomicFlow](#UpdatePlanAtomicFlow)
14
  * [UpdatePlanAtomicFlow](#UpdatePlanAtomicFlow.UpdatePlanAtomicFlow)
15
+ * [run](#UpdatePlanAtomicFlow.UpdatePlanAtomicFlow.run)
16
  * [Planner\_JarvisFlow](#Planner_JarvisFlow)
17
  * [Planner\_JarvisFlow](#Planner_JarvisFlow.Planner_JarvisFlow)
18
+ * [detect\_finish\_or\_continue](#Planner_JarvisFlow.Planner_JarvisFlow.detect_finish_or_continue)
19
  * [run\_Jarvis](#run_Jarvis)
20
  * [CtrlExMem\_JarvisFlow](#CtrlExMem_JarvisFlow)
21
  * [CtrlExMem\_JarvisFlow](#CtrlExMem_JarvisFlow.CtrlExMem_JarvisFlow)
22
+ * [detect\_finish\_or\_continue](#CtrlExMem_JarvisFlow.CtrlExMem_JarvisFlow.detect_finish_or_continue)
23
  * [\_\_init\_\_](#__init__)
24
  * [IntermediateAns\_Jarvis](#IntermediateAns_Jarvis)
25
  * [IntermediateAns\_Jarvis](#IntermediateAns_Jarvis.IntermediateAns_Jarvis)
26
  * [FinalAns\_Jarvis](#FinalAns_Jarvis)
27
  * [FinalAns\_Jarvis](#FinalAns_Jarvis.FinalAns_Jarvis)
28
+ * [run](#FinalAns_Jarvis.FinalAns_Jarvis.run)
29
 
30
  <a id="JarvisFlow"></a>
31
 
 
40
  ```
41
 
42
  JarvisFlow is a flow module for the boss Jarvis. It inherits from AbstractBossFlow. (
43
+ https://huggingface.co/aiflows/AbstractBossFlowModule/tree/main). Jarvis is a general purpose agent empowered by
44
  multiple large language models and tools including a code interpreter, to take task commands in natural language,
45
  and make plans, write and run code in an interactive fashion to finish the task.
46
 
 
58
  and memfile_path is the path to the corresponding memory file. Configure this either in the .yaml file, or override
59
  the `memory_files` entry when running the flow.
60
  - `subflows_config` (dict): configs for subflows.
61
+ - `MemoryReading`: Module used to read in memory (https://huggingface.co/aiflows/MemoryReadingFlowModule), output interface
62
  configured so that it outputs the neeed memory.
63
  - `Planner`: Module used to interactively write plans for Jarvis, the planner is implemented in the JarvisFlow.
64
  - `CtrlExMem`: Module used to execute the plan in a controller-executor manner, and update the memory. It is implemented
65
  in the JarvisFlow.
66
 
67
+ **The code interpreter of Jarvis (https://huggingface.co/aiflows/InterpreterFlowModule) relies on open-interpreter (https://github.com/KillianLucas/open-interpreter)
68
  We are extracting the specific code from open-interpreter because the litellm version of open-interpreter is not compatible with that of the current version of aiflows(v.0.1.7).**
69
 
70
  <a id="Controller_JarvisFlow"></a>
 
119
 
120
  Initialize the flow, inject the commands into the system message prompt template.
121
 
122
+ **Arguments**:
123
+
124
+ - `commands` (`List[Command]`): a list of commands that the controller can call.
125
+ - `kwargs` (`Dict[str, Any]`): other parameters.
126
+
127
  <a id="Controller_JarvisFlow.Controller_JarvisFlow.instantiate_from_config"></a>
128
 
129
  #### instantiate\_from\_config
 
135
 
136
  Setting up the flow from the config file. In particular, setting up the prompts, backend, and commands.
137
 
138
+ **Arguments**:
139
+
140
+ - `config` (`Dict[str, Any]`): the config file.
141
+
142
+ **Returns**:
143
+
144
+ `Controller_JarvisFlow`: the instantiated flow.
145
+
146
+ <a id="Controller_JarvisFlow.Controller_JarvisFlow.run"></a>
147
+
148
+ #### run
149
+
150
+ ```python
151
+ def run(input_data: Dict[str, Any]) -> Dict[str, Any]
152
+ ```
153
+
154
+ Run the flow, update the system prompts, and run the model.
155
+
156
+ **Arguments**:
157
+
158
+ - `input_data` (`Dict[str, Any]`): the input data to the flow.
159
+
160
+ **Returns**:
161
+
162
+ `Dict[str, Any]`: the output of the flow.
163
+
164
  <a id="UpdatePlanAtomicFlow"></a>
165
 
166
  # UpdatePlanAtomicFlow
 
173
  class UpdatePlanAtomicFlow(AtomicFlow)
174
  ```
175
 
176
+ This class is used to update the plan file with the updated plan, called by the controller,
177
  when it realizes one step of the plan is done, and provide the updated plan, it is exactly the same
178
  as the old plan, except the step that is done is marked as done.
179
 
180
+ *Input Interface*:
181
+ - `updated_plan`: the updated plan, exactly the same as the old plan, except the step that is done is marked as done.
182
+
183
+ *Output Interface*:
184
+ - `result`: the result of the operation
185
+
186
+ *Configuration Parameters*:
187
+ - `input_interface`: the input interface of the atomic flow
188
+ - `output_interface`: the output interface of the atomic flow
189
+
190
+ <a id="UpdatePlanAtomicFlow.UpdatePlanAtomicFlow.run"></a>
191
+
192
+ #### run
193
+
194
+ ```python
195
+ def run(input_data: Dict[str, Any])
196
+ ```
197
+
198
+ Run the atomic flow.
199
+
200
+ **Arguments**:
201
+
202
+ - `input_data` (`Dict[str, Any]`): the input data
203
+
204
+ **Returns**:
205
+
206
+ `Dict[str, Any]`: the result of the operation
207
+
208
  <a id="Planner_JarvisFlow"></a>
209
 
210
  # Planner\_JarvisFlow
 
217
  class Planner_JarvisFlow(PlanWriterFlow)
218
  ```
219
 
220
+ This flow inherits from PlanWriterFlow (https://huggingface.co/aiflows/PlanWriterFlowModule), and is used to generate a plan for Jarvis.
221
  *Input Interface*:
222
  - `goal` (str): the goal of the planner, the goal comes from the user's query when calling Jarvis.
223
  - `memory_files` (dict): a dictionary of memory files, the keys are the names of the memory files, the values are the locations of the memory files.
 
227
  - `summary` (str): the summary of the planner.
228
  - `status` (str): the status of the planner, can be "finished" or "unfinished".
229
 
230
+ *Configuration Parameters*:
231
+ - Also refer to PlanWriterFlow (https://huggingface.co/aiflows/PlanWriterFlowModule/blob/main/PlanWriterFlow.py) for more configuration parameters.
232
+ - `input_interface`: the input interface of the flow.
233
+ - `output_interface`: the output interface of the flow.
234
+ - `subflows_config`: the configuration of the subflows of the flow.
235
+ - `early_exit_key`: the key of the early exit signal in the output payload.
236
+ - `topology`: the topology of the subflows.
237
+
238
+ <a id="Planner_JarvisFlow.Planner_JarvisFlow.detect_finish_or_continue"></a>
239
+
240
+ #### detect\_finish\_or\_continue
241
+
242
+ ```python
243
+ @CircularFlow.output_msg_payload_processor
244
+ def detect_finish_or_continue(output_payload: Dict[str, Any],
245
+ src_flow) -> Dict[str, Any]
246
+ ```
247
+
248
+ This function is used to detect whether the planner should finish or continue.
249
+
250
+ **Arguments**:
251
+
252
+ - `output_payload` (`Dict[str, Any]`): the output payload of the flow.
253
+ - `src_flow` (`Flow`): the flow that generates the output payload.
254
+
255
+ **Returns**:
256
+
257
+ `Dict[str, Any]`: the output payload of the flow.
258
+
259
  <a id="run_Jarvis"></a>
260
 
261
  # run\_Jarvis
 
273
  ```
274
 
275
  This class inherits from the CtrlExMemFlow class from AbstractBossFlowModule.
276
+ See: https://huggingface.co/aiflows/AbstractBossFlowModule/blob/main/CtrlExMemFlow.py
277
+
278
+ *Input Interface*:
279
+ - `plan`
280
+ - `memory_files`
281
+ - `logs`
282
+ - `goal`
283
+
284
+ *Output Interface*:
285
+ - `result`
286
+ - `summary`
287
+
288
+ *Configuration Parameters*:
289
+ - `input_interface`: the input interface of the flow
290
+ - `output_interface`: the output interface of the flow
291
+ - `subflows_config`: the subflows configuration of the flow
292
+ - `topology`: the topology of the subflows
293
 
294
  Take notice that:
295
  1. In the controller, we only keep the previous 3 messages for memory management, that will be:
 
309
  This is basically how the memory management works, to allow for more space for llm execution, and make sure the llm
310
  does not forget important information.
311
 
312
+ <a id="CtrlExMem_JarvisFlow.CtrlExMem_JarvisFlow.detect_finish_or_continue"></a>
313
+
314
+ #### detect\_finish\_or\_continue
315
+
316
+ ```python
317
+ @CircularFlow.output_msg_payload_processor
318
+ def detect_finish_or_continue(output_payload: Dict[str, Any],
319
+ src_flow) -> Dict[str, Any]
320
+ ```
321
+
322
+ This function is called when the JarvisFlow receives a message from one of its branches. This function
323
+
324
+ processes the message and decides whether the JarvisFlow should continue or finish.
325
+
326
+ **Arguments**:
327
+
328
+ - `output_payload` (`Dict[str, Any]`): the output payload of the branch
329
+ - `src_flow` (`str`): the source flow of the message
330
+
331
+ **Returns**:
332
+
333
+ `Dict[str, Any]`: the updated output payload
334
+
335
  <a id="__init__"></a>
336
 
337
  # \_\_init\_\_
 
352
  It is used to give an intermediate answer to the user. The user is then able to provide feedback on the intermediate result.
353
  Depending on the user's feedback, the controller will decide to do different things (e.g. continue, re-plan, etc.)
354
 
355
+ *Input Interface*:
356
+ - `answer`: The intermediate answer to the question asked by the user.
357
+
358
+ *Output Interface*:
359
+ - `result`: User's response to the intermediate answer.
360
+ - `summary`: A summary of the action.
361
+
362
+ *Configuration parameters*:
363
+ - `query_message_prompt_template`: The template of the message that is shown to the user.
364
+ - `request_multi_line_input_flag`: A flag that indicates whether the user can give a multi-line input.
365
+ - `end_of_input_string`: The string that indicates the end of the input.
366
+
367
  <a id="FinalAns_Jarvis"></a>
368
 
369
  # FinalAns\_Jarvis
 
379
  This class inherits from the HumanStandardInputFlow class.
380
  It is used to give the final answer to the user.
381
 
382
+ *Input Interface*:
383
+ - `answer`: The answer to the question asked by the user.
384
+
385
+ *Output Interface*:
386
+ - `result`: User's response to the final answer.
387
+ - `summary`: A summary of the action.
388
+
389
+ *Configuration parameters*:
390
+ - `query_message_prompt_template`: The template of the message that is shown to the user.
391
+ - `request_multi_line_input_flag`: A flag that indicates whether the user can give a multi-line input.
392
+ - `end_of_input_string`: The string that indicates the end of the input.
393
+
394
+ <a id="FinalAns_Jarvis.FinalAns_Jarvis.run"></a>
395
+
396
+ #### run
397
+
398
+ ```python
399
+ def run(input_data: Dict[str, Any]) -> Dict[str, Any]
400
+ ```
401
+
402
+ The run method of the class.
403
+
404
+ **Arguments**:
405
+
406
+ - `input_data` (`Dict[str, Any]`): The input data of the flow.
407
+
408
+ **Returns**:
409
+
410
+ `Dict[str, Any]`: The output data of the flow.
411
+
UpdatePlanAtomicFlow.py CHANGED
@@ -1,16 +1,40 @@
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):
5
- """This class is used to update the plan file with the updated plan, called by the controlller,
6
  when it realizes one step of the plan is done, and provide the updated plan, it is exactly the same
7
  as the old plan, except the step that is done is marked as done.
 
 
 
 
 
 
 
 
 
 
 
8
  """
9
  def _check_input(self, input_data: Dict[str, Any]):
 
 
 
 
 
 
 
10
  assert "memory_files" in input_data, "memory_files not passed to UpdatePlanAtomicFlow.yaml"
11
  assert "plan" in input_data["memory_files"], "plan not in memory_files"
12
 
13
  def _call(self, input_data: Dict[str, Any]):
 
 
 
 
 
 
 
14
  try:
15
  plan_file_location = input_data["memory_files"]["plan"]
16
  plan_to_write = input_data["updated_plan"]
@@ -30,5 +54,12 @@ class UpdatePlanAtomicFlow(AtomicFlow):
30
  self,
31
  input_data: Dict[str, Any]
32
  ):
 
 
 
 
 
 
 
33
  self._check_input(input_data)
34
  return self._call(input_data)
 
 
1
  from typing import Dict, Any
2
  from aiflows.base_flows.atomic import AtomicFlow
3
  class UpdatePlanAtomicFlow(AtomicFlow):
4
+ """This class is used to update the plan file with the updated plan, called by the controller,
5
  when it realizes one step of the plan is done, and provide the updated plan, it is exactly the same
6
  as the old plan, except the step that is done is marked as done.
7
+
8
+ *Input Interface*:
9
+ - `updated_plan`: the updated plan, exactly the same as the old plan, except the step that is done is marked as done.
10
+
11
+ *Output Interface*:
12
+ - `result`: the result of the operation
13
+
14
+ *Configuration Parameters*:
15
+ - `input_interface`: the input interface of the atomic flow
16
+ - `output_interface`: the output interface of the atomic flow
17
+
18
  """
19
  def _check_input(self, input_data: Dict[str, Any]):
20
+ """
21
+ Check if the input data is valid.
22
+ :param input_data: the input data to be checked
23
+ :type input_data: Dict[str, Any]
24
+ :raises AssertionError: if the input data is invalid
25
+ :raises AssertionError: if the input data does not contain the plan file location
26
+ """
27
  assert "memory_files" in input_data, "memory_files not passed to UpdatePlanAtomicFlow.yaml"
28
  assert "plan" in input_data["memory_files"], "plan not in memory_files"
29
 
30
  def _call(self, input_data: Dict[str, Any]):
31
+ """
32
+ Write the updated plan to the plan file.
33
+ :param input_data: the input data
34
+ :type input_data: Dict[str, Any]
35
+ :return: the result of the operation
36
+ :rtype: Dict[str, Any]
37
+ """
38
  try:
39
  plan_file_location = input_data["memory_files"]["plan"]
40
  plan_to_write = input_data["updated_plan"]
 
54
  self,
55
  input_data: Dict[str, Any]
56
  ):
57
+ """
58
+ Run the atomic flow.
59
+ :param input_data: the input data
60
+ :type input_data: Dict[str, Any]
61
+ :return: the result of the operation
62
+ :rtype: Dict[str, Any]
63
+ """
64
  self._check_input(input_data)
65
  return self._call(input_data)