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isFlow)
|
4 |
+
* [JarvisFlow](#JarvisFlow.JarvisFlow)
|
5 |
+
* [Controller\_JarvisFlow](#Controller_JarvisFlow)
|
6 |
+
* [Controller\_JarvisFlow](#Controller_JarvisFlow.Controller_JarvisFlow)
|
7 |
+
* [\_\_init\_\_](#Controller_JarvisFlow.Controller_JarvisFlow.__init__)
|
8 |
+
* [instantiate\_from\_config](#Controller_JarvisFlow.Controller_JarvisFlow.instantiate_from_config)
|
9 |
+
* [UpdatePlanAtomicFlow](#UpdatePlanAtomicFlow)
|
10 |
+
* [UpdatePlanAtomicFlow](#UpdatePlanAtomicFlow.UpdatePlanAtomicFlow)
|
11 |
+
* [Planner\_JarvisFlow](#Planner_JarvisFlow)
|
12 |
+
* [Planner\_JarvisFlow](#Planner_JarvisFlow.Planner_JarvisFlow)
|
13 |
+
* [run\_Jarvis](#run_Jarvis)
|
14 |
+
* [CtrlExMem\_JarvisFlow](#CtrlExMem_JarvisFlow)
|
15 |
+
* [CtrlExMem\_JarvisFlow](#CtrlExMem_JarvisFlow.CtrlExMem_JarvisFlow)
|
16 |
+
* [\_\_init\_\_](#__init__)
|
17 |
+
* [IntermediateAns\_Jarvis](#IntermediateAns_Jarvis)
|
18 |
+
* [IntermediateAns\_Jarvis](#IntermediateAns_Jarvis.IntermediateAns_Jarvis)
|
19 |
+
* [FinalAns\_Jarvis](#FinalAns_Jarvis)
|
20 |
+
* [FinalAns\_Jarvis](#FinalAns_Jarvis.FinalAns_Jarvis)
|
21 |
+
|
22 |
+
<a id="JarvisFlow"></a>
|
23 |
+
|
24 |
+
# JarvisFlow
|
25 |
+
|
26 |
+
<a id="JarvisFlow.JarvisFlow"></a>
|
27 |
+
|
28 |
+
## JarvisFlow Objects
|
29 |
+
|
30 |
+
```python
|
31 |
+
class JarvisFlow(AbstractBossFlow)
|
32 |
+
```
|
33 |
+
|
34 |
+
JarvisFlow is a flow module for the boss Jarvis. It inherits from AbstractBossFlow. (
|
35 |
+
https://huggingface.co/Tachi67/AbstractBossFlowModule/tree/main). Jarvis is a general purpose agent empowered by
|
36 |
+
multiple large language models and tools including a code interpreter, to take task commands in natural language,
|
37 |
+
and make plans, write and run code in an interactive fashion to finish the task.
|
38 |
+
|
39 |
+
The highlight of Jarvis is that it integrates 17 large language models, each of them prompted differently to achieve
|
40 |
+
seamless inter-model communication and model-user interaction. The structure of Jarvis ensures that it is much more
|
41 |
+
robust, flexible and memory-efficient than previous agents empowered by one single model.
|
42 |
+
What's more, Jarvis integrates modules to allow for llm's memory management, ensuring persisted mid-long term memory
|
43 |
+
and efficient short-term memory management, making its life duration much longer than single-modeled agents,
|
44 |
+
and more powerful, in that it is able to accumulate important knowledge e.g. code library. Jarvis can also take
|
45 |
+
response from the user and the environment (e.g. code execution result), and spontaneously re-plan and re-execute
|
46 |
+
to make the execution more robust and reliable.
|
47 |
+
|
48 |
+
*Configuration Parameters*:
|
49 |
+
- `memory_files` (dict): mem_name-memfile_path pairs. mem_name is the name of the memory (plan, logs, code_library),
|
50 |
+
and memfile_path is the path to the corresponding memory file. Configure this either in the .yaml file, or override
|
51 |
+
the `memory_files` entry when running the flow.
|
52 |
+
- `subflows_config` (dict): configs for subflows.
|
53 |
+
- `MemoryReading`: Module used to read in memory (https://huggingface.co/Tachi67/MemoryReadingFlowModule), output interface
|
54 |
+
configured so that it outputs the neeed memory.
|
55 |
+
- `Planner`: Module used to interactively write plans for Jarvis, the planner is implemented in the JarvisFlow.
|
56 |
+
- `CtrlExMem`: Module used to execute the plan in a controller-executor manner, and update the memory. It is implemented
|
57 |
+
in the JarvisFlow.
|
58 |
+
|
59 |
+
<a id="Controller_JarvisFlow"></a>
|
60 |
+
|
61 |
+
# Controller\_JarvisFlow
|
62 |
+
|
63 |
+
<a id="Controller_JarvisFlow.Controller_JarvisFlow"></a>
|
64 |
+
|
65 |
+
## Controller\_JarvisFlow Objects
|
66 |
+
|
67 |
+
```python
|
68 |
+
class Controller_JarvisFlow(ChatAtomicFlow)
|
69 |
+
```
|
70 |
+
|
71 |
+
This class is a controller for JarvisFlow, it takes the plan generated by the planner, logs of previous executions,
|
72 |
+
depending on the initial goal or the subsequent feedback from the branching executors (and the human), to decide which
|
73 |
+
executor to call next (or to exit by calling finish).
|
74 |
+
|
75 |
+
*Configuration Parameters*:
|
76 |
+
- `commands` (dict): a dictionary of commands that the controller can call, each command has a name, a description, and a list of input arguments.
|
77 |
+
The commands will be injected into the system message prompt template.
|
78 |
+
- `system_message_prompt_template` (str): the template for the system message prompt, there are several components needs to be injected into the
|
79 |
+
template, including the commands, plan, plan_file_location, logs, and the goal. The injection of commands is done then initalizing the flow,
|
80 |
+
the rest of the components are injected at the beginning of each run.
|
81 |
+
- `previous_messages` (int): a sliding window of previous messages that will be passed to the model. This is the central part of short-term memory management.
|
82 |
+
|
83 |
+
*Input Interface Non Initialized*:
|
84 |
+
- `goal` (str): the initial goal of the conversation, this is the input to the model.
|
85 |
+
- `memory_files` (dict): a dictionary of file locations that contains the plan, logs.
|
86 |
+
- `plan` (str): the plan generated by the planner, the plan will change (marked as done, or re-plan) as execution preceeds.
|
87 |
+
- `logs` (str): the logs of previous executions, the logs will be appended as execution preceeds.
|
88 |
+
|
89 |
+
*Input Interface Initialized*:
|
90 |
+
- `result` (str): the result of the previous execution, this is the input to the model.
|
91 |
+
- `memory_files` (dict): a dictionary of file locations that contains the plan, logs.
|
92 |
+
- `plan` (str): the plan generated by the planner, the plan will change (marked as done, or re-plan) as execution preceeds.
|
93 |
+
- `logs` (str): the logs of previous executions, the logs will be appended as execution preceeds.
|
94 |
+
- `goal` (str): the initial goal, this is kept because the goal is also injected into the system prompts so that Jarvis does not
|
95 |
+
forget what the goal is, when the memory sliding window is implemented.
|
96 |
+
|
97 |
+
*Output Interface*:
|
98 |
+
- `command` (str): the command to be executed by the executor.
|
99 |
+
- `command_args` (dict): the arguments of the command to be executed by the executor.
|
100 |
+
|
101 |
+
<a id="Controller_JarvisFlow.Controller_JarvisFlow.__init__"></a>
|
102 |
+
|
103 |
+
#### \_\_init\_\_
|
104 |
+
|
105 |
+
```python
|
106 |
+
def __init__(commands: List[Command], **kwargs)
|
107 |
+
```
|
108 |
+
|
109 |
+
Initialize the flow, inject the commands into the system message prompt template.
|
110 |
+
|
111 |
+
<a id="Controller_JarvisFlow.Controller_JarvisFlow.instantiate_from_config"></a>
|
112 |
+
|
113 |
+
#### instantiate\_from\_config
|
114 |
+
|
115 |
+
```python
|
116 |
+
@classmethod
|
117 |
+
def instantiate_from_config(cls, config)
|
118 |
+
```
|
119 |
+
|
120 |
+
Setting up the flow from the config file. In particular, setting up the prompts, backend, and commands.
|
121 |
+
|
122 |
+
<a id="UpdatePlanAtomicFlow"></a>
|
123 |
+
|
124 |
+
# UpdatePlanAtomicFlow
|
125 |
+
|
126 |
+
<a id="UpdatePlanAtomicFlow.UpdatePlanAtomicFlow"></a>
|
127 |
+
|
128 |
+
## UpdatePlanAtomicFlow Objects
|
129 |
+
|
130 |
+
```python
|
131 |
+
class UpdatePlanAtomicFlow(AtomicFlow)
|
132 |
+
```
|
133 |
+
|
134 |
+
This class is used to update the plan file with the updated plan, called by the controlller,
|
135 |
+
when it realizes one step of the plan is done, and provide the updated plan, it is exactly the same
|
136 |
+
as the old plan, except the step that is done is marked as done.
|
137 |
+
|
138 |
+
<a id="Planner_JarvisFlow"></a>
|
139 |
+
|
140 |
+
# Planner\_JarvisFlow
|
141 |
+
|
142 |
+
<a id="Planner_JarvisFlow.Planner_JarvisFlow"></a>
|
143 |
+
|
144 |
+
## Planner\_JarvisFlow Objects
|
145 |
+
|
146 |
+
```python
|
147 |
+
class Planner_JarvisFlow(PlanWriterFlow)
|
148 |
+
```
|
149 |
+
|
150 |
+
This flow inherits from PlanWriterFlow (https://huggingface.co/Tachi67/PlanWriterFlowModule), and is used to generate a plan for Jarvis.
|
151 |
+
*Input Interface*:
|
152 |
+
- `goal` (str): the goal of the planner, the goal comes from the user's query when calling Jarvis.
|
153 |
+
- `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.
|
154 |
+
|
155 |
+
*Output Interfaces*:
|
156 |
+
- `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.
|
157 |
+
- `summary` (str): the summary of the planner.
|
158 |
+
- `status` (str): the status of the planner, can be "finished" or "unfinished".
|
159 |
+
|
160 |
+
<a id="run_Jarvis"></a>
|
161 |
+
|
162 |
+
# run\_Jarvis
|
163 |
+
|
164 |
+
<a id="CtrlExMem_JarvisFlow"></a>
|
165 |
+
|
166 |
+
# CtrlExMem\_JarvisFlow
|
167 |
+
|
168 |
+
<a id="CtrlExMem_JarvisFlow.CtrlExMem_JarvisFlow"></a>
|
169 |
+
|
170 |
+
## CtrlExMem\_JarvisFlow Objects
|
171 |
+
|
172 |
+
```python
|
173 |
+
class CtrlExMem_JarvisFlow(CtrlExMemFlow)
|
174 |
+
```
|
175 |
+
|
176 |
+
This class inherits from the CtrlExMemFlow class from AbstractBossFlowModule.
|
177 |
+
See: https://huggingface.co/Tachi67/AbstractBossFlowModule/blob/main/CtrlExMemFlow.py
|
178 |
+
|
179 |
+
Take notice that:
|
180 |
+
1. In the controller, we only keep the previous 3 messages for memory management, that will be:
|
181 |
+
a. The assistant message (controller's last command)
|
182 |
+
b. Manually updated new system prompt (new logs, new plans, etc.)
|
183 |
+
c. The user message (result, feedback)
|
184 |
+
2. Each time one executor from the branch is executed, the logs is updated, this means:
|
185 |
+
a. The logs file of Jarvis is updated.
|
186 |
+
b. After MemoryReading at the end of each run of the loop, the logs in the flow_state is updated.
|
187 |
+
c. The next time the controller is called, the updated logs is injected into the system prompts.
|
188 |
+
3. In the prompts of the controller, when the controller realizes one step of the plan is done,
|
189 |
+
we ask the controller to revise what was done and mark the current step as done. This means:
|
190 |
+
a. The plan file is updated.
|
191 |
+
b. The plan in the flow_state is updated.
|
192 |
+
c. The next time the controller is called, the updated plan is injected into the system prompts.
|
193 |
+
|
194 |
+
This is basically how the memory management works, to allow for more space for llm execution, and make sure the llm
|
195 |
+
does not forget important information.
|
196 |
+
|
197 |
+
<a id="__init__"></a>
|
198 |
+
|
199 |
+
# \_\_init\_\_
|
200 |
+
|
201 |
+
<a id="IntermediateAns_Jarvis"></a>
|
202 |
+
|
203 |
+
# IntermediateAns\_Jarvis
|
204 |
+
|
205 |
+
<a id="IntermediateAns_Jarvis.IntermediateAns_Jarvis"></a>
|
206 |
+
|
207 |
+
## IntermediateAns\_Jarvis Objects
|
208 |
+
|
209 |
+
```python
|
210 |
+
class IntermediateAns_Jarvis(HumanStandardInputFlow)
|
211 |
+
```
|
212 |
+
|
213 |
+
This class inherits from the HumanStandardInputFlow class.
|
214 |
+
It is used to give an intermediate answer to the user. The user is then able to provide feedback on the intermediate result.
|
215 |
+
Depending on the user's feedback, the controller will decide to do different things (e.g. continue, re-plan, etc.)
|
216 |
+
|
217 |
+
<a id="FinalAns_Jarvis"></a>
|
218 |
+
|
219 |
+
# FinalAns\_Jarvis
|
220 |
+
|
221 |
+
<a id="FinalAns_Jarvis.FinalAns_Jarvis"></a>
|
222 |
+
|
223 |
+
## FinalAns\_Jarvis Objects
|
224 |
+
|
225 |
+
```python
|
226 |
+
class FinalAns_Jarvis(HumanStandardInputFlow)
|
227 |
+
```
|
228 |
+
|
229 |
+
This class inherits from the HumanStandardInputFlow class.
|
230 |
+
It is used to give the final answer to the user.
|
231 |
+
|