File size: 15,549 Bytes
7cccd2a 343bc6e 962d35d 343bc6e 962d35d 343bc6e 962d35d 343bc6e 962d35d 343bc6e 962d35d 343bc6e 962d35d 343bc6e 962d35d 343bc6e 962d35d 343bc6e 962d35d 343bc6e 962d35d 343bc6e 962d35d 343bc6e 962d35d 343bc6e 962d35d 343bc6e d4f3dad 962d35d 343bc6e 962d35d 343bc6e 962d35d 343bc6e 962d35d 343bc6e 962d35d 343bc6e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 |
**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**
# Table of Contents
* [JarvisFlow](#JarvisFlow)
* [JarvisFlow](#JarvisFlow.JarvisFlow)
* [Controller\_JarvisFlow](#Controller_JarvisFlow)
* [Controller\_JarvisFlow](#Controller_JarvisFlow.Controller_JarvisFlow)
* [\_\_init\_\_](#Controller_JarvisFlow.Controller_JarvisFlow.__init__)
* [instantiate\_from\_config](#Controller_JarvisFlow.Controller_JarvisFlow.instantiate_from_config)
* [run](#Controller_JarvisFlow.Controller_JarvisFlow.run)
* [UpdatePlanAtomicFlow](#UpdatePlanAtomicFlow)
* [UpdatePlanAtomicFlow](#UpdatePlanAtomicFlow.UpdatePlanAtomicFlow)
* [run](#UpdatePlanAtomicFlow.UpdatePlanAtomicFlow.run)
* [Planner\_JarvisFlow](#Planner_JarvisFlow)
* [Planner\_JarvisFlow](#Planner_JarvisFlow.Planner_JarvisFlow)
* [detect\_finish\_or\_continue](#Planner_JarvisFlow.Planner_JarvisFlow.detect_finish_or_continue)
* [run\_Jarvis](#run_Jarvis)
* [CtrlExMem\_JarvisFlow](#CtrlExMem_JarvisFlow)
* [CtrlExMem\_JarvisFlow](#CtrlExMem_JarvisFlow.CtrlExMem_JarvisFlow)
* [detect\_finish\_or\_continue](#CtrlExMem_JarvisFlow.CtrlExMem_JarvisFlow.detect_finish_or_continue)
* [\_\_init\_\_](#__init__)
* [IntermediateAns\_Jarvis](#IntermediateAns_Jarvis)
* [IntermediateAns\_Jarvis](#IntermediateAns_Jarvis.IntermediateAns_Jarvis)
* [FinalAns\_Jarvis](#FinalAns_Jarvis)
* [FinalAns\_Jarvis](#FinalAns_Jarvis.FinalAns_Jarvis)
* [run](#FinalAns_Jarvis.FinalAns_Jarvis.run)
<a id="JarvisFlow"></a>
# JarvisFlow
<a id="JarvisFlow.JarvisFlow"></a>
## JarvisFlow Objects
```python
class JarvisFlow(AbstractBossFlow)
```
JarvisFlow is a flow module for the boss Jarvis. It inherits from AbstractBossFlow. (
https://huggingface.co/aiflows/AbstractBossFlowModule/tree/main). Jarvis is a general purpose agent empowered by
multiple large language models and tools including a code interpreter, to take task commands in natural language,
and make plans, write and run code in an interactive fashion to finish the task.
The highlight of Jarvis is that it integrates 17 large language models, each of them prompted differently to achieve
seamless inter-model communication and model-user interaction. The structure of Jarvis ensures that it is much more
robust, flexible and memory-efficient than previous agents empowered by one single model.
What's more, Jarvis integrates modules to allow for llm's memory management, ensuring persisted mid-long term memory
and efficient short-term memory management, making its life duration much longer than single-modeled agents,
and more powerful, in that it is able to accumulate important knowledge e.g. code library. Jarvis can also take
response from the user and the environment (e.g. code execution result), and spontaneously re-plan and re-execute
to make the execution more robust and reliable.
*Configuration Parameters*:
- `memory_files` (dict): mem_name-memfile_path pairs. mem_name is the name of the memory (plan, logs, code_library),
and memfile_path is the path to the corresponding memory file. Configure this either in the .yaml file, or override
the `memory_files` entry when running the flow.
- `subflows_config` (dict): configs for subflows.
- `MemoryReading`: Module used to read in memory (https://huggingface.co/aiflows/MemoryReadingFlowModule), output interface
configured so that it outputs the neeed memory.
- `Planner`: Module used to interactively write plans for Jarvis, the planner is implemented in the JarvisFlow.
- `CtrlExMem`: Module used to execute the plan in a controller-executor manner, and update the memory. It is implemented
in the JarvisFlow.
**The code interpreter of Jarvis (https://huggingface.co/aiflows/InterpreterFlowModule) relies on open-interpreter (https://github.com/KillianLucas/open-interpreter)
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).**
<a id="Controller_JarvisFlow"></a>
# Controller\_JarvisFlow
<a id="Controller_JarvisFlow.Controller_JarvisFlow"></a>
## Controller\_JarvisFlow Objects
```python
class Controller_JarvisFlow(ChatAtomicFlow)
```
This class is a controller for JarvisFlow, it takes the plan generated by the planner, logs of previous executions,
depending on the initial goal or the subsequent feedback from the branching executors (and the human), to decide which
executor to call next (or to exit by calling finish).
*Configuration Parameters*:
- `commands` (dict): a dictionary of commands that the controller can call, each command has a name, a description, and a list of input arguments.
The commands will be injected into the system message prompt template.
- `system_message_prompt_template` (str): the template for the system message prompt, there are several components needs to be injected into the
template, including the commands, plan, plan_file_location, logs, and the goal. The injection of commands is done then initalizing the flow,
the rest of the components are injected at the beginning of each run.
- `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.
*Input Interface Non Initialized*:
- `goal` (str): the initial goal of the conversation, this is the input to the model.
- `memory_files` (dict): a dictionary of file locations that contains the plan, logs.
- `plan` (str): the plan generated by the planner, the plan will change (marked as done, or re-plan) as execution preceeds.
- `logs` (str): the logs of previous executions, the logs will be appended as execution preceeds.
*Input Interface Initialized*:
- `result` (str): the result of the previous execution, this is the input to the model.
- `memory_files` (dict): a dictionary of file locations that contains the plan, logs.
- `plan` (str): the plan generated by the planner, the plan will change (marked as done, or re-plan) as execution preceeds.
- `logs` (str): the logs of previous executions, the logs will be appended as execution preceeds.
- `goal` (str): the initial goal, this is kept because the goal is also injected into the system prompts so that Jarvis does not
forget what the goal is, when the memory sliding window is implemented.
*Output Interface*:
- `command` (str): the command to be executed by the executor.
- `command_args` (dict): the arguments of the command to be executed by the executor.
<a id="Controller_JarvisFlow.Controller_JarvisFlow.__init__"></a>
#### \_\_init\_\_
```python
def __init__(commands: List[Command], **kwargs)
```
Initialize the flow, inject the commands into the system message prompt template.
**Arguments**:
- `commands` (`List[Command]`): a list of commands that the controller can call.
- `kwargs` (`Dict[str, Any]`): other parameters.
<a id="Controller_JarvisFlow.Controller_JarvisFlow.instantiate_from_config"></a>
#### instantiate\_from\_config
```python
@classmethod
def instantiate_from_config(cls, config)
```
Setting up the flow from the config file. In particular, setting up the prompts, backend, and commands.
**Arguments**:
- `config` (`Dict[str, Any]`): the config file.
**Returns**:
`Controller_JarvisFlow`: the instantiated flow.
<a id="Controller_JarvisFlow.Controller_JarvisFlow.run"></a>
#### run
```python
def run(input_data: Dict[str, Any]) -> Dict[str, Any]
```
Run the flow, update the system prompts, and run the model.
**Arguments**:
- `input_data` (`Dict[str, Any]`): the input data to the flow.
**Returns**:
`Dict[str, Any]`: the output of the flow.
<a id="UpdatePlanAtomicFlow"></a>
# UpdatePlanAtomicFlow
<a id="UpdatePlanAtomicFlow.UpdatePlanAtomicFlow"></a>
## UpdatePlanAtomicFlow Objects
```python
class UpdatePlanAtomicFlow(AtomicFlow)
```
This class is used to update the plan file with the updated plan, called by the controller,
when it realizes one step of the plan is done, and provide the updated plan, it is exactly the same
as the old plan, except the step that is done is marked as done.
*Input Interface*:
- `updated_plan`: the updated plan, exactly the same as the old plan, except the step that is done is marked as done.
*Output Interface*:
- `result`: the result of the operation
*Configuration Parameters*:
- `input_interface`: the input interface of the atomic flow
- `output_interface`: the output interface of the atomic flow
<a id="UpdatePlanAtomicFlow.UpdatePlanAtomicFlow.run"></a>
#### run
```python
def run(input_data: Dict[str, Any])
```
Run the atomic flow.
**Arguments**:
- `input_data` (`Dict[str, Any]`): the input data
**Returns**:
`Dict[str, Any]`: the result of the operation
<a id="Planner_JarvisFlow"></a>
# Planner\_JarvisFlow
<a id="Planner_JarvisFlow.Planner_JarvisFlow"></a>
## Planner\_JarvisFlow Objects
```python
class Planner_JarvisFlow(PlanWriterFlow)
```
This flow inherits from PlanWriterFlow (https://huggingface.co/aiflows/PlanWriterFlowModule), and is used to generate a plan for Jarvis.
*Input Interface*:
- `goal` (str): the goal of the planner, the goal comes from the user's query when calling Jarvis.
- `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.
*Output Interfaces*:
- `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.
- `summary` (str): the summary of the planner.
- `status` (str): the status of the planner, can be "finished" or "unfinished".
*Configuration Parameters*:
- Also refer to PlanWriterFlow (https://huggingface.co/aiflows/PlanWriterFlowModule/blob/main/PlanWriterFlow.py) for more configuration parameters.
- `input_interface`: the input interface of the flow.
- `output_interface`: the output interface of the flow.
- `subflows_config`: the configuration of the subflows of the flow.
- `early_exit_key`: the key of the early exit signal in the output payload.
- `topology`: the topology of the subflows.
<a id="Planner_JarvisFlow.Planner_JarvisFlow.detect_finish_or_continue"></a>
#### detect\_finish\_or\_continue
```python
@CircularFlow.output_msg_payload_processor
def detect_finish_or_continue(output_payload: Dict[str, Any],
src_flow) -> Dict[str, Any]
```
This function is used to detect whether the planner should finish or continue.
**Arguments**:
- `output_payload` (`Dict[str, Any]`): the output payload of the flow.
- `src_flow` (`Flow`): the flow that generates the output payload.
**Returns**:
`Dict[str, Any]`: the output payload of the flow.
<a id="run_Jarvis"></a>
# run\_Jarvis
<a id="CtrlExMem_JarvisFlow"></a>
# CtrlExMem\_JarvisFlow
<a id="CtrlExMem_JarvisFlow.CtrlExMem_JarvisFlow"></a>
## CtrlExMem\_JarvisFlow Objects
```python
class CtrlExMem_JarvisFlow(CtrlExMemFlow)
```
This class inherits from the CtrlExMemFlow class from AbstractBossFlowModule.
See: https://huggingface.co/aiflows/AbstractBossFlowModule/blob/main/CtrlExMemFlow.py
*Input Interface*:
- `plan`
- `memory_files`
- `logs`
- `goal`
*Output Interface*:
- `result`
- `summary`
*Configuration Parameters*:
- `input_interface`: the input interface of the flow
- `output_interface`: the output interface of the flow
- `subflows_config`: the subflows configuration of the flow
- `topology`: the topology of the subflows
Take notice that:
1. In the controller, we only keep the previous 3 messages for memory management, that will be:
a. The assistant message (controller's last command)
b. Manually updated new system prompt (new logs, new plans, etc.)
c. The user message (result, feedback)
2. Each time one executor from the branch is executed, the logs is updated, this means:
a. The logs file of Jarvis is updated.
b. After MemoryReading at the end of each run of the loop, the logs in the flow_state is updated.
c. The next time the controller is called, the updated logs is injected into the system prompts.
3. In the prompts of the controller, when the controller realizes one step of the plan is done,
we ask the controller to revise what was done and mark the current step as done. This means:
a. The plan file is updated.
b. The plan in the flow_state is updated.
c. The next time the controller is called, the updated plan is injected into the system prompts.
This is basically how the memory management works, to allow for more space for llm execution, and make sure the llm
does not forget important information.
<a id="CtrlExMem_JarvisFlow.CtrlExMem_JarvisFlow.detect_finish_or_continue"></a>
#### detect\_finish\_or\_continue
```python
@CircularFlow.output_msg_payload_processor
def detect_finish_or_continue(output_payload: Dict[str, Any],
src_flow) -> Dict[str, Any]
```
This function is called when the JarvisFlow receives a message from one of its branches. This function
processes the message and decides whether the JarvisFlow should continue or finish.
**Arguments**:
- `output_payload` (`Dict[str, Any]`): the output payload of the branch
- `src_flow` (`str`): the source flow of the message
**Returns**:
`Dict[str, Any]`: the updated output payload
<a id="__init__"></a>
# \_\_init\_\_
<a id="IntermediateAns_Jarvis"></a>
# IntermediateAns\_Jarvis
<a id="IntermediateAns_Jarvis.IntermediateAns_Jarvis"></a>
## IntermediateAns\_Jarvis Objects
```python
class IntermediateAns_Jarvis(HumanStandardInputFlow)
```
This class inherits from the HumanStandardInputFlow class.
It is used to give an intermediate answer to the user. The user is then able to provide feedback on the intermediate result.
Depending on the user's feedback, the controller will decide to do different things (e.g. continue, re-plan, etc.)
*Input Interface*:
- `answer`: The intermediate answer to the question asked by the user.
*Output Interface*:
- `result`: User's response to the intermediate answer.
- `summary`: A summary of the action.
*Configuration parameters*:
- `query_message_prompt_template`: The template of the message that is shown to the user.
- `request_multi_line_input_flag`: A flag that indicates whether the user can give a multi-line input.
- `end_of_input_string`: The string that indicates the end of the input.
<a id="FinalAns_Jarvis"></a>
# FinalAns\_Jarvis
<a id="FinalAns_Jarvis.FinalAns_Jarvis"></a>
## FinalAns\_Jarvis Objects
```python
class FinalAns_Jarvis(HumanStandardInputFlow)
```
This class inherits from the HumanStandardInputFlow class.
It is used to give the final answer to the user.
*Input Interface*:
- `answer`: The answer to the question asked by the user.
*Output Interface*:
- `result`: User's response to the final answer.
- `summary`: A summary of the action.
*Configuration parameters*:
- `query_message_prompt_template`: The template of the message that is shown to the user.
- `request_multi_line_input_flag`: A flag that indicates whether the user can give a multi-line input.
- `end_of_input_string`: The string that indicates the end of the input.
<a id="FinalAns_Jarvis.FinalAns_Jarvis.run"></a>
#### run
```python
def run(input_data: Dict[str, Any]) -> Dict[str, Any]
```
The run method of the class.
**Arguments**:
- `input_data` (`Dict[str, Any]`): The input data of the flow.
**Returns**:
`Dict[str, Any]`: The output data of the flow.
|