fix typo
Browse files112334567789101111121314151516171718191920212122232324252526272728293070 unmodified lines1011021031041041051061077 unmodified lines11511611711811811912012112212312112212312412512621 unmodified lines1481491501511511521531531541551561 unmodified line158159160161161162163164165166167167168169169170171171172173174100 unmodified lines27527627727827927827928028128228128228328428573 unmodified lines35936036136236336436236336436536636736636736836937037037137237337437437537637637737837924 unmodified lines404405406407407408409409## Introduction to Jarvis## Introduction to JARVIS
Jarvis is a general purpose agent built upon `aiflows`, empowered by a hierarchical structure of large language models and tools including a code interpreter. At a high level, Jarvis takes in tasks in natural language, and achieve the task by making plans, writing and executing code.JARVIS is a general purpose agent built upon `aiflows`, empowered by a hierarchical structure of large language models and tools including a code interpreter. At a high level, JARVIS takes in tasks in natural language, and achieve the task by making plans, writing and executing code.
To allow for extended the lifespan of Jarvis (constrained by token limitations of LLM APIs) and enable Jarvis to be able to utilize previously accomplished results, we implemented some interesting [memory management mechanisms](#memory-management-mechanisms).To allow for extended the lifespan of JARVIS (constrained by token limitations of LLM APIs) and enable JARVIS to be able to utilize previously accomplished results, we implemented some interesting [memory management mechanisms](#memory-management-mechanisms).
**Notice:**[The code interpreter of Jarvis]((https://huggingface.co/Tachi67/InterpreterFlowModule)) relies on **open-interpreter** (https://github.com/KillianLucas/open-interpreter) (version v0.1.15). 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).[The code interpreter of JARVIS]((https://huggingface.co/Tachi67/InterpreterFlowModule)) relies on **open-interpreter** (https://github.com/KillianLucas/open-interpreter) (version v0.1.15). 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).
### Structure of Jarvis### Structure of JARVIS
The high level structure of Jarvis is a sequence of flows.The high level structure of JARVIS is a sequence of flows.
To start with, the input of Jarvis (from the user) is `goal`, which is the task described in natural language.To start with, the input of JARVIS (from the user) is `goal`, which is the task described in natural language.
Before running Jarvis, we configure the `memory_files` for Jarvis, memory files are external memories for a flow (a careful reader may have already discovered that we also configure memory files to some other flows, please refer to [Memory Management Mechanisms](#memory-management-mechanisms) for more details). We inject the corresponding memory to the system prompts of the respective LLM chats. Before running JARVIS, we configure the `memory_files` for JARVIS, memory files are external memories for a flow (a careful reader may have already discovered that we also configure memory files to some other flows, please refer to [Memory Management Mechanisms](#memory-management-mechanisms) for more details). We inject the corresponding memory to the system prompts of the respective LLM chats.
Entering Jarvis, we first read in the memory from the memory files with `MemoryReadingFlow`. After that, we invoke the `PlanWriter`, to draft a step-by-step plan to achieve the goal given by the user. Finally, the goal, the plan, and other memory, along with the memory_files are input to the `CtrlExMemFlow`, who executes the plan in a controller-executor fashion.Entering JARVIS, we first read in the memory from the memory files with `MemoryReadingFlow`. After that, we invoke the `PlanWriter`, to draft a step-by-step plan to achieve the goal given by the user. Finally, the goal, the plan, and other memory, along with the memory_files are input to the `CtrlExMemFlow`, who executes the plan in a controller-executor fashion.
Let's cut things short, here is an illustration of the Jarvis architecture, for detailed information on all the modules involved down below, find them in the [Basic ideas and components of Jarvis](#basic-ideas-and-components-of-jarvis) section.Let's cut things short, here is an illustration of the JARVIS architecture, for detailed information on all the modules involved down below, find them in the [Basic ideas and components of JARVIS](#basic-ideas-and-components-of-jarvis) section.``` goal (input data), memory_files (configured before running Jarvis) goal (input data), memory_files (configured before running JARVIS) | v +-------------------+70 unmodified lines
```
Now, the `Executor` of Jarvis. Remember that it is a "branching" flow with several branches, for detailed information about each branch, find them in the [Basic ideas and components of Jarvis](#basic-ideas-and-components-of-jarvis) section.Now, the `Executor` of JARVIS. Remember that it is a "branching" flow with several branches, for detailed information about each branch, find them in the [Basic ideas and components of JARVIS](#basic-ideas-and-components-of-jarvis) section.``` +-------------------+ | Branching |7 unmodified lines
```
In fact, this whole structure is defined as [AbstractBoss](https://huggingface.co/Tachi67/AbstractBossFlowModule), Jarvis inherits from this abstract flow. There are other components thatIn fact, this whole structure is defined as [AbstractBoss](https://huggingface.co/Tachi67/AbstractBossFlowModule), JARVIS inherits from this abstract flow. There are other components thatinherits from this structure. for example, [Coder](https://huggingface.co/Tachi67/CoderFlowModule), [ExtendLibrary](https://huggingface.co/Tachi67/ExtendLibraryFlowModule).
#### Basic ideas and components of JarvisLet's go through some basic ideas of Jarvis and its components now.- memory: Jarvis should remember certain important memory, they include the plan (`plan`), and the history of subflows execution results (`logs`). To do this, we put them in external files, and inject them into the system prompts to controllers and other corresponding roles. There are other classes that inherits from `AbstractBoss` and have other memories, e.g. `Coder` takes the memory of `code_libarary`, which is the function signatures and docstrings of the code written by the Coder and saved in the code library.#### Basic ideas and components of JARVISLet's go through some basic ideas of JARVIS and its components now.- memory: JARVIS should remember certain important memory, they include the plan (`plan`), and the history of subflows execution results (`logs`). To do this, we put them in external files, and inject them into the system prompts to controllers and other corresponding roles. There are other classes that inherits from `AbstractBoss` and have other memories, e.g. `Coder` takes the memory of `code_libarary`, which is the function signatures and docstrings of the code written by the Coder and saved in the code library.- memory_files: A dictionary: `{memory_name: memory_file_path}`- [MemoryReadingFlow](https://huggingface.co/Tachi67/MemoryReadingFlowModule): Reads in the content of the memory files.- [PlanWriter](https://huggingface.co/Tachi67/PlanWriterFlowModule): Writes a step-by-step plan to achieve the goal in an interactive fashion. During the process of writing a plan, the user has the chance to provide feedback to or directly edit the plan just written. The PlanWriter can comprehend the user's action and make adjustments to the plan accordingly.21 unmodified lines- Whenever the chat that utilizes the sliding window is called, we inject a new system prompt with the newest memory (plan, logs, for `Coder` and some other flows, `code_library` is also injected) into the chat history.)- We crop the chat history with a tailing window of length 3, that will include the assistant's previous call, the updated system prompt, the the user's new response.
As a result, Jarvis is able to run for quite a long time, and it's able to use the code written before.As a result, JARVIS is able to run for quite a long time, and it's able to use the code written before.
### An Example run of Jarvis### An Example run of JARVIS**Before reading this section**:- This section is quite lengthy. - Please run `run_Jarvis.py` when reading this section and follow along, in this way it's much easier to understand what's going on.1 unmodified line
Here we go!- memory files configuration: - memory files for Jarvis: `plan_jarvis.txt`, `logs_jarvis.txt` - memory files for JARVIS: `plan_jarvis.txt`, `logs_jarvis.txt` - memory files for Coder: `plan_coder.txt`, `logs_coder.txt`, `library.py` - memory files for ExtendLibrary: `plan_extlib.txt`, `logs_extlib.txt`, `library.py` - memory files for [InteractiveCoder](https://huggingface.co/Tachi67/InteractiveCodeGenFlowModule): `library.py` - memory files for [TestCode](https://huggingface.co/Tachi67/TestCodeFlowModule): `library.py`- user input goal = "Download tesla's stock prices from 2022-01-01 to 2022-06-01 from yfinance, plot the prices."- run Jarvis.- run JARVIS.- MemoryReadingFlow reads in the memory files, for now, nothing is in the files.- Entering PlanWriter of Jarvis, plan of Jarvis is generated, the user is able to edit the plan directly or give feedback.- Entering PlanWriter of JARVIS, plan of JARVIS is generated, the user is able to edit the plan directly or give feedback. > Plan (Jarvis):> Plan (JARVIS):> 1. Write and run code to download Tesla's stock prices from 2022-01-01 to 2022-06-01 using python package yfinance.> 2. Write and run code to plot the downloaded stock prices using matplotlib.> 3. Give a final answer to the user.100 unmodified lines- MemoryReadingFlow of Coder reads in the memory, here, new logs will override the old logs.- The Controller of CtrlExMemFlow_Coder finishes the Coder flow and return result to the JarvisFlow.- When finishing, the CoderFlow resets, setting its flow_state and the flow_state of its subflows an an empty dict. The core takeaway here is that the chat history of the Controller of CtrlExMemFlow_Coder and CtrlExMemFlow_ExtLib (as Coder's subflow) is erased.- MemoryWritingFlow of Jarvis updates the logs of Jarvis, it records the action of Coder.- MemoryReadingFlow of Jarvis reads in the memory, here, new logs will override the old logs.- MemoryWritingFlow of JARVIS updates the logs of JARVIS, it records the action of Coder.- MemoryReadingFlow of JARVIS reads in the memory, here, new logs will override the old logs.- The Controller of CtrlExMemFlow_Jarvis calls update_plan to mark step 1 of the plan as done.- MemoryWritingFlow of Jarvis updates the logs of Jarvis, it records the action of update_plan.- MemoryReadingFlow of Jarvis reads in the memory, here, new logs will override the old logs.- MemoryWritingFlow of JARVIS updates the logs of JARVIS, it records the action of update_plan.- MemoryReadingFlow of JARVIS reads in the memory, here, new logs will override the old logs.- The Controller of CtrlExMemFlow_Jarvis calls Coder with the goal of the second step of plan.- The PlanWriter of Coder makes a plan: 73 unmodified lines- The Controller of CtrlExMemFlow_Coder updates the rest of the plan as done.- The MemoryWritingFlow of Coder updates the logs of Coder, it records the action of update_plan.- The MemoryReadingFlow of Coder reads in the memory, here, new logs will override the old logs.- The Controller of CtrlExMemFlow_Coder finishes the CoderFlow, reset the flow and go back to Jarvis.- The MemoryWritingFlow of Jarvis updates the logs of Jarvis, it records the action of Coder.- The MemoryReadingFlow of Jarvis reads in the memory, here, new logs will override the old logs.- The Controller of CtrlExMemFlow_Coder finishes the CoderFlow, reset the flow and go back to JARVIS.- The MemoryWritingFlow of JARVIS updates the logs of JARVIS, it records the action of Coder.- The MemoryReadingFlow of JARVIS reads in the memory, here, new logs will override the old logs.- The Controller of CtrlExMemFlow_Jarvis updates the plan to mark the second step of plan as done.- The MemoryWritingFlow of Jarvis updates the logs of Jarvis, it records the action of update_plan.- The MemoryReadingFlow of Jarvis reads in the memory, here, new logs will override the old logs.- The MemoryWritingFlow of JARVIS updates the logs of JARVIS, it records the action of update_plan.- The MemoryReadingFlow of JARVIS reads in the memory, here, new logs will override the old logs.- The Controller of CtrlExMemFlow_Jarvis calls final_ans to provide the final answer.- The user provides a positive feedback, for example, "lgtm".- The Controller of CtrlExMemFlow_Jarvis finishes the Jarvis flow.- The Controller of CtrlExMemFlow_Jarvis finishes the JARVIS flow.
### Future Improvements**We are currently running on V0 of Jarvis, so any contributions are more than welcome!****We are currently running on V0 of JARVIS, so any contributions are more than welcome!**
Up until the publishing of V0 Jarvis, there are several things that we would like to improve:Up until the publishing of V0 JARVIS, there are several things that we would like to improve:
- When running code tests in [TestCodeFlow](https://huggingface.co/Tachi67/TestCodeFlowModule) we should show the test results to the user and fetch for feedback before exiting the flow, and add the part of user feedback to the result returned to the controller. - This can be done by appending a subflow to ask for human feedback (like [this](https://huggingface.co/Tachi67/JarvisFlowModule/blob/main/IntermediateAns_Jarvis.py)) to [TestCodeFlow](https://huggingface.co/Tachi67/TestCodeFlowModule/blob/main/TestCodeFlow.py).24 unmodified lines
### AcknowledgementJarvis is done independently as a semester project by [Haolong Li](https://github.com/Tachi-67) ([haolong.li@epfl.ch](mailto:haolong.li@epfl.ch)) at EPFL. Very special and strong thanks to his mentor: Martin Josifoski, and semi-mentor: Nicolas Baldwin for their powerful and long-lasting help and support during the design and implementation of Jarvis, Jarvis is not possible without you guys, love you!JARVIS is done independently as a semester project by [Haolong Li](https://github.com/Tachi-67) ([haolong.li@epfl.ch](mailto:haolong.li@epfl.ch)) at EPFL. Very special and strong thanks to his mentor: Martin Josifoski, and semi-mentor: Nicolas Baldwin for their powerful and long-lasting help and support during the design and implementation of JARVIS, JARVIS is not possible without you guys, love you!
Jarvis is built under the framework of [aiflows](https://github.com/epfl-dlab/aiflows), it's cool -- try it out!JARVIS is built under the framework of [aiflows](https://github.com/epfl-dlab/aiflows), it's cool -- try it out!Introduction_to_Jarvis.md+36-36