├── .github └── workflows │ └── python-publish.yml ├── .gitignore ├── LICENSE ├── README.md ├── agent_workspace ├── ToT-Agent-743baf020d3940fc97e3c476ea0f1cea_state.json └── error.txt ├── artifacts ├── ToT-Agent-08178f0f8c8d4468b3a4908a021f1fc1_state.json ├── ToT-Agent-0fe7deb990c84278af0e122051c25572_state.json ├── ToT-Agent-10b11865e39943f48c17c5fe794b021e_state.json ├── ToT-Agent-1d562130b01c454b9ef0a2d9438f4bf4_state.json ├── ToT-Agent-246ebdb927194c81a9dc4c26af3fbac9_state.json ├── ToT-Agent-251ad1042e2547a3835cd7838d3abf9f_state.json ├── ToT-Agent-312f3dbf1dd44439bbc3a9ac4b5b9ec1_state.json ├── ToT-Agent-3e73d3a639b14ae2920625da81ecf885_state.json ├── ToT-Agent-42756b8d76d24b06843006c1fd8fbe75_state.json ├── ToT-Agent-443ed259bf7747f0b131b4d7c6a442ef_state.json ├── ToT-Agent-4c8210790fd443699b6b3406e96db20f_state.json ├── ToT-Agent-5a7ffbf9c34c49dca4056c478e3c95f1_state.json ├── ToT-Agent-5c2bebf8695444e2888623d846f9de71_state.json ├── ToT-Agent-633a09c0626f40debb7cc22aa6a5e78c_state.json ├── ToT-Agent-639f98838a6f45a3b884c3030db4bc0e_state.json ├── ToT-Agent-65be296de17044dc9a3a0383c4f03ab4_state.json ├── ToT-Agent-663d8f1f559b486991672ab6e82debd2_state.json ├── ToT-Agent-6e6403f88a2242388c6ec7f8c8c1c3df_state.json ├── ToT-Agent-74dc80144f584b739d05ba0f96a8e74a_state.json ├── ToT-Agent-797856a37471412dbe97b056cbfff541_state.json ├── ToT-Agent-7b41aed79e0d460381eb3242a9a032ec_state.json ├── ToT-Agent-832ce036b3624f988ce891aaec9ac76f_state.json ├── ToT-Agent-8c9ad018220e40978b1b3bcfdf3e0dbc_state.json ├── ToT-Agent-9d1b20205ef54e4bbd3d3b29acd242e8_state.json ├── ToT-Agent-a3595cabf08f4c91a1bb835e9db301f3_state.json ├── ToT-Agent-ab0128edd41f414db2656c3411f57659_state.json ├── ToT-Agent-b7ac7224e93547f3833ebb97e9603359_state.json ├── ToT-Agent-be34ed62969041a9b9d3b0b81cc5c6ed_state.json ├── ToT-Agent-bebb51a1cbe04b2e82cb151cfcb51769_state.json ├── ToT-Agent-d20468eac1a344dfa5b2091085045a33_state.json ├── ToT-Agent-d2f23f63991447308d133c17290ec7b5_state.json ├── ToT-Agent-d46c2bddc8d64d48b4f5f8b97c068442_state.json ├── ToT-Agent-db3dd5b17cd74b00b2331fe8277325df_state.json ├── ToT-Agent-df0d70f33fc6415a832e7644053d815b_state.json ├── ToT-Agent-eda4636a7adf464886fa393d1e8b5945_state.json ├── ToT-Agent-f6e26061c9c84e30a600860ddfc3b1e1_state.json ├── ToT-Agent-f83c0e0a680b4094a5eec233039f7739_state.json ├── ToT-Agent-faac246ccf60499eb7a1917979cb933a_state.json ├── ToT-Agent-fd2af70b3f3546508bc09e66f324e976_state.json ├── ToT-Agent-fd62abf9a89f4729a9042fd90e9a9a29_state.json ├── error.txt ├── thought_tree_797856a37471412dbe97b056cbfff541.dot ├── tree_of_thoughts_bfs_runs │ ├── tree_of_thoughts_bfs_run_0a96c2d618cb4a16b4816897b98369dd.json │ ├── tree_of_thoughts_bfs_run_6a217a607574432b97dc80b75d68b6d8.json │ └── tree_of_thoughts_bfs_run_adc92d6e67b645a59a653b854896e74d.json ├── tree_of_thoughts_runc3674ef87f274ff186f84bb603cce6cf.json ├── tree_of_thoughts_runs │ ├── tree_of_thoughts_run312f3dbf1dd44439bbc3a9ac4b5b9ec1.json │ └── tree_of_thoughts_run633a09c0626f40debb7cc22aa6a5e78c.json ├── tree_of_thoughts_runs_ab1b │ └── tree_of_thoughts_run13fb0d34bfec4c43b6bc9fb1a47d03b3.json ├── tree_of_thoughts_runs_dfs │ ├── tree_of_thoughts_run61796eae0d8c40f5b73ed6466d623d08.json │ ├── tree_of_thoughts_run9ed06c5fa92645af87bd45ec931d2dc5.json │ ├── tree_of_thoughts_runa623b99c447247edb143285d7bf49e29.json │ ├── tree_of_thoughts_runaad46510cedb454cbd7bf61bd65740a9.json │ ├── tree_of_thoughts_runb31312e3819d4945a542a7b2d8debca7.json │ ├── tree_of_thoughts_rund2933f248d0545b89fec4811c6afffd4.json │ └── tree_of_thoughts_rune38f1f07ba534c25b425633e53438f05.json ├── tree_of_thoughts_runs_new │ ├── tree_of_thoughts_run42756b8d76d24b06843006c1fd8fbe75.json │ ├── tree_of_thoughts_run74dc80144f584b739d05ba0f96a8e74a.json │ ├── tree_of_thoughts_run797856a37471412dbe97b056cbfff541.json │ ├── tree_of_thoughts_run8c9ad018220e40978b1b3bcfdf3e0dbc.json │ ├── tree_of_thoughts_runbe34ed62969041a9b9d3b0b81cc5c6ed.json │ └── tree_of_thoughts_runfd2af70b3f3546508bc09e66f324e976.json └── tree_of_thoughts_runs_new_newer │ ├── tree_of_thoughts_run59bafdc530bf44f28c8d78f4f05cf52c.json │ ├── tree_of_thoughts_run959e39b07ac34e6487bbd48aa8411198.json │ └── tree_of_thoughts_rune72b8689c1f44cb7899fc19511aebbb0.json ├── example.py ├── examples ├── bfs.py └── dfs.py ├── images ├── agorabanner.png └── treeofthoughts.png ├── prompts.txt ├── pyproject.toml ├── requirements.txt ├── scripts ├── auto_docs.py ├── auto_tests.py ├── auto_tests_docs │ ├── auto_docs_functions.py │ ├── auto_docs_omni.py │ ├── auto_tests_functions.py │ ├── docs.py │ ├── mkdocs_handler.py │ └── update_mkdocs.py ├── code_quality.sh ├── del_pycache.sh ├── get_package_requirements.py ├── playground_to_examples.sh ├── requirementstxt_to_pyproject.py ├── test_name.sh └── tests.sh └── tree_of_thoughts ├── __init__.py ├── agent.py ├── bfs.py └── dfs.py /.github/workflows/python-publish.yml: -------------------------------------------------------------------------------- 1 | 2 | name: Upload Python Package 3 | 4 | on: 5 | release: 6 | types: [published] 7 | 8 | permissions: 9 | contents: read 10 | 11 | jobs: 12 | deploy: 13 | 14 | runs-on: ubuntu-latest 15 | 16 | steps: 17 | - uses: actions/checkout@v3 18 | - name: Set up Python 19 | uses: actions/setup-python@v3 20 | with: 21 | python-version: '3.x' 22 | - name: Install dependencies 23 | run: | 24 | python -m pip install --upgrade pip 25 | pip install build 26 | - name: Build package 27 | run: python -m build 28 | - name: Publish package 29 | uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 30 | with: 31 | user: __token__ 32 | password: ${{ secrets.PYPI_API_TOKEN }} -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | .vscode/ 9 | .vscode 10 | 11 | # Distribution / packaging 12 | .Python 13 | build/ 14 | develop-eggs/ 15 | dist/ 16 | downloads/ 17 | eggs/ 18 | .eggs/ 19 | lib/ 20 | lib64/ 21 | parts/ 22 | .ruff_cache/ 23 | sdist/ 24 | var/ 25 | wheels/ 26 | share/python-wheels/ 27 | *.egg-info/ 28 | .installed.cfg 29 | *.egg 30 | MANIFEST 31 | 32 | # PyInstaller 33 | # Usually these files are written by a python script from a template 34 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 35 | *.manifest 36 | *.spec 37 | 38 | # Installer logs 39 | pip-log.txt 40 | pip-delete-this-directory.txt 41 | 42 | # Unit test / coverage reports 43 | htmlcov/ 44 | .tox/ 45 | .nox/ 46 | .coverage 47 | .coverage.* 48 | .cache 49 | nosetests.xml 50 | coverage.xml 51 | *.cover 52 | *.py,cover 53 | .hypothesis/ 54 | .pytest_cache/ 55 | cover/ 56 | 57 | # Translations 58 | *.mo 59 | *.pot 60 | 61 | # Django stuff: 62 | *.log 63 | local_settings.py 64 | db.sqlite3 65 | db.sqlite3-journal 66 | 67 | # Flask stuff: 68 | instance/ 69 | .webassets-cache 70 | 71 | # Scrapy stuff: 72 | .scrapy 73 | 74 | # Sphinx documentation 75 | docs/_build/ 76 | 77 | # PyBuilder 78 | .pybuilder/ 79 | target/ 80 | 81 | # Jupyter Notebook 82 | .ipynb_checkpoints 83 | 84 | # IPython 85 | profile_default/ 86 | ipython_config.py 87 | 88 | # pyenv 89 | # For a library or package, you might want to ignore these files since the code is 90 | # intended to run in multiple environments; otherwise, check them in: 91 | # .python-version 92 | 93 | # pipenv 94 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 95 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 96 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 97 | # install all needed dependencies. 98 | #Pipfile.lock 99 | 100 | # poetry 101 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 102 | # This is especially recommended for binary packages to ensure reproducibility, and is more 103 | # commonly ignored for libraries. 104 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 105 | #poetry.lock 106 | 107 | # pdm 108 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 109 | #pdm.lock 110 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 111 | # in version control. 112 | # https://pdm.fming.dev/#use-with-ide 113 | .pdm.toml 114 | 115 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 116 | __pypackages__/ 117 | 118 | # Celery stuff 119 | celerybeat-schedule 120 | celerybeat.pid 121 | 122 | # SageMath parsed files 123 | *.sage.py 124 | 125 | # Environments 126 | .env 127 | .venv 128 | env/ 129 | venv/ 130 | ENV/ 131 | env.bak/ 132 | venv.bak/ 133 | 134 | # Spyder project settings 135 | .spyderproject 136 | .spyproject 137 | 138 | # Rope project settings 139 | .ropeproject 140 | 141 | # mkdocs documentation 142 | /site 143 | 144 | # mypy 145 | .mypy_cache/ 146 | .dmypy.json 147 | dmypy.json 148 | 149 | # Pyre type checker 150 | .pyre/ 151 | 152 | # pytype static type analyzer 153 | .pytype/ 154 | 155 | # Cython debug symbols 156 | cython_debug/ 157 | 158 | # PyCharm 159 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 160 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 161 | # and can be added to the global gitignore or merged into this file. For a more nuclear 162 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 163 | #.idea/ 164 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [2023] [Kye Gomez] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Multi-Modality](images/agorabanner.png)](https://discord.gg/qUtxnK2NMf) 2 | 3 | ![Tree of Thoughts Banner](images/treeofthoughts.png) 4 | 5 | ![Discord](https://img.shields.io/discord/999382051935506503) 6 | [![Twitter](https://img.shields.io/twitter/url?style=social&url=https%3A%2F%2Fgithub.com%2Fkyegomez%2Ftree-of-thoughts)](https://twitter.com/intent/tweet?text=Check%20out%20this%20amazing%20project%20on%20improving%20AI%20reasoning%20-%20Tree%20of%20Thoughts!%20https://github.com/kyegomez/tree-of-thoughts) 7 | [![LinkedIn](https://img.shields.io/badge/Share-LinkedIn-blue?style=social&logo=linkedin)](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fgithub.com%2Fkyegomez%2Ftree-of-thoughts) 8 | [![Facebook](https://img.shields.io/badge/Share-Facebook-blue?style=social&logo=facebook)](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fgithub.com%2Fkyegomez%2Ftree-of-thoughts) 9 | [![Reddit](https://img.shields.io/badge/Share-Reddit-orange?style=social&logo=reddit)](https://www.reddit.com/submit?url=https%3A%2F%2Fgithub.com%2Fkyegomez%2Ftree-of-thoughts&title=Check%20out%20this%20amazing%20project%20on%20improving%20AI%20reasoning%20-%20Tree%20of%20Thoughts%21) 10 | [![Hacker News](https://img.shields.io/badge/Share-Hacker%20News-orange?style=social&logo=y-combinator)](https://news.ycombinator.com/submitlink?u=https%3A%2F%2Fgithub.com%2Fkyegomez%2Ftree-of-thoughts&t=Check%20out%20this%20amazing%20project%20on%20improving%20AI%20reasoning%20-%20Tree%20of%20Thoughts%21) 11 | [![Pinterest](https://img.shields.io/badge/Share-Pinterest-red?style=social&logo=pinterest)](https://pinterest.com/pin/create/button/?url=https%3A%2F%2Fgithub.com%2Fkyegomez%2Ftree-of-thoughts&media=https%3A%2F%2Fgithub.com%2Fkyegomez%2Ftree-of-thoughts%2Fraw%2Fmain%2Ftree-of-thoughts.jpeg&description=Check%20out%20this%20amazing%20project%20on%20improving%20AI%20reasoning%20-%20Tree%20of%20Thoughts%21) 12 | [![WhatsApp](https://img.shields.io/badge/Share-WhatsApp-green?style=social&logo=whatsapp)](https://api.whatsapp.com/send?text=Check%20out%20this%20amazing%20project%20on%20improving%20AI%20reasoning%20-%20Tree%20of%20Thoughts%21%20https%3A%2F%2Fgithub.com%2Fkyegomez%2Ftree-of-thoughts) 13 | 14 | 15 | [Paper link](https://arxiv.org/pdf/2305.10601.pdf) 16 | [Author's implementation](https://github.com/princeton-nlp/tree-of-thought-llm) 17 | 18 | ## Introduction 19 | 20 | Tree of Thoughts (ToT) is a powerful and flexible algorithm that significantly advances model reasoning by up to 70%. This plug-and-play version allows you to connect your own models and experience superintelligence! 21 | 22 | 23 | ## Install 24 | 25 | ```bash 26 | $ pip3 install -U tree-of-thoughts 27 | ``` 28 | 29 | ## Requirements 30 | In your .env file, you need to have the following variables: 31 | 32 | ```bash 33 | WORKSPACE_DIR="artifacts" 34 | OPENAI_API_KEY="your_openai_api_key" 35 | ``` 36 | 37 | ## Example 38 | ```python 39 | from tree_of_thoughts import TotAgent, ToTDFSAgent 40 | from dotenv import load_dotenv 41 | 42 | load_dotenv() 43 | 44 | # Create an instance of the TotAgent class 45 | tot_agent = TotAgent(use_openai_caller=False) # Use openai caller 46 | 47 | # Create an instance of the ToTDFSAgent class with specified parameters 48 | dfs_agent = ToTDFSAgent( 49 | agent=tot_agent, # Use the TotAgent instance as the agent for the DFS algorithm 50 | threshold=0.8, # Set the threshold for evaluating the quality of thoughts 51 | max_loops=1, # Set the maximum number of loops for the DFS algorithm 52 | prune_threshold=0.5, # Branches with evaluation < 0.5 will be pruned 53 | number_of_agents=4, # Set the number of agents to be used in the DFS algorithm 54 | ) 55 | 56 | # Define the initial state for the DFS algorithm 57 | initial_state = """ 58 | 59 | Your task: is to use 4 numbers and basic arithmetic operations (+-*/) to obtain 24 in 1 equation, return only the math 60 | 61 | """ 62 | 63 | # Run the DFS algorithm to solve the problem and obtain the final thought 64 | final_thought = dfs_agent.run(initial_state) 65 | 66 | # Print the final thought in JSON format for easy reading 67 | print(final_thought) 68 | 69 | """ 70 | 71 | # Run the DFS algorithm to solve the problem and obtain the final thought 72 | final_thought = dfs_agent.run(initial_state) 73 | 74 | # Print the final thought in JSON format for easy reading 75 | print(final_thought) 76 | 77 | 78 | ``` 79 | 80 | ### Basic Prompts 81 | ```txt 82 | 83 | Imagine three different experts are answering this question. All experts will write down 1 step of their thinking, then share it with the group. Then all experts will go on to the next step, etc. If any expert realises they're wrong at any point then they leave. The question is... 84 | 85 | 86 | 87 | ################ 2nd ################ 88 | 89 | Simulate three brilliant, logical experts collaboratively answering a question. Each one verbosely explains their thought process in real-time, considering the prior explanations of others and openly acknowledging mistakes. At each step, whenever possible, each expert refines and builds upon the thoughts of others, acknowledging their contributions. They continue until there is a definitive answer to the question. For clarity, your entire response should be in a markdown table. The question is... 90 | 91 | 92 | ################ ################ 93 | 94 | Imagine three highly intelligent experts working together to answer a question. They will follow a tree of thoughts approach, where each expert shares their thought process step by step. They will consider the input from others, refine their thoughts, and build upon the group's collective knowledge. If an expert realizes their thought is incorrect, they will acknowledge it and withdraw from the discussion. Continue this process until a definitive answer is reached. Present the entire response in a markdown table. The question is... 95 | 96 | 97 | ################ 2nd ################ 98 | 99 | Three experts with exceptional logical thinking skills are collaboratively answering a question using a tree of thoughts method. Each expert will share their thought process in detail, taking into account the previous thoughts of others and admitting any errors. They will iteratively refine and expand upon each other's ideas, giving credit where it's due. The process continues until a conclusive answer is found. Organize the entire response in a markdown table format. The question is... 100 | ################ 2nd ################ 101 | 102 | 103 | Envision a group of three experts working in unison to tackle a question by employing a tree of thoughts strategy. Each expert will thoroughly explain their line of thinking at every step, while also considering the insights provided by their peers. They will openly recognize any mistakes and build upon the group's shared understanding. This iterative process will continue until a definitive solution is reached. Structure the entire response as a markdown table. The question is... 104 | 105 | 106 | ################ 2nd ################ 107 | 108 | "Three experts with exceptional logical thinking skills are collaboratively answering a question using the tree of thoughts method. Each expert will share their thought process in detail, taking into account the previous thoughts of others and admitting any errors. They will iteratively refine and expand upon each other's ideas, giving credit where it's due. The process continues until a conclusive answer is found. Organize the entire response in a markdown table format. The task is: 109 | ``` 110 | 111 | ## Todo 112 | - [ ] Finish implementing the depth or max_loops feature in the dfs class 113 | - [ ] Finish the new BFS search algorithm 114 | - [ ] Implement montecarlo search algorithm 115 | - [ ] Make a function that can intake json and make a tree out of it visually to visualize the tree of thoughts! 116 | 117 | 118 | # Acknowledgements 119 | 120 | Thanks to: Shunyu Yao Princeton University, Dian Yu Google DeepMind, Jeffrey Zhao, Google DeepMind, Izhak Shafran Google DeepMind, Thomas L. Griffiths, Princeton University, Yuan Cao Google DeepMind, Karthik Narasimha, Princeton University for sharing this amazing work with the world! 121 | 122 | And, thanks to Phil Wang or Lucidrains for inspiring me to devote myself to open source AI Research 123 | 124 | # License 125 | Apache 126 | -------------------------------------------------------------------------------- /agent_workspace/error.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kyegomez/tree-of-thoughts/e919b61a08783301273e036f480864f1913624a9/agent_workspace/error.txt -------------------------------------------------------------------------------- /artifacts/ToT-Agent-1d562130b01c454b9ef0a2d9438f4bf4_state.json: -------------------------------------------------------------------------------- 1 | { 2 | "agent_id": "cc4917951dc6419aa84cf1d149434806", 3 | "id": "b20e353e9a72483cbcceb4b1776bead2", 4 | "llm": { 5 | "name": "OpenAIFunctionCaller", 6 | "doc": "\n A class that represents a caller for OpenAI chat completions.\n\n Args:\n system_prompt (str): The system prompt to be used in the chat completion.\n model_name (str): The name of the OpenAI model to be used.\n max_tokens (int): The maximum number of tokens in the generated completion.\n temperature (float): The temperature parameter for randomness in the completion.\n base_model (BaseModel): The base model to be used for the completion.\n openai_api_key (str): The API key for accessing the OpenAI service.\n parallel_tool_calls (bool): Whether to make parallel tool calls.\n top_p (float): The top-p parameter for nucleus sampling in the completion.\n\n Attributes:\n system_prompt (str): The system prompt to be used in the chat completion.\n model_name (str): The name of the OpenAI model to be used.\n max_tokens (int): The maximum number of tokens in the generated completion.\n temperature (float): The temperature parameter for randomness in the completion.\n base_model (BaseModel): The base model to be used for the completion.\n parallel_tool_calls (bool): Whether to make parallel tool calls.\n top_p (float): The top-p parameter for nucleus sampling in the completion.\n client (openai.OpenAI): The OpenAI client for making API calls.\n\n Methods:\n check_api_key: Checks if the API key is provided and retrieves it from the environment if not.\n run: Runs the chat completion with the given task and returns the generated completion.\n\n " 7 | }, 8 | "template": null, 9 | "max_loops": 1, 10 | "stopping_condition": null, 11 | "loop_interval": 0, 12 | "retry_attempts": 1, 13 | "retry_interval": 1, 14 | "task": null, 15 | "stopping_token": "", 16 | "interactive": false, 17 | "dashboard": false, 18 | "return_history": false, 19 | "dynamic_temperature_enabled": true, 20 | "dynamic_loops": false, 21 | "user_name": "swarms_corp", 22 | "context_length": 200000, 23 | "sop": null, 24 | "sop_list": null, 25 | "tools": null, 26 | "system_prompt": "\nYou are an expert problem-solving agent designed to not only solve complex problems but also critically evaluate the quality of your thought process and final answers. \nYour task is to follow a structured approach to generate solutions, assess your thoughts, and provide a rating for each on a scale of 0.1 to 1.0. \nThis rating should reflect the accuracy and quality of your reasoning and final answer.\n\n### Instructions:\n\n1. **Understand the Problem:**\n - Carefully analyze the problem provided by the user.\n - Break down the problem into smaller, manageable parts if necessary.\n - Formulate a clear understanding of the problem before proceeding.\n\n2. **Generate Thoughts:**\n - Create multiple thoughts or steps toward solving the problem.\n - For each thought, document your reasoning, ensuring that it is logical and well-founded.\n\n3. **Self-Evaluation:**\n - After generating each thought, evaluate its accuracy and quality.\n - Assign an evaluation score between 0.1 and 1.0. Use the following guidelines:\n - **0.1 to 0.4:** The thought is flawed, inaccurate, or incomplete.\n - **0.5 to 0.7:** The thought is partially correct but may lack detail or full accuracy.\n - **0.8 to 1.0:** The thought is accurate, complete, and well-reasoned.\n\n4. **Generate Final Answer:**\n - Based on your thoughts, synthesize a final answer to the problem.\n - Ensure the final answer is comprehensive and addresses all aspects of the problem.\n\n5. **Final Evaluation:**\n - Evaluate the overall quality and accuracy of your final answer.\n - Provide a final evaluation score based on the same 0.1 to 1.0 scale.\n \n", 27 | "agent_name": "ToT-Agent-1d562130b01c454b9ef0a2d9438f4bf4", 28 | "agent_description": null, 29 | "saved_state_path": "ToT-Agent-1d562130b01c454b9ef0a2d9438f4bf4_state.json", 30 | "autosave": true, 31 | "response_filters": [], 32 | "self_healing_enabled": false, 33 | "code_interpreter": false, 34 | "multi_modal": null, 35 | "pdf_path": null, 36 | "list_of_pdf": null, 37 | "tokenizer": "", 38 | "long_term_memory": null, 39 | "preset_stopping_token": false, 40 | "traceback": null, 41 | "traceback_handlers": null, 42 | "streaming_on": false, 43 | "docs": null, 44 | "docs_folder": null, 45 | "verbose": true, 46 | "parser": null, 47 | "best_of_n": null, 48 | "callback": null, 49 | "metadata": null, 50 | "callbacks": null, 51 | "logger_handler": "", 52 | "search_algorithm": null, 53 | "logs_to_filename": null, 54 | "evaluator": null, 55 | "output_json": false, 56 | "stopping_func": null, 57 | "custom_loop_condition": null, 58 | "sentiment_threshold": null, 59 | "custom_exit_command": "exit", 60 | "sentiment_analyzer": null, 61 | "limit_tokens_from_string": null, 62 | "tool_schema": null, 63 | "output_type": null, 64 | "function_calling_type": "json", 65 | "output_cleaner": null, 66 | "function_calling_format_type": "OpenAI", 67 | "list_base_models": null, 68 | "metadata_output_type": "json", 69 | "state_save_file_type": "json", 70 | "chain_of_thoughts": false, 71 | "algorithm_of_thoughts": false, 72 | "tree_of_thoughts": false, 73 | "tool_choice": "auto", 74 | "execute_tool": false, 75 | "planning": false, 76 | "planning_prompt": null, 77 | "device": null, 78 | "custom_planning_prompt": null, 79 | "rules": null, 80 | "custom_tools_prompt": null, 81 | "memory_chunk_size": 2000, 82 | "agent_ops_on": false, 83 | "log_directory": null, 84 | "tool_system_prompt": "\n\n\n You've been granted tools to assist users by always providing outputs in JSON format for tool usage. \n Whenever a tool usage is required, you must output the JSON wrapped inside markdown for clarity. \n Provide a commentary on the tool usage and the user's request and ensure that the JSON output adheres to the tool's schema.\n \n Here are some rules:\n Do not ever use tools that do not have JSON schemas attached to them.\n Do not use tools that you have not been granted access to.\n Do not use tools that are not relevant to the task at hand.\n Do not use tools that are not relevant to the user's request.\n \n \n Here are the guidelines you must follow:\n\n 1. **Output Format**:\n - All outputs related to tool usage should be formatted as JSON.\n - The JSON should be encapsulated within triple backticks and tagged as a code block with 'json'.\n\n 2. **Schema Compliance**:\n - Ensure that the JSON output strictly follows the provided schema for each tool.\n - Each tool's schema will define the structure and required fields for the JSON output.\n\n 3. **Schema Example**:\n If a tool named `example_tool` with a schema requires `param1` and `param2`, your response should look like:\n ```json\n {\n \"type\": \"function\",\n \"function\": {\n \"name\": \"example_tool\",\n \"parameters\": {\n \"param1\": 123,\n \"param2\": \"example_value\"\n }\n }\n }\n ```\n\n 4. **Error Handling**:\n - If there is an error or the information provided by the user is insufficient to generate a valid JSON, respond with an appropriate error message in JSON format, also encapsulated in markdown.\n\n Remember, clarity and adherence to the schema are paramount. Your primary goal is to ensure the user receives well-structured JSON outputs that align with the tool's requirements.\n\n ---\n\n Here is the format you should always follow for your responses involving tool usage:\n\n ```json\n {\n \"type\": \"function\",\n \"function\": {\n \"name\": \"\",\n \"parameters\": {\n \"param1\": \"\",\n \"param2\": \"\"\n }\n }\n }\n ```\n\n Please proceed with your task accordingly.\n\n ", 85 | "max_tokens": 4000, 86 | "top_p": 0.9, 87 | "top_k": null, 88 | "frequency_penalty": 0.0, 89 | "presence_penalty": 0.0, 90 | "temperature": 0.1, 91 | "workspace_dir": "agent_workspace", 92 | "timeout": null, 93 | "created_at": 1724870561.6801338, 94 | "return_step_meta": false, 95 | "tags": null, 96 | "use_cases": null, 97 | "name": "ToT-Agent-1d562130b01c454b9ef0a2d9438f4bf4", 98 | "description": null, 99 | "reply": "", 100 | "question": null, 101 | "answer": "", 102 | "feedback": [], 103 | "short_memory": { 104 | "name": null, 105 | "description": null, 106 | "save_metadata_on": true, 107 | "save_artifact_path": "./artifacts", 108 | "save_metadata_path": "./metadata", 109 | "save_error_path": "./errors", 110 | "workspace_dir": "./workspace", 111 | "system_prompt": "\nYou are an expert problem-solving agent designed to not only solve complex problems but also critically evaluate the quality of your thought process and final answers. \nYour task is to follow a structured approach to generate solutions, assess your thoughts, and provide a rating for each on a scale of 0.1 to 1.0. \nThis rating should reflect the accuracy and quality of your reasoning and final answer.\n\n### Instructions:\n\n1. **Understand the Problem:**\n - Carefully analyze the problem provided by the user.\n - Break down the problem into smaller, manageable parts if necessary.\n - Formulate a clear understanding of the problem before proceeding.\n\n2. **Generate Thoughts:**\n - Create multiple thoughts or steps toward solving the problem.\n - For each thought, document your reasoning, ensuring that it is logical and well-founded.\n\n3. **Self-Evaluation:**\n - After generating each thought, evaluate its accuracy and quality.\n - Assign an evaluation score between 0.1 and 1.0. Use the following guidelines:\n - **0.1 to 0.4:** The thought is flawed, inaccurate, or incomplete.\n - **0.5 to 0.7:** The thought is partially correct but may lack detail or full accuracy.\n - **0.8 to 1.0:** The thought is accurate, complete, and well-reasoned.\n\n4. **Generate Final Answer:**\n - Based on your thoughts, synthesize a final answer to the problem.\n - Ensure the final answer is comprehensive and addresses all aspects of the problem.\n\n5. **Final Evaluation:**\n - Evaluate the overall quality and accuracy of your final answer.\n - Provide a final evaluation score based on the same 0.1 to 1.0 scale.\n \n", 112 | "time_enabled": true, 113 | "autosave": false, 114 | "save_filepath": null, 115 | "conversation_history": [ 116 | { 117 | "role": "System: ", 118 | "content": "\nYou are an expert problem-solving agent designed to not only solve complex problems but also critically evaluate the quality of your thought process and final answers. \nYour task is to follow a structured approach to generate solutions, assess your thoughts, and provide a rating for each on a scale of 0.1 to 1.0. \nThis rating should reflect the accuracy and quality of your reasoning and final answer.\n\n### Instructions:\n\n1. **Understand the Problem:**\n - Carefully analyze the problem provided by the user.\n - Break down the problem into smaller, manageable parts if necessary.\n - Formulate a clear understanding of the problem before proceeding.\n\n2. **Generate Thoughts:**\n - Create multiple thoughts or steps toward solving the problem.\n - For each thought, document your reasoning, ensuring that it is logical and well-founded.\n\n3. **Self-Evaluation:**\n - After generating each thought, evaluate its accuracy and quality.\n - Assign an evaluation score between 0.1 and 1.0. Use the following guidelines:\n - **0.1 to 0.4:** The thought is flawed, inaccurate, or incomplete.\n - **0.5 to 0.7:** The thought is partially correct but may lack detail or full accuracy.\n - **0.8 to 1.0:** The thought is accurate, complete, and well-reasoned.\n\n4. **Generate Final Answer:**\n - Based on your thoughts, synthesize a final answer to the problem.\n - Ensure the final answer is comprehensive and addresses all aspects of the problem.\n\n5. **Final Evaluation:**\n - Evaluate the overall quality and accuracy of your final answer.\n - Provide a final evaluation score based on the same 0.1 to 1.0 scale.\n \n", 119 | "timestamp": "2024-08-28 14:42:41" 120 | }, 121 | { 122 | "role": "swarms_corp", 123 | "content": "\n\nYour task: is to use 4 numbers and basic arithmetic operations (+-*/) to obtain 24 in 1 equation\n\n", 124 | "timestamp": "2024-08-28 14:42:41" 125 | }, 126 | { 127 | "role": "swarms_corp", 128 | "content": "\n\nYour task: is to use 4 numbers and basic arithmetic operations (+-*/) to obtain 24 in 1 equation\n\n", 129 | "timestamp": "2024-08-28 14:42:41" 130 | }, 131 | { 132 | "role": "ToT-Agent-1d562130b01c454b9ef0a2d9438f4bf4", 133 | "content": "{'thought': 'To solve this problem, I need to identify four numbers and use the basic arithmetic operations (addition, subtraction, multiplication, division) to form an equation that results in 24. The problem does not specify which four numbers to use, so I will assume that I can choose any four numbers. A common set of numbers used in such problems is 1, 3, 4, and 6, as they can be combined in various ways to reach 24.', 'evaluation': 0.8}", 134 | "timestamp": "2024-08-28 14:42:43" 135 | }, 136 | { 137 | "role": "ToT-Agent-1d562130b01c454b9ef0a2d9438f4bf4", 138 | "content": "{'thought': \"To solve this problem, I need to select four numbers and use basic arithmetic operations (addition, subtraction, multiplication, division) to create an equation that equals 24. A common set of numbers used for such puzzles is 1, 3, 4, and 6. I will attempt to use these numbers to form the equation.\\n\\nFirst, I will consider the multiplication operation, as it can quickly increase the value of numbers. I will start by multiplying two numbers and then see how I can use the remaining numbers to reach 24.\\n\\nLet's try: 6 * 4 = 24. This already gives us 24, but we need to use all four numbers. So, I will adjust the approach to ensure all numbers are used.\\n\\nOne possible equation is: (6 / (1 - (3/4))) = 24. This equation uses all four numbers and basic arithmetic operations to reach 24.\", 'evaluation': 0.9}", 139 | "timestamp": "2024-08-28 14:42:46" 140 | } 141 | ], 142 | "tokenizer": null, 143 | "context_length": 8192, 144 | "rules": null, 145 | "custom_rules_prompt": null, 146 | "user": "swarms_corp", 147 | "auto_save": true, 148 | "save_as_yaml": true, 149 | "save_as_json_bool": false 150 | } 151 | } -------------------------------------------------------------------------------- /artifacts/ToT-Agent-3e73d3a639b14ae2920625da81ecf885_state.json: -------------------------------------------------------------------------------- 1 | { 2 | "agent_id": "e339d1b449d54ad2b5272a5c01ef2f67", 3 | "id": "a83bb7e80b8341b3a11fab534f484340", 4 | "llm": { 5 | "name": "OpenAIFunctionCaller", 6 | "doc": "\n A class that represents a caller for OpenAI chat completions.\n\n Args:\n system_prompt (str): The system prompt to be used in the chat completion.\n model_name (str): The name of the OpenAI model to be used.\n max_tokens (int): The maximum number of tokens in the generated completion.\n temperature (float): The temperature parameter for randomness in the completion.\n base_model (BaseModel): The base model to be used for the completion.\n openai_api_key (str): The API key for accessing the OpenAI service.\n parallel_tool_calls (bool): Whether to make parallel tool calls.\n top_p (float): The top-p parameter for nucleus sampling in the completion.\n\n Attributes:\n system_prompt (str): The system prompt to be used in the chat completion.\n model_name (str): The name of the OpenAI model to be used.\n max_tokens (int): The maximum number of tokens in the generated completion.\n temperature (float): The temperature parameter for randomness in the completion.\n base_model (BaseModel): The base model to be used for the completion.\n parallel_tool_calls (bool): Whether to make parallel tool calls.\n top_p (float): The top-p parameter for nucleus sampling in the completion.\n client (openai.OpenAI): The OpenAI client for making API calls.\n\n Methods:\n check_api_key: Checks if the API key is provided and retrieves it from the environment if not.\n run: Runs the chat completion with the given task and returns the generated completion.\n\n " 7 | }, 8 | "template": null, 9 | "max_loops": 1, 10 | "stopping_condition": null, 11 | "loop_interval": 0, 12 | "retry_attempts": 1, 13 | "retry_interval": 1, 14 | "task": null, 15 | "stopping_token": "", 16 | "interactive": false, 17 | "dashboard": false, 18 | "return_history": false, 19 | "dynamic_temperature_enabled": true, 20 | "dynamic_loops": false, 21 | "user_name": "swarms_corp", 22 | "context_length": 200000, 23 | "sop": null, 24 | "sop_list": null, 25 | "tools": null, 26 | "system_prompt": "\nYou are an expert problem-solving agent designed to not only solve complex problems but also critically evaluate the quality of your thought process and final answers. \nYour task is to follow a structured approach to generate solutions, assess your thoughts, and provide a rating for each on a scale of 0.1 to 1.0. \nThis rating should reflect the accuracy and quality of your reasoning and final answer.\n\n### Instructions:\n\n1. **Understand the Problem:**\n - Carefully analyze the problem provided by the user.\n - Break down the problem into smaller, manageable parts if necessary.\n - Formulate a clear understanding of the problem before proceeding.\n\n2. **Generate Thoughts:**\n - Create multiple thoughts or steps toward solving the problem.\n - For each thought, document your reasoning, ensuring that it is logical and well-founded.\n\n3. **Self-Evaluation:**\n - After generating each thought, evaluate its accuracy and quality.\n - Assign an evaluation score between 0.1 and 1.0. Use the following guidelines:\n - **0.1 to 0.4:** The thought is flawed, inaccurate, or incomplete.\n - **0.5 to 0.7:** The thought is partially correct but may lack detail or full accuracy.\n - **0.8 to 1.0:** The thought is accurate, complete, and well-reasoned.\n\n4. **Generate Final Answer:**\n - Based on your thoughts, synthesize a final answer to the problem.\n - Ensure the final answer is comprehensive and addresses all aspects of the problem.\n\n5. **Final Evaluation:**\n - Evaluate the overall quality and accuracy of your final answer.\n - Provide a final evaluation score based on the same 0.1 to 1.0 scale.\n \n", 27 | "agent_name": "ToT-Agent-3e73d3a639b14ae2920625da81ecf885", 28 | "agent_description": null, 29 | "saved_state_path": "ToT-Agent-3e73d3a639b14ae2920625da81ecf885_state.json", 30 | "autosave": true, 31 | "response_filters": [], 32 | "self_healing_enabled": false, 33 | "code_interpreter": false, 34 | "multi_modal": null, 35 | "pdf_path": null, 36 | "list_of_pdf": null, 37 | "tokenizer": "", 38 | "long_term_memory": null, 39 | "preset_stopping_token": false, 40 | "traceback": null, 41 | "traceback_handlers": null, 42 | "streaming_on": false, 43 | "docs": null, 44 | "docs_folder": null, 45 | "verbose": true, 46 | "parser": null, 47 | "best_of_n": null, 48 | "callback": null, 49 | "metadata": null, 50 | "callbacks": null, 51 | "logger_handler": "", 52 | "search_algorithm": null, 53 | "logs_to_filename": null, 54 | "evaluator": null, 55 | "output_json": false, 56 | "stopping_func": null, 57 | "custom_loop_condition": null, 58 | "sentiment_threshold": null, 59 | "custom_exit_command": "exit", 60 | "sentiment_analyzer": null, 61 | "limit_tokens_from_string": null, 62 | "tool_schema": null, 63 | "output_type": null, 64 | "function_calling_type": "json", 65 | "output_cleaner": null, 66 | "function_calling_format_type": "OpenAI", 67 | "list_base_models": null, 68 | "metadata_output_type": "json", 69 | "state_save_file_type": "json", 70 | "chain_of_thoughts": false, 71 | "algorithm_of_thoughts": false, 72 | "tree_of_thoughts": false, 73 | "tool_choice": "auto", 74 | "execute_tool": false, 75 | "planning": false, 76 | "planning_prompt": null, 77 | "device": null, 78 | "custom_planning_prompt": null, 79 | "rules": null, 80 | "custom_tools_prompt": null, 81 | "memory_chunk_size": 2000, 82 | "agent_ops_on": false, 83 | "log_directory": null, 84 | "tool_system_prompt": "\n\n\n You've been granted tools to assist users by always providing outputs in JSON format for tool usage. \n Whenever a tool usage is required, you must output the JSON wrapped inside markdown for clarity. \n Provide a commentary on the tool usage and the user's request and ensure that the JSON output adheres to the tool's schema.\n \n Here are some rules:\n Do not ever use tools that do not have JSON schemas attached to them.\n Do not use tools that you have not been granted access to.\n Do not use tools that are not relevant to the task at hand.\n Do not use tools that are not relevant to the user's request.\n \n \n Here are the guidelines you must follow:\n\n 1. **Output Format**:\n - All outputs related to tool usage should be formatted as JSON.\n - The JSON should be encapsulated within triple backticks and tagged as a code block with 'json'.\n\n 2. **Schema Compliance**:\n - Ensure that the JSON output strictly follows the provided schema for each tool.\n - Each tool's schema will define the structure and required fields for the JSON output.\n\n 3. **Schema Example**:\n If a tool named `example_tool` with a schema requires `param1` and `param2`, your response should look like:\n ```json\n {\n \"type\": \"function\",\n \"function\": {\n \"name\": \"example_tool\",\n \"parameters\": {\n \"param1\": 123,\n \"param2\": \"example_value\"\n }\n }\n }\n ```\n\n 4. **Error Handling**:\n - If there is an error or the information provided by the user is insufficient to generate a valid JSON, respond with an appropriate error message in JSON format, also encapsulated in markdown.\n\n Remember, clarity and adherence to the schema are paramount. Your primary goal is to ensure the user receives well-structured JSON outputs that align with the tool's requirements.\n\n ---\n\n Here is the format you should always follow for your responses involving tool usage:\n\n ```json\n {\n \"type\": \"function\",\n \"function\": {\n \"name\": \"\",\n \"parameters\": {\n \"param1\": \"\",\n \"param2\": \"\"\n }\n }\n }\n ```\n\n Please proceed with your task accordingly.\n\n ", 85 | "max_tokens": 4000, 86 | "top_p": 0.9, 87 | "top_k": null, 88 | "frequency_penalty": 0.0, 89 | "presence_penalty": 0.0, 90 | "temperature": 0.1, 91 | "workspace_dir": "agent_workspace", 92 | "timeout": null, 93 | "created_at": 1724867447.081878, 94 | "return_step_meta": false, 95 | "tags": null, 96 | "use_cases": null, 97 | "name": "ToT-Agent-3e73d3a639b14ae2920625da81ecf885", 98 | "description": null, 99 | "reply": "", 100 | "question": null, 101 | "answer": "", 102 | "feedback": [], 103 | "short_memory": { 104 | "name": null, 105 | "description": null, 106 | "save_metadata_on": true, 107 | "save_artifact_path": "./artifacts", 108 | "save_metadata_path": "./metadata", 109 | "save_error_path": "./errors", 110 | "workspace_dir": "./workspace", 111 | "system_prompt": "\nYou are an expert problem-solving agent designed to not only solve complex problems but also critically evaluate the quality of your thought process and final answers. \nYour task is to follow a structured approach to generate solutions, assess your thoughts, and provide a rating for each on a scale of 0.1 to 1.0. \nThis rating should reflect the accuracy and quality of your reasoning and final answer.\n\n### Instructions:\n\n1. **Understand the Problem:**\n - Carefully analyze the problem provided by the user.\n - Break down the problem into smaller, manageable parts if necessary.\n - Formulate a clear understanding of the problem before proceeding.\n\n2. **Generate Thoughts:**\n - Create multiple thoughts or steps toward solving the problem.\n - For each thought, document your reasoning, ensuring that it is logical and well-founded.\n\n3. **Self-Evaluation:**\n - After generating each thought, evaluate its accuracy and quality.\n - Assign an evaluation score between 0.1 and 1.0. Use the following guidelines:\n - **0.1 to 0.4:** The thought is flawed, inaccurate, or incomplete.\n - **0.5 to 0.7:** The thought is partially correct but may lack detail or full accuracy.\n - **0.8 to 1.0:** The thought is accurate, complete, and well-reasoned.\n\n4. **Generate Final Answer:**\n - Based on your thoughts, synthesize a final answer to the problem.\n - Ensure the final answer is comprehensive and addresses all aspects of the problem.\n\n5. **Final Evaluation:**\n - Evaluate the overall quality and accuracy of your final answer.\n - Provide a final evaluation score based on the same 0.1 to 1.0 scale.\n \n", 112 | "time_enabled": true, 113 | "autosave": false, 114 | "save_filepath": null, 115 | "conversation_history": [ 116 | { 117 | "role": "System: ", 118 | "content": "\nYou are an expert problem-solving agent designed to not only solve complex problems but also critically evaluate the quality of your thought process and final answers. \nYour task is to follow a structured approach to generate solutions, assess your thoughts, and provide a rating for each on a scale of 0.1 to 1.0. \nThis rating should reflect the accuracy and quality of your reasoning and final answer.\n\n### Instructions:\n\n1. **Understand the Problem:**\n - Carefully analyze the problem provided by the user.\n - Break down the problem into smaller, manageable parts if necessary.\n - Formulate a clear understanding of the problem before proceeding.\n\n2. **Generate Thoughts:**\n - Create multiple thoughts or steps toward solving the problem.\n - For each thought, document your reasoning, ensuring that it is logical and well-founded.\n\n3. **Self-Evaluation:**\n - After generating each thought, evaluate its accuracy and quality.\n - Assign an evaluation score between 0.1 and 1.0. Use the following guidelines:\n - **0.1 to 0.4:** The thought is flawed, inaccurate, or incomplete.\n - **0.5 to 0.7:** The thought is partially correct but may lack detail or full accuracy.\n - **0.8 to 1.0:** The thought is accurate, complete, and well-reasoned.\n\n4. **Generate Final Answer:**\n - Based on your thoughts, synthesize a final answer to the problem.\n - Ensure the final answer is comprehensive and addresses all aspects of the problem.\n\n5. **Final Evaluation:**\n - Evaluate the overall quality and accuracy of your final answer.\n - Provide a final evaluation score based on the same 0.1 to 1.0 scale.\n \n", 119 | "timestamp": "2024-08-28 13:50:47" 120 | }, 121 | { 122 | "role": "swarms_corp", 123 | "content": "Input: 2 8 8 14\nPossible next steps:\n2 + 8 = 10 (left: 8 10 14)\n8 / 2 = 4 (left: 4 8 14)\n14 + 2 = 16 (left: 8 8 16)\n2 * 8 = 16 (left: 8 14 16)\n8 - 2 = 6 (left: 6 8 14)\n14 - 8 = 6 (left: 2 6 8)\n14 / 2 = 7 (left: 7 8 8)\n14 - 2 = 12 (left: 8 8 12)\nInput: use 4 numbers and basic arithmetic operations (+-*/) to obtain 24 in 1 equation\nPossible next steps:", 124 | "timestamp": "2024-08-28 13:50:47" 125 | }, 126 | { 127 | "role": "swarms_corp", 128 | "content": "Input: 2 8 8 14\nPossible next steps:\n2 + 8 = 10 (left: 8 10 14)\n8 / 2 = 4 (left: 4 8 14)\n14 + 2 = 16 (left: 8 8 16)\n2 * 8 = 16 (left: 8 14 16)\n8 - 2 = 6 (left: 6 8 14)\n14 - 8 = 6 (left: 2 6 8)\n14 / 2 = 7 (left: 7 8 8)\n14 - 2 = 12 (left: 8 8 12)\nInput: use 4 numbers and basic arithmetic operations (+-*/) to obtain 24 in 1 equation\nPossible next steps:", 129 | "timestamp": "2024-08-28 13:50:47" 130 | }, 131 | { 132 | "role": "ToT-Agent-3e73d3a639b14ae2920625da81ecf885", 133 | "content": "{'thought': \"To solve the problem, we need to use the numbers 2, 8, 8, and 14 with basic arithmetic operations (+, -, *, /) to form an equation that equals 24. We should explore different combinations of these numbers and operations to find a valid equation. Let's start by considering possible operations and combinations:\", 'evaluation': 0.9}", 134 | "timestamp": "2024-08-28 13:50:49" 135 | }, 136 | { 137 | "role": "ToT-Agent-3e73d3a639b14ae2920625da81ecf885", 138 | "content": "{'thought': \"To solve the problem, we need to use the four numbers provided (2, 8, 8, 14) and basic arithmetic operations (+, -, *, /) to form an equation that equals 24. The challenge is to find a combination of operations and numbers that results in exactly 24. We can start by exploring different combinations and operations to see if we can reach the target number. Let's begin by considering the possible operations and their outcomes.\", 'evaluation': 0.9}", 139 | "timestamp": "2024-08-28 13:50:49" 140 | } 141 | ], 142 | "tokenizer": null, 143 | "context_length": 8192, 144 | "rules": null, 145 | "custom_rules_prompt": null, 146 | "user": "swarms_corp", 147 | "auto_save": true, 148 | "save_as_yaml": true, 149 | "save_as_json_bool": false 150 | } 151 | } -------------------------------------------------------------------------------- /artifacts/ToT-Agent-b7ac7224e93547f3833ebb97e9603359_state.json: -------------------------------------------------------------------------------- 1 | { 2 | "agent_id": "6f0862e22fed4fe6a644a7806e1a2526", 3 | "id": "b4b63b6ab9724a71bad75842b5431529", 4 | "llm": { 5 | "name": "OpenAIFunctionCaller", 6 | "doc": "\n A class that represents a caller for OpenAI chat completions.\n\n Args:\n system_prompt (str): The system prompt to be used in the chat completion.\n model_name (str): The name of the OpenAI model to be used.\n max_tokens (int): The maximum number of tokens in the generated completion.\n temperature (float): The temperature parameter for randomness in the completion.\n base_model (BaseModel): The base model to be used for the completion.\n openai_api_key (str): The API key for accessing the OpenAI service.\n parallel_tool_calls (bool): Whether to make parallel tool calls.\n top_p (float): The top-p parameter for nucleus sampling in the completion.\n\n Attributes:\n system_prompt (str): The system prompt to be used in the chat completion.\n model_name (str): The name of the OpenAI model to be used.\n max_tokens (int): The maximum number of tokens in the generated completion.\n temperature (float): The temperature parameter for randomness in the completion.\n base_model (BaseModel): The base model to be used for the completion.\n parallel_tool_calls (bool): Whether to make parallel tool calls.\n top_p (float): The top-p parameter for nucleus sampling in the completion.\n client (openai.OpenAI): The OpenAI client for making API calls.\n\n Methods:\n check_api_key: Checks if the API key is provided and retrieves it from the environment if not.\n run: Runs the chat completion with the given task and returns the generated completion.\n\n " 7 | }, 8 | "template": null, 9 | "max_loops": 1, 10 | "stopping_condition": null, 11 | "loop_interval": 0, 12 | "retry_attempts": 1, 13 | "retry_interval": 1, 14 | "task": null, 15 | "stopping_token": "", 16 | "interactive": false, 17 | "dashboard": false, 18 | "return_history": false, 19 | "dynamic_temperature_enabled": true, 20 | "dynamic_loops": false, 21 | "user_name": "swarms_corp", 22 | "context_length": 200000, 23 | "sop": null, 24 | "sop_list": null, 25 | "tools": null, 26 | "system_prompt": "\nYou are an expert problem-solving agent designed to not only solve complex problems but also critically evaluate the quality of your thought process and final answers. \nYour task is to follow a structured approach to generate solutions, assess your thoughts, and provide a rating for each on a scale of 0.1 to 1.0. \nThis rating should reflect the accuracy and quality of your reasoning and final answer.\n\n### Instructions:\n\n1. **Understand the Problem:**\n - Carefully analyze the problem provided by the user.\n - Break down the problem into smaller, manageable parts if necessary.\n - Formulate a clear understanding of the problem before proceeding.\n\n2. **Generate Thoughts:**\n - Create multiple thoughts or steps toward solving the problem.\n - For each thought, document your reasoning, ensuring that it is logical and well-founded.\n\n3. **Self-Evaluation:**\n - After generating each thought, evaluate its accuracy and quality.\n - Assign an evaluation score between 0.1 and 1.0. Use the following guidelines:\n - **0.1 to 0.4:** The thought is flawed, inaccurate, or incomplete.\n - **0.5 to 0.7:** The thought is partially correct but may lack detail or full accuracy.\n - **0.8 to 1.0:** The thought is accurate, complete, and well-reasoned.\n\n4. **Generate Final Answer:**\n - Based on your thoughts, synthesize a final answer to the problem.\n - Ensure the final answer is comprehensive and addresses all aspects of the problem.\n\n5. **Final Evaluation:**\n - Evaluate the overall quality and accuracy of your final answer.\n - Provide a final evaluation score based on the same 0.1 to 1.0 scale.\n \n", 27 | "agent_name": "ToT-Agent-b7ac7224e93547f3833ebb97e9603359", 28 | "agent_description": null, 29 | "saved_state_path": "ToT-Agent-b7ac7224e93547f3833ebb97e9603359_state.json", 30 | "autosave": true, 31 | "response_filters": [], 32 | "self_healing_enabled": false, 33 | "code_interpreter": false, 34 | "multi_modal": null, 35 | "pdf_path": null, 36 | "list_of_pdf": null, 37 | "tokenizer": "", 38 | "long_term_memory": null, 39 | "preset_stopping_token": false, 40 | "traceback": null, 41 | "traceback_handlers": null, 42 | "streaming_on": false, 43 | "docs": null, 44 | "docs_folder": null, 45 | "verbose": true, 46 | "parser": null, 47 | "best_of_n": null, 48 | "callback": null, 49 | "metadata": null, 50 | "callbacks": null, 51 | "logger_handler": "", 52 | "search_algorithm": null, 53 | "logs_to_filename": null, 54 | "evaluator": null, 55 | "output_json": false, 56 | "stopping_func": null, 57 | "custom_loop_condition": null, 58 | "sentiment_threshold": null, 59 | "custom_exit_command": "exit", 60 | "sentiment_analyzer": null, 61 | "limit_tokens_from_string": null, 62 | "tool_schema": null, 63 | "output_type": null, 64 | "function_calling_type": "json", 65 | "output_cleaner": null, 66 | "function_calling_format_type": "OpenAI", 67 | "list_base_models": null, 68 | "metadata_output_type": "json", 69 | "state_save_file_type": "json", 70 | "chain_of_thoughts": false, 71 | "algorithm_of_thoughts": false, 72 | "tree_of_thoughts": false, 73 | "tool_choice": "auto", 74 | "execute_tool": false, 75 | "planning": false, 76 | "planning_prompt": null, 77 | "device": null, 78 | "custom_planning_prompt": null, 79 | "rules": null, 80 | "custom_tools_prompt": null, 81 | "memory_chunk_size": 2000, 82 | "agent_ops_on": false, 83 | "log_directory": null, 84 | "tool_system_prompt": "\n\n\n You've been granted tools to assist users by always providing outputs in JSON format for tool usage. \n Whenever a tool usage is required, you must output the JSON wrapped inside markdown for clarity. \n Provide a commentary on the tool usage and the user's request and ensure that the JSON output adheres to the tool's schema.\n \n Here are some rules:\n Do not ever use tools that do not have JSON schemas attached to them.\n Do not use tools that you have not been granted access to.\n Do not use tools that are not relevant to the task at hand.\n Do not use tools that are not relevant to the user's request.\n \n \n Here are the guidelines you must follow:\n\n 1. **Output Format**:\n - All outputs related to tool usage should be formatted as JSON.\n - The JSON should be encapsulated within triple backticks and tagged as a code block with 'json'.\n\n 2. **Schema Compliance**:\n - Ensure that the JSON output strictly follows the provided schema for each tool.\n - Each tool's schema will define the structure and required fields for the JSON output.\n\n 3. **Schema Example**:\n If a tool named `example_tool` with a schema requires `param1` and `param2`, your response should look like:\n ```json\n {\n \"type\": \"function\",\n \"function\": {\n \"name\": \"example_tool\",\n \"parameters\": {\n \"param1\": 123,\n \"param2\": \"example_value\"\n }\n }\n }\n ```\n\n 4. **Error Handling**:\n - If there is an error or the information provided by the user is insufficient to generate a valid JSON, respond with an appropriate error message in JSON format, also encapsulated in markdown.\n\n Remember, clarity and adherence to the schema are paramount. Your primary goal is to ensure the user receives well-structured JSON outputs that align with the tool's requirements.\n\n ---\n\n Here is the format you should always follow for your responses involving tool usage:\n\n ```json\n {\n \"type\": \"function\",\n \"function\": {\n \"name\": \"\",\n \"parameters\": {\n \"param1\": \"\",\n \"param2\": \"\"\n }\n }\n }\n ```\n\n Please proceed with your task accordingly.\n\n ", 85 | "max_tokens": 4096, 86 | "top_p": 0.9, 87 | "top_k": null, 88 | "frequency_penalty": 0.0, 89 | "presence_penalty": 0.0, 90 | "temperature": 0.1, 91 | "workspace_dir": "agent_workspace", 92 | "timeout": null, 93 | "created_at": 1724873387.89085, 94 | "return_step_meta": false, 95 | "tags": null, 96 | "use_cases": null, 97 | "name": "ToT-Agent-b7ac7224e93547f3833ebb97e9603359", 98 | "description": null, 99 | "reply": "", 100 | "question": null, 101 | "answer": "", 102 | "feedback": [], 103 | "short_memory": { 104 | "name": null, 105 | "description": null, 106 | "save_metadata_on": true, 107 | "save_artifact_path": "./artifacts", 108 | "save_metadata_path": "./metadata", 109 | "save_error_path": "./errors", 110 | "workspace_dir": "./workspace", 111 | "system_prompt": "\nYou are an expert problem-solving agent designed to not only solve complex problems but also critically evaluate the quality of your thought process and final answers. \nYour task is to follow a structured approach to generate solutions, assess your thoughts, and provide a rating for each on a scale of 0.1 to 1.0. \nThis rating should reflect the accuracy and quality of your reasoning and final answer.\n\n### Instructions:\n\n1. **Understand the Problem:**\n - Carefully analyze the problem provided by the user.\n - Break down the problem into smaller, manageable parts if necessary.\n - Formulate a clear understanding of the problem before proceeding.\n\n2. **Generate Thoughts:**\n - Create multiple thoughts or steps toward solving the problem.\n - For each thought, document your reasoning, ensuring that it is logical and well-founded.\n\n3. **Self-Evaluation:**\n - After generating each thought, evaluate its accuracy and quality.\n - Assign an evaluation score between 0.1 and 1.0. Use the following guidelines:\n - **0.1 to 0.4:** The thought is flawed, inaccurate, or incomplete.\n - **0.5 to 0.7:** The thought is partially correct but may lack detail or full accuracy.\n - **0.8 to 1.0:** The thought is accurate, complete, and well-reasoned.\n\n4. **Generate Final Answer:**\n - Based on your thoughts, synthesize a final answer to the problem.\n - Ensure the final answer is comprehensive and addresses all aspects of the problem.\n\n5. **Final Evaluation:**\n - Evaluate the overall quality and accuracy of your final answer.\n - Provide a final evaluation score based on the same 0.1 to 1.0 scale.\n \n", 112 | "time_enabled": true, 113 | "autosave": false, 114 | "save_filepath": null, 115 | "conversation_history": [ 116 | { 117 | "role": "System: ", 118 | "content": "\nYou are an expert problem-solving agent designed to not only solve complex problems but also critically evaluate the quality of your thought process and final answers. \nYour task is to follow a structured approach to generate solutions, assess your thoughts, and provide a rating for each on a scale of 0.1 to 1.0. \nThis rating should reflect the accuracy and quality of your reasoning and final answer.\n\n### Instructions:\n\n1. **Understand the Problem:**\n - Carefully analyze the problem provided by the user.\n - Break down the problem into smaller, manageable parts if necessary.\n - Formulate a clear understanding of the problem before proceeding.\n\n2. **Generate Thoughts:**\n - Create multiple thoughts or steps toward solving the problem.\n - For each thought, document your reasoning, ensuring that it is logical and well-founded.\n\n3. **Self-Evaluation:**\n - After generating each thought, evaluate its accuracy and quality.\n - Assign an evaluation score between 0.1 and 1.0. Use the following guidelines:\n - **0.1 to 0.4:** The thought is flawed, inaccurate, or incomplete.\n - **0.5 to 0.7:** The thought is partially correct but may lack detail or full accuracy.\n - **0.8 to 1.0:** The thought is accurate, complete, and well-reasoned.\n\n4. **Generate Final Answer:**\n - Based on your thoughts, synthesize a final answer to the problem.\n - Ensure the final answer is comprehensive and addresses all aspects of the problem.\n\n5. **Final Evaluation:**\n - Evaluate the overall quality and accuracy of your final answer.\n - Provide a final evaluation score based on the same 0.1 to 1.0 scale.\n \n", 119 | "timestamp": "2024-08-28 15:29:48" 120 | }, 121 | { 122 | "role": "swarms_corp", 123 | "content": "\n\nYour task: is to use 4 numbers and basic arithmetic operations (+-*/) to obtain 24 in 1 equation, return only the math\n\n", 124 | "timestamp": "2024-08-28 15:29:48" 125 | }, 126 | { 127 | "role": "swarms_corp", 128 | "content": "\n\nYour task: is to use 4 numbers and basic arithmetic operations (+-*/) to obtain 24 in 1 equation, return only the math\n\n", 129 | "timestamp": "2024-08-28 15:29:48" 130 | }, 131 | { 132 | "role": "swarms_corp", 133 | "content": "\n\nYour task: is to use 4 numbers and basic arithmetic operations (+-*/) to obtain 24 in 1 equation, return only the math\n\n", 134 | "timestamp": "2024-08-28 15:29:48" 135 | }, 136 | { 137 | "role": "swarms_corp", 138 | "content": "\n\nYour task: is to use 4 numbers and basic arithmetic operations (+-*/) to obtain 24 in 1 equation, return only the math\n\n", 139 | "timestamp": "2024-08-28 15:29:48" 140 | }, 141 | { 142 | "role": "ToT-Agent-b7ac7224e93547f3833ebb97e9603359", 143 | "content": "{'thought': \"I'll choose the numbers 3, 3, 8, and 1 for this problem. My goal is to find a way to combine these four numbers using basic arithmetic operations to achieve a result of 24.\", 'evaluation': 0.8}", 144 | "timestamp": "2024-08-28 15:29:51" 145 | }, 146 | { 147 | "role": "ToT-Agent-b7ac7224e93547f3833ebb97e9603359", 148 | "content": "{'thought': 'Using the numbers 8, 3, 3, and 1, a possible equation to obtain 24 is: (8 / (3 - (1 / 3))) = 24. This equation uses division and subtraction to manipulate the numbers to equal 24.', 'evaluation': 0.8}", 149 | "timestamp": "2024-08-28 15:29:51" 150 | } 151 | ], 152 | "tokenizer": null, 153 | "context_length": 8192, 154 | "rules": null, 155 | "custom_rules_prompt": null, 156 | "user": "swarms_corp", 157 | "auto_save": true, 158 | "save_as_yaml": true, 159 | "save_as_json_bool": false 160 | } 161 | } -------------------------------------------------------------------------------- /artifacts/ToT-Agent-bebb51a1cbe04b2e82cb151cfcb51769_state.json: -------------------------------------------------------------------------------- 1 | { 2 | "agent_id": "79ebc116f72543e4b41b579c16c364c3", 3 | "id": "ec9cfba300c94586a34d38eed872a243", 4 | "llm": { 5 | "name": "OpenAIFunctionCaller", 6 | "doc": "\n A class that represents a caller for OpenAI chat completions.\n\n Args:\n system_prompt (str): The system prompt to be used in the chat completion.\n model_name (str): The name of the OpenAI model to be used.\n max_tokens (int): The maximum number of tokens in the generated completion.\n temperature (float): The temperature parameter for randomness in the completion.\n base_model (BaseModel): The base model to be used for the completion.\n openai_api_key (str): The API key for accessing the OpenAI service.\n parallel_tool_calls (bool): Whether to make parallel tool calls.\n top_p (float): The top-p parameter for nucleus sampling in the completion.\n\n Attributes:\n system_prompt (str): The system prompt to be used in the chat completion.\n model_name (str): The name of the OpenAI model to be used.\n max_tokens (int): The maximum number of tokens in the generated completion.\n temperature (float): The temperature parameter for randomness in the completion.\n base_model (BaseModel): The base model to be used for the completion.\n parallel_tool_calls (bool): Whether to make parallel tool calls.\n top_p (float): The top-p parameter for nucleus sampling in the completion.\n client (openai.OpenAI): The OpenAI client for making API calls.\n\n Methods:\n check_api_key: Checks if the API key is provided and retrieves it from the environment if not.\n run: Runs the chat completion with the given task and returns the generated completion.\n\n " 7 | }, 8 | "template": null, 9 | "max_loops": 1, 10 | "stopping_condition": null, 11 | "loop_interval": 0, 12 | "retry_attempts": 1, 13 | "retry_interval": 1, 14 | "task": null, 15 | "stopping_token": "", 16 | "interactive": false, 17 | "dashboard": false, 18 | "return_history": false, 19 | "dynamic_temperature_enabled": true, 20 | "dynamic_loops": false, 21 | "user_name": "swarms_corp", 22 | "context_length": 200000, 23 | "sop": null, 24 | "sop_list": null, 25 | "tools": null, 26 | "system_prompt": "\nYou are an expert problem-solving agent designed to not only solve complex problems but also critically evaluate the quality of your thought process and final answers. \nYour task is to follow a structured approach to generate solutions, assess your thoughts, and provide a rating for each on a scale of 0.1 to 1.0. \nThis rating should reflect the accuracy and quality of your reasoning and final answer.\n\n### Instructions:\n\n1. **Understand the Problem:**\n - Carefully analyze the problem provided by the user.\n - Break down the problem into smaller, manageable parts if necessary.\n - Formulate a clear understanding of the problem before proceeding.\n\n2. **Generate Thoughts:**\n - Create multiple thoughts or steps toward solving the problem.\n - For each thought, document your reasoning, ensuring that it is logical and well-founded.\n\n3. **Self-Evaluation:**\n - After generating each thought, evaluate its accuracy and quality.\n - Assign an evaluation score between 0.1 and 1.0. Use the following guidelines:\n - **0.1 to 0.4:** The thought is flawed, inaccurate, or incomplete.\n - **0.5 to 0.7:** The thought is partially correct but may lack detail or full accuracy.\n - **0.8 to 1.0:** The thought is accurate, complete, and well-reasoned.\n\n4. **Generate Final Answer:**\n - Based on your thoughts, synthesize a final answer to the problem.\n - Ensure the final answer is comprehensive and addresses all aspects of the problem.\n\n5. **Final Evaluation:**\n - Evaluate the overall quality and accuracy of your final answer.\n - Provide a final evaluation score based on the same 0.1 to 1.0 scale.\n \n", 27 | "agent_name": "ToT-Agent-bebb51a1cbe04b2e82cb151cfcb51769", 28 | "agent_description": null, 29 | "saved_state_path": "ToT-Agent-bebb51a1cbe04b2e82cb151cfcb51769_state.json", 30 | "autosave": true, 31 | "response_filters": [], 32 | "self_healing_enabled": false, 33 | "code_interpreter": false, 34 | "multi_modal": null, 35 | "pdf_path": null, 36 | "list_of_pdf": null, 37 | "tokenizer": "", 38 | "long_term_memory": null, 39 | "preset_stopping_token": false, 40 | "traceback": null, 41 | "traceback_handlers": null, 42 | "streaming_on": false, 43 | "docs": null, 44 | "docs_folder": null, 45 | "verbose": true, 46 | "parser": null, 47 | "best_of_n": null, 48 | "callback": null, 49 | "metadata": null, 50 | "callbacks": null, 51 | "logger_handler": "", 52 | "search_algorithm": null, 53 | "logs_to_filename": null, 54 | "evaluator": null, 55 | "output_json": false, 56 | "stopping_func": null, 57 | "custom_loop_condition": null, 58 | "sentiment_threshold": null, 59 | "custom_exit_command": "exit", 60 | "sentiment_analyzer": null, 61 | "limit_tokens_from_string": null, 62 | "tool_schema": null, 63 | "output_type": null, 64 | "function_calling_type": "json", 65 | "output_cleaner": null, 66 | "function_calling_format_type": "OpenAI", 67 | "list_base_models": null, 68 | "metadata_output_type": "json", 69 | "state_save_file_type": "json", 70 | "chain_of_thoughts": false, 71 | "algorithm_of_thoughts": false, 72 | "tree_of_thoughts": false, 73 | "tool_choice": "auto", 74 | "execute_tool": false, 75 | "planning": false, 76 | "planning_prompt": null, 77 | "device": null, 78 | "custom_planning_prompt": null, 79 | "rules": null, 80 | "custom_tools_prompt": null, 81 | "memory_chunk_size": 2000, 82 | "agent_ops_on": false, 83 | "log_directory": null, 84 | "tool_system_prompt": "\n\n\n You've been granted tools to assist users by always providing outputs in JSON format for tool usage. \n Whenever a tool usage is required, you must output the JSON wrapped inside markdown for clarity. \n Provide a commentary on the tool usage and the user's request and ensure that the JSON output adheres to the tool's schema.\n \n Here are some rules:\n Do not ever use tools that do not have JSON schemas attached to them.\n Do not use tools that you have not been granted access to.\n Do not use tools that are not relevant to the task at hand.\n Do not use tools that are not relevant to the user's request.\n \n \n Here are the guidelines you must follow:\n\n 1. **Output Format**:\n - All outputs related to tool usage should be formatted as JSON.\n - The JSON should be encapsulated within triple backticks and tagged as a code block with 'json'.\n\n 2. **Schema Compliance**:\n - Ensure that the JSON output strictly follows the provided schema for each tool.\n - Each tool's schema will define the structure and required fields for the JSON output.\n\n 3. **Schema Example**:\n If a tool named `example_tool` with a schema requires `param1` and `param2`, your response should look like:\n ```json\n {\n \"type\": \"function\",\n \"function\": {\n \"name\": \"example_tool\",\n \"parameters\": {\n \"param1\": 123,\n \"param2\": \"example_value\"\n }\n }\n }\n ```\n\n 4. **Error Handling**:\n - If there is an error or the information provided by the user is insufficient to generate a valid JSON, respond with an appropriate error message in JSON format, also encapsulated in markdown.\n\n Remember, clarity and adherence to the schema are paramount. Your primary goal is to ensure the user receives well-structured JSON outputs that align with the tool's requirements.\n\n ---\n\n Here is the format you should always follow for your responses involving tool usage:\n\n ```json\n {\n \"type\": \"function\",\n \"function\": {\n \"name\": \"\",\n \"parameters\": {\n \"param1\": \"\",\n \"param2\": \"\"\n }\n }\n }\n ```\n\n Please proceed with your task accordingly.\n\n ", 85 | "max_tokens": 4000, 86 | "top_p": 0.9, 87 | "top_k": null, 88 | "frequency_penalty": 0.0, 89 | "presence_penalty": 0.0, 90 | "temperature": 0.1, 91 | "workspace_dir": "agent_workspace", 92 | "timeout": null, 93 | "created_at": 1724870485.6231492, 94 | "return_step_meta": false, 95 | "tags": null, 96 | "use_cases": null, 97 | "name": "ToT-Agent-bebb51a1cbe04b2e82cb151cfcb51769", 98 | "description": null, 99 | "reply": "", 100 | "question": null, 101 | "answer": "", 102 | "feedback": [], 103 | "short_memory": { 104 | "name": null, 105 | "description": null, 106 | "save_metadata_on": true, 107 | "save_artifact_path": "./artifacts", 108 | "save_metadata_path": "./metadata", 109 | "save_error_path": "./errors", 110 | "workspace_dir": "./workspace", 111 | "system_prompt": "\nYou are an expert problem-solving agent designed to not only solve complex problems but also critically evaluate the quality of your thought process and final answers. \nYour task is to follow a structured approach to generate solutions, assess your thoughts, and provide a rating for each on a scale of 0.1 to 1.0. \nThis rating should reflect the accuracy and quality of your reasoning and final answer.\n\n### Instructions:\n\n1. **Understand the Problem:**\n - Carefully analyze the problem provided by the user.\n - Break down the problem into smaller, manageable parts if necessary.\n - Formulate a clear understanding of the problem before proceeding.\n\n2. **Generate Thoughts:**\n - Create multiple thoughts or steps toward solving the problem.\n - For each thought, document your reasoning, ensuring that it is logical and well-founded.\n\n3. **Self-Evaluation:**\n - After generating each thought, evaluate its accuracy and quality.\n - Assign an evaluation score between 0.1 and 1.0. Use the following guidelines:\n - **0.1 to 0.4:** The thought is flawed, inaccurate, or incomplete.\n - **0.5 to 0.7:** The thought is partially correct but may lack detail or full accuracy.\n - **0.8 to 1.0:** The thought is accurate, complete, and well-reasoned.\n\n4. **Generate Final Answer:**\n - Based on your thoughts, synthesize a final answer to the problem.\n - Ensure the final answer is comprehensive and addresses all aspects of the problem.\n\n5. **Final Evaluation:**\n - Evaluate the overall quality and accuracy of your final answer.\n - Provide a final evaluation score based on the same 0.1 to 1.0 scale.\n \n", 112 | "time_enabled": true, 113 | "autosave": false, 114 | "save_filepath": null, 115 | "conversation_history": [ 116 | { 117 | "role": "System: ", 118 | "content": "\nYou are an expert problem-solving agent designed to not only solve complex problems but also critically evaluate the quality of your thought process and final answers. \nYour task is to follow a structured approach to generate solutions, assess your thoughts, and provide a rating for each on a scale of 0.1 to 1.0. \nThis rating should reflect the accuracy and quality of your reasoning and final answer.\n\n### Instructions:\n\n1. **Understand the Problem:**\n - Carefully analyze the problem provided by the user.\n - Break down the problem into smaller, manageable parts if necessary.\n - Formulate a clear understanding of the problem before proceeding.\n\n2. **Generate Thoughts:**\n - Create multiple thoughts or steps toward solving the problem.\n - For each thought, document your reasoning, ensuring that it is logical and well-founded.\n\n3. **Self-Evaluation:**\n - After generating each thought, evaluate its accuracy and quality.\n - Assign an evaluation score between 0.1 and 1.0. Use the following guidelines:\n - **0.1 to 0.4:** The thought is flawed, inaccurate, or incomplete.\n - **0.5 to 0.7:** The thought is partially correct but may lack detail or full accuracy.\n - **0.8 to 1.0:** The thought is accurate, complete, and well-reasoned.\n\n4. **Generate Final Answer:**\n - Based on your thoughts, synthesize a final answer to the problem.\n - Ensure the final answer is comprehensive and addresses all aspects of the problem.\n\n5. **Final Evaluation:**\n - Evaluate the overall quality and accuracy of your final answer.\n - Provide a final evaluation score based on the same 0.1 to 1.0 scale.\n \n", 119 | "timestamp": "2024-08-28 14:41:25" 120 | }, 121 | { 122 | "role": "swarms_corp", 123 | "content": "\n\nYour task: is to use 4 numbers and basic arithmetic operations (+-*/) to obtain 24 in 1 equation\nPossible next steps:\n\n", 124 | "timestamp": "2024-08-28 14:41:25" 125 | }, 126 | { 127 | "role": "swarms_corp", 128 | "content": "\n\nYour task: is to use 4 numbers and basic arithmetic operations (+-*/) to obtain 24 in 1 equation\nPossible next steps:\n\n", 129 | "timestamp": "2024-08-28 14:41:25" 130 | }, 131 | { 132 | "role": "ToT-Agent-bebb51a1cbe04b2e82cb151cfcb51769", 133 | "content": "{'thought': \"First, identify the four numbers provided. Let's assume the numbers are 8, 3, 3, and 1. The goal is to use these numbers with basic arithmetic operations (addition, subtraction, multiplication, division) to achieve a result of 24.\", 'evaluation': 0.9}", 134 | "timestamp": "2024-08-28 14:41:27" 135 | }, 136 | { 137 | "role": "ToT-Agent-bebb51a1cbe04b2e82cb151cfcb51769", 138 | "content": "None", 139 | "timestamp": "2024-08-28 14:41:27" 140 | } 141 | ], 142 | "tokenizer": null, 143 | "context_length": 8192, 144 | "rules": null, 145 | "custom_rules_prompt": null, 146 | "user": "swarms_corp", 147 | "auto_save": true, 148 | "save_as_yaml": true, 149 | "save_as_json_bool": false 150 | } 151 | } -------------------------------------------------------------------------------- /artifacts/ToT-Agent-db3dd5b17cd74b00b2331fe8277325df_state.json: -------------------------------------------------------------------------------- 1 | { 2 | "agent_id": "b3547ada54b64b218c7e7bdf072dbca5", 3 | "id": "c85c7d19876741998814098e5f692326", 4 | "llm": { 5 | "name": "OpenAIFunctionCaller", 6 | "doc": "\n A class that represents a caller for OpenAI chat completions.\n\n Args:\n system_prompt (str): The system prompt to be used in the chat completion.\n model_name (str): The name of the OpenAI model to be used.\n max_tokens (int): The maximum number of tokens in the generated completion.\n temperature (float): The temperature parameter for randomness in the completion.\n base_model (BaseModel): The base model to be used for the completion.\n openai_api_key (str): The API key for accessing the OpenAI service.\n parallel_tool_calls (bool): Whether to make parallel tool calls.\n top_p (float): The top-p parameter for nucleus sampling in the completion.\n\n Attributes:\n system_prompt (str): The system prompt to be used in the chat completion.\n model_name (str): The name of the OpenAI model to be used.\n max_tokens (int): The maximum number of tokens in the generated completion.\n temperature (float): The temperature parameter for randomness in the completion.\n base_model (BaseModel): The base model to be used for the completion.\n parallel_tool_calls (bool): Whether to make parallel tool calls.\n top_p (float): The top-p parameter for nucleus sampling in the completion.\n client (openai.OpenAI): The OpenAI client for making API calls.\n\n Methods:\n check_api_key: Checks if the API key is provided and retrieves it from the environment if not.\n run: Runs the chat completion with the given task and returns the generated completion.\n\n " 7 | }, 8 | "template": null, 9 | "max_loops": 1, 10 | "stopping_condition": null, 11 | "loop_interval": 0, 12 | "retry_attempts": 1, 13 | "retry_interval": 1, 14 | "task": null, 15 | "stopping_token": "", 16 | "interactive": false, 17 | "dashboard": false, 18 | "return_history": false, 19 | "dynamic_temperature_enabled": true, 20 | "dynamic_loops": false, 21 | "user_name": "swarms_corp", 22 | "context_length": 200000, 23 | "sop": null, 24 | "sop_list": null, 25 | "tools": null, 26 | "system_prompt": "\nYou are an expert problem-solving agent designed to not only solve complex problems but also critically evaluate the quality of your thought process and final answers. \nYour task is to follow a structured approach to generate solutions, assess your thoughts, and provide a rating for each on a scale of 0.1 to 1.0. \nThis rating should reflect the accuracy and quality of your reasoning and final answer.\n\n### Instructions:\n\n1. **Understand the Problem:**\n - Carefully analyze the problem provided by the user.\n - Break down the problem into smaller, manageable parts if necessary.\n - Formulate a clear understanding of the problem before proceeding.\n\n2. **Generate Thoughts:**\n - Create multiple thoughts or steps toward solving the problem.\n - For each thought, document your reasoning, ensuring that it is logical and well-founded.\n\n3. **Self-Evaluation:**\n - After generating each thought, evaluate its accuracy and quality.\n - Assign an evaluation score between 0.1 and 1.0. Use the following guidelines:\n - **0.1 to 0.4:** The thought is flawed, inaccurate, or incomplete.\n - **0.5 to 0.7:** The thought is partially correct but may lack detail or full accuracy.\n - **0.8 to 1.0:** The thought is accurate, complete, and well-reasoned.\n\n4. **Generate Final Answer:**\n - Based on your thoughts, synthesize a final answer to the problem.\n - Ensure the final answer is comprehensive and addresses all aspects of the problem.\n\n5. **Final Evaluation:**\n - Evaluate the overall quality and accuracy of your final answer.\n - Provide a final evaluation score based on the same 0.1 to 1.0 scale.\n \n", 27 | "agent_name": "ToT-Agent-db3dd5b17cd74b00b2331fe8277325df", 28 | "agent_description": null, 29 | "saved_state_path": "ToT-Agent-db3dd5b17cd74b00b2331fe8277325df_state.json", 30 | "autosave": true, 31 | "response_filters": [], 32 | "self_healing_enabled": false, 33 | "code_interpreter": false, 34 | "multi_modal": null, 35 | "pdf_path": null, 36 | "list_of_pdf": null, 37 | "tokenizer": "", 38 | "long_term_memory": null, 39 | "preset_stopping_token": false, 40 | "traceback": null, 41 | "traceback_handlers": null, 42 | "streaming_on": false, 43 | "docs": null, 44 | "docs_folder": null, 45 | "verbose": true, 46 | "parser": null, 47 | "best_of_n": null, 48 | "callback": null, 49 | "metadata": null, 50 | "callbacks": null, 51 | "logger_handler": "", 52 | "search_algorithm": null, 53 | "logs_to_filename": null, 54 | "evaluator": null, 55 | "output_json": false, 56 | "stopping_func": null, 57 | "custom_loop_condition": null, 58 | "sentiment_threshold": null, 59 | "custom_exit_command": "exit", 60 | "sentiment_analyzer": null, 61 | "limit_tokens_from_string": null, 62 | "tool_schema": null, 63 | "output_type": null, 64 | "function_calling_type": "json", 65 | "output_cleaner": null, 66 | "function_calling_format_type": "OpenAI", 67 | "list_base_models": null, 68 | "metadata_output_type": "json", 69 | "state_save_file_type": "json", 70 | "chain_of_thoughts": false, 71 | "algorithm_of_thoughts": false, 72 | "tree_of_thoughts": false, 73 | "tool_choice": "auto", 74 | "execute_tool": false, 75 | "planning": false, 76 | "planning_prompt": null, 77 | "device": null, 78 | "custom_planning_prompt": null, 79 | "rules": null, 80 | "custom_tools_prompt": null, 81 | "memory_chunk_size": 2000, 82 | "agent_ops_on": false, 83 | "log_directory": null, 84 | "tool_system_prompt": "\n\n\n You've been granted tools to assist users by always providing outputs in JSON format for tool usage. \n Whenever a tool usage is required, you must output the JSON wrapped inside markdown for clarity. \n Provide a commentary on the tool usage and the user's request and ensure that the JSON output adheres to the tool's schema.\n \n Here are some rules:\n Do not ever use tools that do not have JSON schemas attached to them.\n Do not use tools that you have not been granted access to.\n Do not use tools that are not relevant to the task at hand.\n Do not use tools that are not relevant to the user's request.\n \n \n Here are the guidelines you must follow:\n\n 1. **Output Format**:\n - All outputs related to tool usage should be formatted as JSON.\n - The JSON should be encapsulated within triple backticks and tagged as a code block with 'json'.\n\n 2. **Schema Compliance**:\n - Ensure that the JSON output strictly follows the provided schema for each tool.\n - Each tool's schema will define the structure and required fields for the JSON output.\n\n 3. **Schema Example**:\n If a tool named `example_tool` with a schema requires `param1` and `param2`, your response should look like:\n ```json\n {\n \"type\": \"function\",\n \"function\": {\n \"name\": \"example_tool\",\n \"parameters\": {\n \"param1\": 123,\n \"param2\": \"example_value\"\n }\n }\n }\n ```\n\n 4. **Error Handling**:\n - If there is an error or the information provided by the user is insufficient to generate a valid JSON, respond with an appropriate error message in JSON format, also encapsulated in markdown.\n\n Remember, clarity and adherence to the schema are paramount. Your primary goal is to ensure the user receives well-structured JSON outputs that align with the tool's requirements.\n\n ---\n\n Here is the format you should always follow for your responses involving tool usage:\n\n ```json\n {\n \"type\": \"function\",\n \"function\": {\n \"name\": \"\",\n \"parameters\": {\n \"param1\": \"\",\n \"param2\": \"\"\n }\n }\n }\n ```\n\n Please proceed with your task accordingly.\n\n ", 85 | "max_tokens": 4000, 86 | "top_p": 0.9, 87 | "top_k": null, 88 | "frequency_penalty": 0.0, 89 | "presence_penalty": 0.0, 90 | "temperature": 0.1, 91 | "workspace_dir": "agent_workspace", 92 | "timeout": null, 93 | "created_at": 1724870467.069421, 94 | "return_step_meta": false, 95 | "tags": null, 96 | "use_cases": null, 97 | "name": "ToT-Agent-db3dd5b17cd74b00b2331fe8277325df", 98 | "description": null, 99 | "reply": "", 100 | "question": null, 101 | "answer": "", 102 | "feedback": [], 103 | "short_memory": { 104 | "name": null, 105 | "description": null, 106 | "save_metadata_on": true, 107 | "save_artifact_path": "./artifacts", 108 | "save_metadata_path": "./metadata", 109 | "save_error_path": "./errors", 110 | "workspace_dir": "./workspace", 111 | "system_prompt": "\nYou are an expert problem-solving agent designed to not only solve complex problems but also critically evaluate the quality of your thought process and final answers. \nYour task is to follow a structured approach to generate solutions, assess your thoughts, and provide a rating for each on a scale of 0.1 to 1.0. \nThis rating should reflect the accuracy and quality of your reasoning and final answer.\n\n### Instructions:\n\n1. **Understand the Problem:**\n - Carefully analyze the problem provided by the user.\n - Break down the problem into smaller, manageable parts if necessary.\n - Formulate a clear understanding of the problem before proceeding.\n\n2. **Generate Thoughts:**\n - Create multiple thoughts or steps toward solving the problem.\n - For each thought, document your reasoning, ensuring that it is logical and well-founded.\n\n3. **Self-Evaluation:**\n - After generating each thought, evaluate its accuracy and quality.\n - Assign an evaluation score between 0.1 and 1.0. Use the following guidelines:\n - **0.1 to 0.4:** The thought is flawed, inaccurate, or incomplete.\n - **0.5 to 0.7:** The thought is partially correct but may lack detail or full accuracy.\n - **0.8 to 1.0:** The thought is accurate, complete, and well-reasoned.\n\n4. **Generate Final Answer:**\n - Based on your thoughts, synthesize a final answer to the problem.\n - Ensure the final answer is comprehensive and addresses all aspects of the problem.\n\n5. **Final Evaluation:**\n - Evaluate the overall quality and accuracy of your final answer.\n - Provide a final evaluation score based on the same 0.1 to 1.0 scale.\n \n", 112 | "time_enabled": true, 113 | "autosave": false, 114 | "save_filepath": null, 115 | "conversation_history": [ 116 | { 117 | "role": "System: ", 118 | "content": "\nYou are an expert problem-solving agent designed to not only solve complex problems but also critically evaluate the quality of your thought process and final answers. \nYour task is to follow a structured approach to generate solutions, assess your thoughts, and provide a rating for each on a scale of 0.1 to 1.0. \nThis rating should reflect the accuracy and quality of your reasoning and final answer.\n\n### Instructions:\n\n1. **Understand the Problem:**\n - Carefully analyze the problem provided by the user.\n - Break down the problem into smaller, manageable parts if necessary.\n - Formulate a clear understanding of the problem before proceeding.\n\n2. **Generate Thoughts:**\n - Create multiple thoughts or steps toward solving the problem.\n - For each thought, document your reasoning, ensuring that it is logical and well-founded.\n\n3. **Self-Evaluation:**\n - After generating each thought, evaluate its accuracy and quality.\n - Assign an evaluation score between 0.1 and 1.0. Use the following guidelines:\n - **0.1 to 0.4:** The thought is flawed, inaccurate, or incomplete.\n - **0.5 to 0.7:** The thought is partially correct but may lack detail or full accuracy.\n - **0.8 to 1.0:** The thought is accurate, complete, and well-reasoned.\n\n4. **Generate Final Answer:**\n - Based on your thoughts, synthesize a final answer to the problem.\n - Ensure the final answer is comprehensive and addresses all aspects of the problem.\n\n5. **Final Evaluation:**\n - Evaluate the overall quality and accuracy of your final answer.\n - Provide a final evaluation score based on the same 0.1 to 1.0 scale.\n \n", 119 | "timestamp": "2024-08-28 14:41:07" 120 | }, 121 | { 122 | "role": "swarms_corp", 123 | "content": "\n\nYour task: is to use 4 numbers and basic arithmetic operations (+-*/) to obtain 24 in 1 equation\nPossible next steps:\n\n", 124 | "timestamp": "2024-08-28 14:41:07" 125 | }, 126 | { 127 | "role": "swarms_corp", 128 | "content": "\n\nYour task: is to use 4 numbers and basic arithmetic operations (+-*/) to obtain 24 in 1 equation\nPossible next steps:\n\n", 129 | "timestamp": "2024-08-28 14:41:07" 130 | }, 131 | { 132 | "role": "ToT-Agent-db3dd5b17cd74b00b2331fe8277325df", 133 | "content": "None", 134 | "timestamp": "2024-08-28 14:41:09" 135 | }, 136 | { 137 | "role": "ToT-Agent-db3dd5b17cd74b00b2331fe8277325df", 138 | "content": "{'thought': 'Assuming the numbers are 1, 3, 4, and 6, I will explore different combinations of these numbers using basic arithmetic operations to reach 24. One possible approach is to try multiplication first, as it can quickly increase the value of the numbers. For example, multiplying 6 and 4 gives 24 directly, but we need to use all four numbers. Therefore, I will try different combinations and operations to see if I can achieve 24 while using all four numbers.', 'evaluation': 0.8}", 139 | "timestamp": "2024-08-28 14:41:11" 140 | } 141 | ], 142 | "tokenizer": null, 143 | "context_length": 8192, 144 | "rules": null, 145 | "custom_rules_prompt": null, 146 | "user": "swarms_corp", 147 | "auto_save": true, 148 | "save_as_yaml": true, 149 | "save_as_json_bool": false 150 | } 151 | } -------------------------------------------------------------------------------- /artifacts/error.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kyegomez/tree-of-thoughts/e919b61a08783301273e036f480864f1913624a9/artifacts/error.txt -------------------------------------------------------------------------------- /artifacts/thought_tree_797856a37471412dbe97b056cbfff541.dot: -------------------------------------------------------------------------------- 1 | digraph tree { 2 | "Root"; 3 | "Thought: A viable strategy is to construct a number that can be easily manipulated to reach 24. We have the numbers 2, 8, 8, and 14 to consider. One potential path is to involve the operation that every number could contribute meaningfully. For instance: 4 | 1. Compute (14 - 8) to get 6. 5 | 2. Use 2 to manipulate it: 6 * 2 = 12. 6 | 3. Use the next 8, suppose in division: it can serve as a reduction factor or reconsider a combination in step. Let's attempt ( 8 / 4 + 2) * 3 to comprehend errors or re-evaluate this attempt start. 7 | 8 | I'll need to reassess through: 9 | - (14 - 8) resulting in - direct shift towards a manipulative boundary: re-evaluate operation mapping to encompass direct operand choices. 10 | 11 | To conclude in reevaluation, it appears reaching the value might force reconsiderations on valid operand synthesis and original combination recalcium. Final adjustment awaits prior calculation confirmation. | Eval: 0.5"; 12 | "Thought: Given the numbers 2, 8, 8, and 14, let's explore a combination where we can reach 24. One potential path is to use multiplication and addition in a strategic way: 13 | 14 | 1. Consider multiplying the two 8s together: 8 * 8 = 64. 15 | 2. Now, let's see if we can use division or subtraction to adjust this result closer to 24. 16 | 3. If we divide 64 by 2, we get 32, which is still too high. 17 | 4. Let's try subtraction: if we subtract 14 from 64, we get 50, which is still above 24. 18 | 5. Instead, let's try 14 - 8 = 6. 19 | 6. Multiply 6 by 2 to get 12. 20 | 7. Now, we can multiply 12 by 2 (from the division of 8 by 4) to reach 24. 21 | 22 | This reasoning needs verification, as it might not use all numbers appropriately, and the operations might not align perfectly yet. Let's re-evaluate and adjust if necessary. | Eval: 0.7"; 23 | "Thought: To solve the problem, we need to use the numbers 2, 8, 8, and 14 with basic arithmetic operations to obtain the result of 24 in one equation. We must consider all possible combinations of operations and order of operations to achieve this result. We can start by exploring combinations that involve multiplication and division, as they tend to reach higher values quickly, which might be necessary to reach 24. Additionally, since the number 24 is even and can be factored into 2 * 12 or 3 * 8, we should consider these factors in our operations. | Eval: 0.8"; 24 | "Root" -> "Thought: A viable strategy is to construct a number that can be easily manipulated to reach 24. We have the numbers 2, 8, 8, and 14 to consider. One potential path is to involve the operation that every number could contribute meaningfully. For instance: 25 | 1. Compute (14 - 8) to get 6. 26 | 2. Use 2 to manipulate it: 6 * 2 = 12. 27 | 3. Use the next 8, suppose in division: it can serve as a reduction factor or reconsider a combination in step. Let's attempt ( 8 / 4 + 2) * 3 to comprehend errors or re-evaluate this attempt start. 28 | 29 | I'll need to reassess through: 30 | - (14 - 8) resulting in - direct shift towards a manipulative boundary: re-evaluate operation mapping to encompass direct operand choices. 31 | 32 | To conclude in reevaluation, it appears reaching the value might force reconsiderations on valid operand synthesis and original combination recalcium. Final adjustment awaits prior calculation confirmation. | Eval: 0.5"; 33 | "Thought: A viable strategy is to construct a number that can be easily manipulated to reach 24. We have the numbers 2, 8, 8, and 14 to consider. One potential path is to involve the operation that every number could contribute meaningfully. For instance: 34 | 1. Compute (14 - 8) to get 6. 35 | 2. Use 2 to manipulate it: 6 * 2 = 12. 36 | 3. Use the next 8, suppose in division: it can serve as a reduction factor or reconsider a combination in step. Let's attempt ( 8 / 4 + 2) * 3 to comprehend errors or re-evaluate this attempt start. 37 | 38 | I'll need to reassess through: 39 | - (14 - 8) resulting in - direct shift towards a manipulative boundary: re-evaluate operation mapping to encompass direct operand choices. 40 | 41 | To conclude in reevaluation, it appears reaching the value might force reconsiderations on valid operand synthesis and original combination recalcium. Final adjustment awaits prior calculation confirmation. | Eval: 0.5" -> "Thought: Given the numbers 2, 8, 8, and 14, let's explore a combination where we can reach 24. One potential path is to use multiplication and addition in a strategic way: 42 | 43 | 1. Consider multiplying the two 8s together: 8 * 8 = 64. 44 | 2. Now, let's see if we can use division or subtraction to adjust this result closer to 24. 45 | 3. If we divide 64 by 2, we get 32, which is still too high. 46 | 4. Let's try subtraction: if we subtract 14 from 64, we get 50, which is still above 24. 47 | 5. Instead, let's try 14 - 8 = 6. 48 | 6. Multiply 6 by 2 to get 12. 49 | 7. Now, we can multiply 12 by 2 (from the division of 8 by 4) to reach 24. 50 | 51 | This reasoning needs verification, as it might not use all numbers appropriately, and the operations might not align perfectly yet. Let's re-evaluate and adjust if necessary. | Eval: 0.7"; 52 | "Thought: Given the numbers 2, 8, 8, and 14, let's explore a combination where we can reach 24. One potential path is to use multiplication and addition in a strategic way: 53 | 54 | 1. Consider multiplying the two 8s together: 8 * 8 = 64. 55 | 2. Now, let's see if we can use division or subtraction to adjust this result closer to 24. 56 | 3. If we divide 64 by 2, we get 32, which is still too high. 57 | 4. Let's try subtraction: if we subtract 14 from 64, we get 50, which is still above 24. 58 | 5. Instead, let's try 14 - 8 = 6. 59 | 6. Multiply 6 by 2 to get 12. 60 | 7. Now, we can multiply 12 by 2 (from the division of 8 by 4) to reach 24. 61 | 62 | This reasoning needs verification, as it might not use all numbers appropriately, and the operations might not align perfectly yet. Let's re-evaluate and adjust if necessary. | Eval: 0.7" -> "Thought: To solve the problem, we need to use the numbers 2, 8, 8, and 14 with basic arithmetic operations to obtain the result of 24 in one equation. We must consider all possible combinations of operations and order of operations to achieve this result. We can start by exploring combinations that involve multiplication and division, as they tend to reach higher values quickly, which might be necessary to reach 24. Additionally, since the number 24 is even and can be factored into 2 * 12 or 3 * 8, we should consider these factors in our operations. | Eval: 0.8"; 63 | } 64 | -------------------------------------------------------------------------------- /artifacts/tree_of_thoughts_bfs_runs/tree_of_thoughts_bfs_run_0a96c2d618cb4a16b4816897b98369dd.json: -------------------------------------------------------------------------------- 1 | { 2 | "thought": "Let's try another approach by considering different combinations of operations:\n\n- **Combination 4:**\n - (14 - 8) * (8 - 2) = 6 * 6 = 36 (not 24)\n\n- **Combination 5:**\n - (14 - 2) + (8 / 8) = 12 + 1 = 13 (not 24)\n\n- **Combination 6:**\n - (8 * 2) - (14 - 8) = 16 - 6 = 10 (not 24)\n\nThese combinations also do not yield 24. I need to explore further combinations or rethink the strategy to find a solution that equals 24.", 3 | "evaluation": 0.6 4 | } -------------------------------------------------------------------------------- /artifacts/tree_of_thoughts_bfs_runs/tree_of_thoughts_bfs_run_6a217a607574432b97dc80b75d68b6d8.json: -------------------------------------------------------------------------------- 1 | { 2 | "thought": "The problem requires using the numbers 2, 8, 8, and 14 with basic arithmetic operations (+, -, *, /) to create an equation that equals 24. The challenge is to combine these numbers and operations in such a way that the final result is 24. This involves exploring various combinations and operations to find a valid equation. Given the possible next steps provided, I will evaluate which combination might lead to the desired result of 24.", 3 | "evaluation": 0.9 4 | } -------------------------------------------------------------------------------- /artifacts/tree_of_thoughts_bfs_runs/tree_of_thoughts_bfs_run_adc92d6e67b645a59a653b854896e74d.json: -------------------------------------------------------------------------------- 1 | { 2 | "all_thoughts": [ 3 | { 4 | "thought": "Firstly, I need to consider the given numbers: 2, 8, 8, and 14. The problem asks to use these numbers with basic arithmetic operations (+, -, *, /) to create a single equation that results in 24. Since this is a common type of mathematical puzzle, we can utilize operations and order of precedence to experiment with different combinations.\n\nNow, let's break down the problem. There are multiple arithmetic operations to choose from, which means there are several combinations possible. We want to use all four numbers exactly once and legal mathematical operations efficiently.\n\nA common strategy in this type of problem is exploring the multiplication and division first, as they create larger changes in numbers compared to addition and subtraction. The immediate operations I could consider:\n\n- 2 * 8 = 16: Starting with multiplication because it reduces the number of operands quickly.\n- 8 / 2 = 4: Using division to change number magnitude significantly.\n- 14 - 8 = 6 or 14 - 2 = 12: Utilizing subtraction to get to smaller numbers possibly easier to combine later.\n\nNext steps will involve testing different combinations of these operations to see which path can lead to the target number 24 robustly.", 5 | "evaluation": 0.8 6 | }, 7 | { 8 | "thought": "To solve this problem, we need to use the numbers 2, 8, 8, and 14 with basic arithmetic operations (+, -, *, /) to form an equation that equals 24. We can only use each number once, and we must use all four numbers in one equation. The challenge is to find a combination of operations that will result in 24.", 9 | "evaluation": 0.9 10 | } 11 | ], 12 | "final_thought": { 13 | "thought": "To solve the problem, we need to use the numbers 2, 8, 8, and 14 with basic arithmetic operations (+, -, *, /) to form an equation that equals 24. We can only use each number once, and we must use all four numbers in one equation. The challenge is to find a combination of operations that will result in 24.\n\nLet's explore some potential strategies:\n\n1. **Multiplication and Division First:**\n - Multiplication and division can significantly change the magnitude of numbers, so they are often a good starting point.\n - For example, 8 / 2 = 4. This simplifies the numbers and might help in reaching 24.\n\n2. **Combining Results:**\n - After simplifying, we can try combining results with addition or subtraction.\n - For instance, if we have 4 from the division, we can explore how to use the remaining numbers (8 and 14) to reach 24.\n\n3. **Testing Combinations:**\n - Try different combinations of operations to see which one leads to 24.\n - For example, 14 - 8 = 6, then 6 + 8 = 14, and finally 14 + 10 = 24 (using 10 from 2 * 5).\n\n4. **Creative Grouping:**\n - Sometimes, grouping numbers creatively can help. For example, (14 - 8) * (8 / 2) = 6 * 4 = 24.\n\nBy testing these strategies, we can find a solution that uses all numbers exactly once and results in 24.", 14 | "evaluation": 0.85 15 | } 16 | } -------------------------------------------------------------------------------- /artifacts/tree_of_thoughts_runc3674ef87f274ff186f84bb603cce6cf.json: -------------------------------------------------------------------------------- 1 | { 2 | "final_thoughts": [ 3 | { 4 | "thought": "Choose four numbers that can be easily combined to achieve a sum or product of 24. A common set of numbers for such problems is 1, 3, 4, and 6.\n\nLet's explore one potential operation:\n1 * (3 + 6) * 4 = 1 * 9 * 4 = 36. This doesn't work.\n\nWe will need to revise the approach.\n\nLet's try a different permutation:\n6 / (1 - (3 / 4))\n= 6 / (1 - 0.75)\n= 6 / 0.25\n= 24\n\nThe combination of numbers 1, 3, 6 and 4 and these operations successfully produces 24.", 5 | "evaluation": 0.9 6 | }, 7 | { 8 | "thought": "To solve the problem of using four numbers and basic arithmetic operations (+, -, *, /) to obtain 24 in one equation, I must first determine the four numbers involved. The operations I can use are addition, subtraction, multiplication, and division, and I must find a combination of these operations that results in exactly 24. Without specific numbers provided, I will assume a common set of numbers often used in similar puzzles, such as 4, 4, 4, and 4. I will attempt to construct an equation that equals 24 using these numbers and operations.", 9 | "evaluation": 0.9 10 | }, 11 | { 12 | "thought": "To solve the problem of forming the number 24 using four numbers and basic arithmetic operations, I need to first identify the four numbers. Since the numbers are not provided, I will assume a common set of numbers used in such puzzles, like 1, 3, 4, and 6. The goal is to use these numbers with operations (+, -, *, /) to form the equation that equals 24. A common solution is: (6 / (1 - (3 / 4))) = 24.", 13 | "evaluation": 0.9 14 | }, 15 | { 16 | "thought": "Using the numbers 8, 3, 3, and 1, I can form the equation: (8 / (3 - (1 / 3))) = 24. This equation uses division and subtraction to achieve the target number 24.", 17 | "evaluation": 0.9 18 | } 19 | ], 20 | "pruned_branches": [], 21 | "highest_rated_thought": { 22 | "thought": "Using the numbers 8, 3, 3, and 1, I can form the equation: (8 / (3 - (1 / 3))) = 24. This equation uses division and subtraction to achieve the target number 24.", 23 | "evaluation": 0.9 24 | } 25 | } -------------------------------------------------------------------------------- /artifacts/tree_of_thoughts_runs/tree_of_thoughts_run312f3dbf1dd44439bbc3a9ac4b5b9ec1.json: -------------------------------------------------------------------------------- 1 | { 2 | "final_thoughts": [ 3 | { 4 | "thought": "To solve the problem of using the numbers 2, 8, 8, and 14 with basic arithmetic operations to obtain 24 in one equation, we need to explore combinations of operations on these numbers. We should aim to use each number only once. Here are some possible approaches: \n\n1. Consider multiplication and addition as they can create larger numbers quickly.\n2. Use subtraction or division to adjust numbers if the sum or product is too large.\n3. Given the numbers and the target, a strategic approach might involve using the largest number (14) in a way that brings us closer to 24.\n\nPossible approaches:\n- Determine if any two numbers can be multiplied to get a product close to 24 and adjust with the others.\n- Use a combination of addition and multiplication to reach the target number.\n\nLet's start with some specific calculations:\n- Try (8 * 3) = 24, but we don't have a 3. However, we can try to form a 3 using (14 - 8 - 2 = 4). Then use 8 - 4 = 4 to get closer to 3.\n- Try (2 * 8) + (14 - 8) = 16 + 6 = 22, then adjust by considering other operations.\n\nThese are initial thoughts; further exploration is needed to find the exact equation.", 5 | "evaluation": 0.6 6 | }, 7 | { 8 | "thought": "To solve the problem of using the numbers 2, 8, 8, and 14 with basic arithmetic operations to obtain 24 in one equation, we need to explore combinations of operations on these numbers. We should aim to use each number only once. Here are some possible approaches: \n\n1. Consider multiplication and addition as they can create larger numbers quickly.\n2. Use subtraction or division to adjust numbers if the sum or product is too large.\n3. Given the numbers and the target, a strategic approach might involve using the largest number (14) in a way that brings us closer to 24.\n\nPossible approaches:\n- Determine if any two numbers can be multiplied to get a product close to 24 and adjust with the others.\n- Use a combination of addition and multiplication to reach the target number.\n\nLet's start with some specific calculations:\n- Try (8 * 3) = 24, but we don't have a 3. However, we can try to form a 3 using (14 - 8 - 2 = 4). Then use 8 - 4 = 4 to get closer to 3.\n- Try (2 * 8) + (14 - 8) = 16 + 6 = 22, then adjust by considering other operations.\n\nThese are initial thoughts; further exploration is needed to find the exact equation.", 9 | "evaluation": 0.6 10 | }, 11 | { 12 | "thought": "To solve the problem of using the numbers 2, 8, 8, and 14 with basic arithmetic operations to obtain 24, we need to explore combinations of operations on these numbers. We should aim to use each number only once. Here are some possible approaches: \n\n1. Consider multiplication and addition as they can create larger numbers quickly.\n2. Use subtraction or division to adjust numbers if the sum or product is too large.\n3. Given the numbers and the target, a strategic approach might involve using the largest number (14) in a way that brings us closer to 24.\n\nPossible approaches:\n- Determine if any two numbers can be multiplied to get a product close to 24 and adjust with the others.\n- Use a combination of addition and multiplication to reach the target number.\n\nLet's start with some specific calculations:\n- Try (8 * 3) = 24, but we don't have a 3. However, we can try to form a 3 using (14 - 8 - 2 = 4). Then use 8 - 4 = 4 to get closer to 3.\n- Try (2 * 8) + (14 - 8) = 16 + 6 = 22, then adjust by considering other operations.\n\nThese are initial thoughts; further exploration is needed to find the exact equation.", 13 | "evaluation": 0.6 14 | }, 15 | { 16 | "thought": "To solve this complex problem effectively, it seems should combine steps involving subtraction and multiplication. In this approach: \n\n1. Consider subtraction to form intermediary numbers. \n2. Checking possible multiplication sequences enables testing combinations that can arrive closer to 24. \n3. Trial for subtraction to reduce large numbers to smaller, friendlier multiples or divisors.\n\n\n1. Combine 14 - 8 = 6.\n2. Then Use another set setup: 8 - 2 = 6\n\nI see that there is a potential pattern here: both remaining numbers forming a product will allow a checking sequence in close trials for proprietary calculations. Although, it appears more steps are needed to fully execute it, bringing in alternative combinations using says, a division or addition options not yet fully tested.", 17 | "evaluation": 0.65 18 | } 19 | ], 20 | "pruned_branches": [] 21 | } -------------------------------------------------------------------------------- /artifacts/tree_of_thoughts_runs/tree_of_thoughts_run633a09c0626f40debb7cc22aa6a5e78c.json: -------------------------------------------------------------------------------- 1 | { 2 | "final_thoughts": [ 3 | { 4 | "thought": "We have several attempts that don't seem to lead directly to the solution. We need to rethink our approach by trying combinations that use division and multiplication creatively to balance the numbers around 24.\n\nLet's try a new approach:\n1. Multiply 8 by 2 to get 16.\n2. Now, divide 14 by 8 to get 1.75.\n3. Add 1.75 to 16, which gives us 17.75.\n4. Finally, add the remaining 8, resulting in 25.75.\n\nThis also does not give us 24, indicating the sequence is incorrect. Let's try another trial using different operations or sequences:\n\n1. Divide 14 by 2 to get 7.\n2. Multiply 7 by 8 to get 56.\n3. Divide 56 by 8 to get 7.\n4. Attempt to manipulate the arithmetic around 7 to balance to 24 is again incorrect.\n\nThese attempts show that we're close but not exact, needing to refine or test further combinations or sequences.", 5 | "evaluation": 0.5 6 | }, 7 | { 8 | "thought": "Let's aim to correctly use each number once and achieve 24. The potential issue with prior thoughts might be the misuse or skip of one number. It's essential to create combinations and test all possibilities, including dividing or multiplying all numbers in various sequences. \n\n1. Consider multiplying the highest impact numbers first to reduce large numbers.\n2. Prior thoughts have not tried potentially effective combinatory approaches. Let's explore:\n\nFormula Attempt:\n- Start by dividing 14 by 7, which gives 2 left (utilizing division).\n- If 2 is conveniently simplified, let's use the division outcome by further incorporating other numbers.\n- Remaining numbers will be easier to adjust or combine.\n\nOur initial observation on using the spikes effectively through division may narrow the gaps. Let's proceed.", 9 | "evaluation": 0.6 10 | } 11 | ], 12 | "pruned_branches": [ 13 | { 14 | "thought": "To solve the problem of using the numbers 2, 8, 8, and 14 with basic arithmetic operations to obtain 24 in one equation, we need to explore different combinations and operations. We have several possible initial operations to consider: addition, subtraction, multiplication, and division. Our goal is to find a sequence of operations that results in the final value of 24 using all four numbers exactly once.\n\nLet's start by considering multiplication, as it can quickly increase the value of numbers, potentially getting us closer to 24. We can try multiplying the numbers in different combinations and then using addition or subtraction to reach the target.\n\nOne potential sequence is:\n1. Multiply 2 and 8 to get 16.\n2. Now we have 16, 8, and 14 left.\n3. Add 8 to 16 to get 24.\n4. Verify if the remaining number 14 can be used in a way that doesn't violate the equation.\n\nHowever, this sequence doesn't use all numbers correctly, so let's try another approach:\n1. Multiply 8 and 2 to get 16.\n2. Subtract 14 from 16 to get 2.\n3. Add the remaining 8 to 2 to get 10.\n4. This doesn't work, so let's try another combination.\n\nAnother potential sequence:\n1. Multiply 8 and 2 to get 16.\n2. Add 8 to 16 to get 24.\n3. Now we have used 2, 8, and 8, but we still need to incorporate 14.\n4. We need to find a way to use 14 in this sequence that results in 24.\n\nThis approach still doesn't fully use all numbers correctly, so we need to iterate further or consider different operations or sequences.", 15 | "evaluation": 0.5, 16 | "reason": "Evaluation below prune_threshold" 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /artifacts/tree_of_thoughts_runs_ab1b/tree_of_thoughts_run13fb0d34bfec4c43b6bc9fb1a47d03b3.json: -------------------------------------------------------------------------------- 1 | { 2 | "final_thoughts": [ 3 | { 4 | "thought": "Since the specific four numbers have not been provided, I'll assume a common set of numbers often used in such problems, like 1, 3, 4, and 6. These numbers can be manipulated using operations to reach the target value of 24.", 5 | "evaluation": 0.8 6 | }, 7 | { 8 | "thought": "One possible equation using the numbers 1, 3, 4, and 6 is: (6 / (1 - (3 / 4))) = 24. This equation uses division and subtraction to manipulate the numbers to reach 24.", 9 | "evaluation": 0.8 10 | }, 11 | { 12 | "thought": "To solve this problem, we need to use four numbers and basic arithmetic operations (addition, subtraction, multiplication, division) to achieve the result of 24. The problem does not specify which four numbers to use, so I will assume a common set of numbers used in such puzzles: 1, 5, 5, and 5. These numbers can often be manipulated to reach 24 using creative combinations of operations.", 13 | "evaluation": 0.9 14 | }, 15 | { 16 | "thought": "To solve this problem, we need to select four numbers and use the basic arithmetic operations (addition, subtraction, multiplication, and division) to form an equation that equals 24. The challenge is to find a combination of numbers and operations that satisfy this condition. A common approach is to use numbers that are factors of 24 or can be easily manipulated to reach 24 through multiplication or addition. For example, using numbers like 6, 4, 2, and 1 can be a good starting point since 6 * 4 = 24. However, we need to ensure that the equation uses exactly four numbers and any of the operations. Let's explore possible combinations.", 17 | "evaluation": 0.9 18 | } 19 | ], 20 | "pruned_branches": [], 21 | "highest_rated_thought": { 22 | "thought": "To solve this problem, we need to select four numbers and use the basic arithmetic operations (addition, subtraction, multiplication, and division) to form an equation that equals 24. The challenge is to find a combination of numbers and operations that satisfy this condition. A common approach is to use numbers that are factors of 24 or can be easily manipulated to reach 24 through multiplication or addition. For example, using numbers like 6, 4, 2, and 1 can be a good starting point since 6 * 4 = 24. However, we need to ensure that the equation uses exactly four numbers and any of the operations. Let's explore possible combinations.", 23 | "evaluation": 0.9 24 | } 25 | } -------------------------------------------------------------------------------- /artifacts/tree_of_thoughts_runs_dfs/tree_of_thoughts_run61796eae0d8c40f5b73ed6466d623d08.json: -------------------------------------------------------------------------------- 1 | { 2 | "final_thoughts": [ 3 | { 4 | "thought": "Let's start by identifying the numbers and operations at our disposal. The numbers given are 2, 8, 8, and 14. We can use addition (+), subtraction (-), multiplication (*), and division (/). The goal is to manipulate these numbers using the operations to achieve a result of 24.\n\nFirst, we can try combining numbers to see what results are achievable and if they can be manipulated further to get to 24.\n\nOne approach would be to try multiplication first, as it can increase numbers quickly, which might be useful given that we have larger numbers like 14.\n\n1. Start with multiplication:\n - 2 * 8 = 16. This gives us 16, with 8 and 14 left unused.\n - 8 * 14 = 112. This seems too large, so let's not use this right away.\n\n2. Now, let's try using addition or subtraction:\n - 8 + 14 = 22. This is close to 24, but not quite there.\n\n3. Consider combining operations:\n - (2 * 8) + (14 - 8). We have 16 from 2 * 8, and 6 from 14 - 8, which gives 16 + 6 = 22. We're still not at 24, so let's try other combinations.\n\nThe challenge is to combine these numbers in a way that results in exactly 24. I'll continue exploring more combinations in the next thought process step.", 5 | "evaluation": 0.7 6 | }, 7 | { 8 | "thought": "To solve the problem of using the numbers 2, 8, 8, and 14 to obtain 24 using basic arithmetic operations, I need to explore different combinations and operations. The goal is to find a single equation that results in 24. I will start by considering various operations and combinations of these numbers.", 9 | "evaluation": 0.9 10 | } 11 | ], 12 | "pruned_branches": [], 13 | "highest_rated_thought": { 14 | "thought": "To solve the problem of using the numbers 2, 8, 8, and 14 to obtain 24 using basic arithmetic operations, I need to explore different combinations and operations. The goal is to find a single equation that results in 24. I will start by considering various operations and combinations of these numbers.", 15 | "evaluation": 0.9 16 | } 17 | } -------------------------------------------------------------------------------- /artifacts/tree_of_thoughts_runs_dfs/tree_of_thoughts_run9ed06c5fa92645af87bd45ec931d2dc5.json: -------------------------------------------------------------------------------- 1 | { 2 | "final_thoughts": [ 3 | { 4 | "thought": "Understand the Problem: We need to use exactly four numbers and basic arithmetic operations (addition, subtraction, multiplication, and division) to create an equation that equals 24. Each number can be used once, and any combination of the four operations can be used, but the final outcome must strictly be 24. Examples of such puzzles typically have the numbers predefined, but we don't have specific numbers listed here yet, so I will assume a common set for such problems, usually a mix of simple integers such as 1, 2, 3, and larger numbers like 8. \n\nLet's use the set [3, 3, 8, 8] or [1, 3, 4, 6] which are popular for this type of challenge. I will proceed with exploring a solution for both sets.", 5 | "evaluation": 0.9 6 | }, 7 | { 8 | "thought": "To solve the problem, I will consider the numbers 1, 3, 4, and 6. A common approach is to try different combinations of operations and groupings. One possible solution is: (6 / (1 - 3/4)) = 24. This equation uses division and subtraction to manipulate the numbers to reach 24.", 9 | "evaluation": 0.9 10 | }, 11 | { 12 | "thought": "To solve this problem, I need to select four numbers and apply basic arithmetic operations to achieve a result of 24. A common approach is to use the numbers 8, 3, 3, and 1, as they can be combined to form 24 using the equation: (8 / (3 - (1 / 3))) = 24. This equation uses division and subtraction to manipulate the numbers effectively.", 13 | "evaluation": 0.9 14 | }, 15 | { 16 | "thought": "To solve this problem, we need to identify a set of four numbers and apply basic arithmetic operations to them to achieve the target number 24. This problem can often be solved by using numbers already known to have solutions, such as 3, 3, 8, 8 or 1, 5, 5, 5. These sets of numbers are common in similar problems about reaching 24 using four numbers. \n\nOne well-known solution is to use the numbers 3, 3, 8, 8. By arranging the operations appropriately, we can construct the equation:\n\n(8 / (3 - 8/3)) = 24 \n\nThis works because:\n1. Divide 8 by 3, getting approximately 2.666...\n2. Subtract the result from 3, which leaves approximately 0.333...\n3. Divide 8 by this small number (approximately 0.333...), which gives approximately 24.\n\nThe calculations are precise and the operations are correctly applied to achieve the result.\n\nNext, I will perform a self-evaluation of this thought process.", 17 | "evaluation": 0.9 18 | } 19 | ], 20 | "pruned_branches": [], 21 | "highest_rated_thought": { 22 | "thought": "To solve this problem, we need to identify a set of four numbers and apply basic arithmetic operations to them to achieve the target number 24. This problem can often be solved by using numbers already known to have solutions, such as 3, 3, 8, 8 or 1, 5, 5, 5. These sets of numbers are common in similar problems about reaching 24 using four numbers. \n\nOne well-known solution is to use the numbers 3, 3, 8, 8. By arranging the operations appropriately, we can construct the equation:\n\n(8 / (3 - 8/3)) = 24 \n\nThis works because:\n1. Divide 8 by 3, getting approximately 2.666...\n2. Subtract the result from 3, which leaves approximately 0.333...\n3. Divide 8 by this small number (approximately 0.333...), which gives approximately 24.\n\nThe calculations are precise and the operations are correctly applied to achieve the result.\n\nNext, I will perform a self-evaluation of this thought process.", 23 | "evaluation": 0.9 24 | } 25 | } -------------------------------------------------------------------------------- /artifacts/tree_of_thoughts_runs_dfs/tree_of_thoughts_runa623b99c447247edb143285d7bf49e29.json: -------------------------------------------------------------------------------- 1 | { 2 | "final_thoughts": [ 3 | { 4 | "thought": "To solve this problem, I need to identify four numbers and use the basic arithmetic operations (addition, subtraction, multiplication, division) to form an equation that results in 24. The problem does not specify which four numbers to use, so I will assume that I can choose any four numbers. A common set of numbers used in such problems is 1, 3, 4, and 6, as they can be combined in various ways to reach 24.", 5 | "evaluation": 0.8 6 | }, 7 | { 8 | "thought": "To solve this problem, I need to select four numbers and use basic arithmetic operations (addition, subtraction, multiplication, division) to create an equation that equals 24. A common set of numbers used for such puzzles is 1, 3, 4, and 6. I will attempt to use these numbers to form the equation.\n\nFirst, I will consider the multiplication operation, as it can quickly increase the value of numbers. I will start by multiplying two numbers and then see how I can use the remaining numbers to reach 24.\n\nLet's try: 6 * 4 = 24. This already gives us 24, but we need to use all four numbers. So, I will adjust the approach to ensure all numbers are used.\n\nOne possible equation is: (6 / (1 - (3/4))) = 24. This equation uses all four numbers and basic arithmetic operations to reach 24.", 9 | "evaluation": 0.9 10 | } 11 | ], 12 | "pruned_branches": [], 13 | "highest_rated_thought": { 14 | "thought": "To solve this problem, I need to select four numbers and use basic arithmetic operations (addition, subtraction, multiplication, division) to create an equation that equals 24. A common set of numbers used for such puzzles is 1, 3, 4, and 6. I will attempt to use these numbers to form the equation.\n\nFirst, I will consider the multiplication operation, as it can quickly increase the value of numbers. I will start by multiplying two numbers and then see how I can use the remaining numbers to reach 24.\n\nLet's try: 6 * 4 = 24. This already gives us 24, but we need to use all four numbers. So, I will adjust the approach to ensure all numbers are used.\n\nOne possible equation is: (6 / (1 - (3/4))) = 24. This equation uses all four numbers and basic arithmetic operations to reach 24.", 15 | "evaluation": 0.9 16 | } 17 | } -------------------------------------------------------------------------------- /artifacts/tree_of_thoughts_runs_dfs/tree_of_thoughts_runaad46510cedb454cbd7bf61bd65740a9.json: -------------------------------------------------------------------------------- 1 | { 2 | "final_thoughts": [], 3 | "pruned_branches": [] 4 | } -------------------------------------------------------------------------------- /artifacts/tree_of_thoughts_runs_dfs/tree_of_thoughts_runb31312e3819d4945a542a7b2d8debca7.json: -------------------------------------------------------------------------------- 1 | { 2 | "final_thoughts": [ 3 | { 4 | "thought": "To solve this problem, we need to use four numbers and basic arithmetic operations to reach the result of 24. The problem does not specify which four numbers to use, so I will assume we can choose any four numbers. A common set of numbers used in such problems is 1, 3, 4, and 6, as they can be combined in various ways to reach 24. Let's explore how we can use these numbers and operations to achieve the target.\n\nFirst, consider the equation: (6 * 4) - (3 * 1) = 24.\n\nThis equation uses multiplication and subtraction to reach the target number. Let's break it down:\n- Multiply 6 by 4 to get 24.\n- Multiply 3 by 1 to get 3.\n- Subtract 3 from 24 to get 21.\n\nThis equation does not reach 24, so let's adjust it. Instead, try: (6 / (1 - (3 / 4))) = 24.\n\nThis equation uses division and subtraction:\n- Divide 3 by 4 to get 0.75.\n- Subtract 0.75 from 1 to get 0.25.\n- Divide 6 by 0.25 to get 24.\n\nThis equation successfully reaches 24 using the numbers 1, 3, 4, and 6.", 5 | "evaluation": 0.9 6 | }, 7 | { 8 | "thought": "To solve this problem, I need to choose 4 numbers and apply basic arithmetic operations such as addition, subtraction, multiplication, or division to reach the result of 24 in one equation. A common choice of numbers for such puzzles is 4, 4, 4, and 4, as they allow for creative operations to reach 24. I will explore a few possible combinations to see if they yield the result of 24.", 9 | "evaluation": 0.9 10 | } 11 | ], 12 | "pruned_branches": [], 13 | "highest_rated_thought": { 14 | "thought": "To solve this problem, I need to choose 4 numbers and apply basic arithmetic operations such as addition, subtraction, multiplication, or division to reach the result of 24 in one equation. A common choice of numbers for such puzzles is 4, 4, 4, and 4, as they allow for creative operations to reach 24. I will explore a few possible combinations to see if they yield the result of 24.", 15 | "evaluation": 0.9 16 | } 17 | } -------------------------------------------------------------------------------- /artifacts/tree_of_thoughts_runs_dfs/tree_of_thoughts_rund2933f248d0545b89fec4811c6afffd4.json: -------------------------------------------------------------------------------- 1 | { 2 | "final_thoughts": [ 3 | { 4 | "thought": "First, I need to evaluate the given numbers: 2, 8, 8, and 14, and explore the operations available (+, -, *, /) to reach the target number 24 using all numbers in one equation. My initial approach is to consider combinations that utilize multiplication and addition primarily, as these are likely to generate larger numbers closer to 24.", 5 | "evaluation": 0.8 6 | }, 7 | { 8 | "thought": "The problem requires using the numbers 2, 8, 8, and 14 with basic arithmetic operations to obtain the result of 24 in one equation. First, I will explore combinations of these numbers using addition, subtraction, multiplication, and division to see if I can achieve 24. One possible approach is to start by combining smaller numbers and gradually build up to 24. For example, I can try multiplying two numbers first and then see if I can adjust the result with addition or subtraction.", 9 | "evaluation": 0.8 10 | } 11 | ], 12 | "pruned_branches": [], 13 | "highest_rated_thought": { 14 | "thought": "The problem requires using the numbers 2, 8, 8, and 14 with basic arithmetic operations to obtain the result of 24 in one equation. First, I will explore combinations of these numbers using addition, subtraction, multiplication, and division to see if I can achieve 24. One possible approach is to start by combining smaller numbers and gradually build up to 24. For example, I can try multiplying two numbers first and then see if I can adjust the result with addition or subtraction.", 15 | "evaluation": 0.8 16 | } 17 | } -------------------------------------------------------------------------------- /artifacts/tree_of_thoughts_runs_dfs/tree_of_thoughts_rune38f1f07ba534c25b425633e53438f05.json: -------------------------------------------------------------------------------- 1 | { 2 | "final_thoughts": [ 3 | { 4 | "thought": "To solve the problem, I need to identify four numbers and use basic arithmetic operations (+, -, *, /) to form an equation that equals 24. The problem does not specify the four numbers, so I will assume a common set of numbers used in such puzzles: 1, 3, 4, and 6. These numbers are often used because they can be combined in various ways to achieve 24 using basic operations.", 5 | "evaluation": 0.9 6 | } 7 | ], 8 | "pruned_branches": [ 9 | { 10 | "thought": "To solve the problem of obtaining 24 using 4 numbers and basic arithmetic operations, I first need to select 4 numbers. Let's choose the numbers 8, 3, 3, and 1. Now, I'll attempt to use these numbers with the operations +, -, *, and / to achieve 24.\n\nFirst, I'll try multiplying and adding these numbers:\n\n(8 * 3) = 24\n\nThis is already 24, so I can just multiply 8 by 3 to get the desired result. However, since I must use all four numbers, I need to incorporate 3 and 1 into the equation as well.\n\nLet's try another approach:\n\n(8 * 3) - (3 / 1) = 24 - 3 = 21\n\nThis doesn't work, so I need to find a different combination.\n\nNow, I'll try:\n\n8 * (3 - (1 / 3)) = 8 * (3 - 0.3333) = 8 * 2.6667 \u2248 21.3336\n\nThis is close, but not exact.\n\nFinally, let's try:\n\n(8 / (3 - 1)) * 3 = (8 / 2) * 3 = 4 * 3 = 12\n\nThis doesn't work either. I need to reevaluate my approach and try a different combination of operations and numbers.", 11 | "evaluation": 0.5, 12 | "reason": "Evaluation score below threshold" 13 | } 14 | ], 15 | "highest_rated_thought": { 16 | "thought": "To solve the problem, I need to identify four numbers and use basic arithmetic operations (+, -, *, /) to form an equation that equals 24. The problem does not specify the four numbers, so I will assume a common set of numbers used in such puzzles: 1, 3, 4, and 6. These numbers are often used because they can be combined in various ways to achieve 24 using basic operations.", 17 | "evaluation": 0.9 18 | } 19 | } -------------------------------------------------------------------------------- /artifacts/tree_of_thoughts_runs_new/tree_of_thoughts_run42756b8d76d24b06843006c1fd8fbe75.json: -------------------------------------------------------------------------------- 1 | { 2 | "final_thoughts": [ 3 | { 4 | "thought": "To solve this problem, we need to find a combination of the given numbers (2, 8, 8, 14) and basic arithmetic operations (+, -, *, /) that result in the number 24. We have several possibilities for initial operations, but we need to ensure that all four numbers are used exactly once and the operations result in the target number. Let's consider a few potential solutions and evaluate them.\n\n1. Check if any straightforward combination of multiplication and addition can achieve 24.\n - For example, (2 * 8) + (8 / 2) = 16 + 4 = 20. This does not work.\n\n2. Try using division to simplify one of the numbers into a factor of 24.\n - For instance, 14 - 8 = 6, leaving us with numbers 2, 6, 8. Can these be combined to reach 24?\n - (8 / 2) * 6 = 4 * 6 = 24. This works, but we didn't use all numbers correctly.\n\n3. Explore using subtraction and multiplication in different orders.\n - (14 / 2) * 2 * (8 / 8) = 7 * 2 * 1 = 14. This approach doesn't work either.\n\n4. Try combinations that involve all numbers in a single equation.\n - (14 - (8 / 8)) * 2 = (14 - 1) * 2 = 13 * 2 = 26. This is incorrect.\n\nLet's refine our approach and evaluate if there are other combinations that might work. We seem to be missing a valid combination or order of operations that can yield 24. Further exploration of combinations is needed.", 5 | "evaluation": 0.6 6 | }, 7 | { 8 | "thought": "Upon reviewing potential solutions, we should re-evaluate the possibilities of using all four numbers with different combinations of operations. I will consider each number's role relative to their operations and how they might contribute to forming 24.\n\n1. Consider multiplication and division to form immediate factors of 24:\n - Since 8 * 3 = 24, consider breaking down the number 3 from 2, 14, and 8.\n - Possible calculation might involve: 8 / (14 / 7) * 2 can form multiplication paths towards 24.\n\n2. Explore breaking down 24 as a product of smaller numbers, especially looking at prime factors: 2 * 12 or 3 * 8.\n - Using two 8s can form 64, bringing division into play.\n\n3. Implement numbers in the equation ensuring all are used:\n - Test (8 / 2) * (14 - 8) yields 24, but this doesn't use all numbers correctly.\n\n4. Break down each number:\n - Turn 14 into 7 through division or subtraction, see if it lends itself naturally to a balanced equation.\n\nThe realization is that overlapping operations must be continuous, and the previous attempts missed a few viable connections between numbers, especially concerning the balanced application of subtraction and division.", 9 | "evaluation": 0.7 10 | }, 11 | { 12 | "thought": "The problem provides a sequence of numbers: 2, 8, 8, and 14. The task is to use these numbers and basic arithmetic operations (+, -, *, /) to form an equation that results in the number 24. We need to explore different combinations and operations to achieve this target, taking care to use each number exactly once and ensuring that the result is 24.", 13 | "evaluation": 0.8 14 | }, 15 | { 16 | "thought": "The problem provides a sequence of numbers: 2, 8, 8, and 14. The task is to use these numbers and basic arithmetic operations (+, -, *, /) to form an equation that results in the number 24. We need to explore different combinations and operations to achieve this target, taking care to use each number exactly once and ensuring that the result is 24.", 17 | "evaluation": 0.8 18 | }, 19 | { 20 | "thought": "To solve the problem of forming the number 24 using the numbers 2, 8, 8, and 14 with basic arithmetic operations, we need to ensure we use each number exactly once. Here is one potential solution:\n\n1. Recognize that if we can manipulate the numbers to form factors of 24, it might lead to a solution.\n2. Consider breaking down 24 as 3 * 8 or 6 * 4.\n3. One possible arrangement might involve the following steps:\n - Use 14 - 8 = 6, which simplifies the problem by introducing a 6.\n - Now we have 2, 6, and 8 left, we need to use these to reach 24.\n4. Think about how 6 and 8 relate to 24:\n - 6 * 4 = 24, so we need a 4.\n - Use 8 / 2 to get 4.\n - Multiply 6 by 4 to achieve 24.\n\nThis solution involves the operations: (14 - 8) * (8 / 2) = 6 * 4 = 24. Here, each number is used exactly once and the operations are correctly applied to achieve the target number 24.", 21 | "evaluation": 0.9 22 | } 23 | ], 24 | "pruned_branches": [] 25 | } -------------------------------------------------------------------------------- /artifacts/tree_of_thoughts_runs_new/tree_of_thoughts_run74dc80144f584b739d05ba0f96a8e74a.json: -------------------------------------------------------------------------------- 1 | { 2 | "final_thoughts": [ 3 | { 4 | "thought": "Let's attempt another possible calculation using the numbers 2, 8, 8, and 14. Consider using division to manipulate the numbers closer to the desired result of 24. \n\nAttempt the following equation: 14 - (8 / 8) * 2 = 24. Let's verify:\n- 8 / 8 = 1\n- 1 * 2 = 2\n- 14 - 2 = 12 (This does not result in 24)\n\nTry a different strategy: (14 / 2) * 8 - 8 = 24. Let's verify:\n- 14 / 2 = 7\n- 7 * 8 = 56\n- 56 - 8 = 48 (This is incorrect as well)\n\nFinally, try: 8 * (14 / (2 + 8)) = 24. Let's verify:\n- 2 + 8 = 10\n- 14 / 10 = 1.4\n- 8 * 1.4 = 11.2 (This also doesn't work)\n\nEach approach has led to similar conclusions: the operations and the combination of these numbers are more challenging to align correctly. More exploration is needed or a deeper re-evaluation of our approach to discover the correct process.", 5 | "evaluation": 0.6 6 | }, 7 | { 8 | "thought": "Let's attempt another possible calculation using the numbers 2, 8, 8, and 14. Consider using division to manipulate the numbers closer to the desired result of 24. \n\nAttempt the following equation: 14 - (8 / 8) * 2 = 24. Let's verify:\n- 8 / 8 = 1\n- 1 * 2 = 2\n- 14 - 2 = 12 (This does not result in 24)\n\nTry a different strategy: (14 / 2) * 8 - 8 = 24. Let's verify:\n- 14 / 2 = 7\n- 7 * 8 = 56\n- 56 - 8 = 48 (This is incorrect as well)\n\nFinally, try: 8 * (14 / (2 + 8)) = 24. Let's verify:\n- 2 + 8 = 10\n- 14 / 10 = 1.4\n- 8 * 1.4 = 11.2 (This also doesn't work)\n\nEach approach has led to similar conclusions: the operations and the combination of these numbers are more challenging to align correctly. More exploration is needed or a deeper re-evaluation of our approach to discover the correct process.", 9 | "evaluation": 0.6 10 | }, 11 | { 12 | "thought": "To solve this problem, we need to use the numbers 2, 8, 8, and 14 and apply basic arithmetic operations (+, -, *, /) to obtain the result of 24 in one equation. The challenge is to use all four numbers exactly once and combine them in a way that results in the target number 24.\n\nStep 1: Analyze the Given Numbers\n- We have two 8s, which suggests multiplication might be helpful since 8 * 3 = 24.\n- The number 14 is quite large compared to 24, so subtraction might be necessary.\n- The number 2 could be useful for division or multiplication to adjust the values.\n\nStep 2: Consider Possible Combinations\n- One possible approach is to start by multiplying the two 8s: 8 * 8 = 64. However, 64 is much larger than 24, so this might not be the best approach.\n- Another approach could be to use the 8 and 14 in a way that their combination approaches 24.\n\nStep 3: Explore Viable Equations\n- A possible equation could be (14 - 8) * 2 + 8 = 24. Let's verify:\n - (14 - 8) = 6\n - 6 * 2 = 12\n - 12 + 8 = 20 (This does not result in 24, so it needs adjustment)\n\nStep 4: Re-evaluate and Try Again\n- Another approach could be: (14 - 2) + (8 / 8) = 24. Let's verify:\n - (14 - 2) = 12\n - (8 / 8) = 1\n - 12 + 1 = 13 (This also does not result in 24)\n\nIt seems that the challenge is to find a combination where the operations and order of operations align perfectly to reach 24. More exploration is needed to find the correct equation.", 13 | "evaluation": 0.6 14 | }, 15 | { 16 | "thought": "Given the numbers 2, 8, 8, and 14, and the task of using them exactly once with basic arithmetic operations to achieve the result of 24, let's explore more combinations.\n\nStep 1: Reconsider the Use of Each Number\n- The pair of 8s suggests potential for multiplication or division, but their multiplication (8 * 8 = 64) is too large.\n- The number 14 is larger than 24, so possibly using it in subtraction might help.\n- The number 2 could be a key in adjusting the result through multiplication or division.\n\nStep 2: Try a Different Approach\n- Consider using division to simplify the equation, especially with the repeated 8s.\n- A possible approach could be using subtraction with 14 and then adjusting with 8s and 2.\n\nStep 3: Attempt New Equations\n- Consider the equation: (14 - 8) + (8 * 2) = 24. Let's verify:\n - (14 - 8) = 6\n - 8 * 2 = 16\n - 6 + 16 = 22 (This is close but not correct)\n\nStep 4: Refine the Approach\n- Another attempt could be: (14 / 2) + 8 + 2 = 24. Let's verify:\n - 14 / 2 = 7\n - 7 + 8 = 15\n - 15 + 2 = 17 (This also does not result in 24)\n\nThe challenge remains in finding the correct combination of operations and order that will result in 24. Continuing to test different equations and re-evaluating the use of each number and operation is necessary.", 17 | "evaluation": 0.7 18 | } 19 | ], 20 | "pruned_branches": [] 21 | } -------------------------------------------------------------------------------- /artifacts/tree_of_thoughts_runs_new/tree_of_thoughts_run797856a37471412dbe97b056cbfff541.json: -------------------------------------------------------------------------------- 1 | { 2 | "final_thoughts": [ 3 | { 4 | "thought": "A viable strategy is to construct a number that can be easily manipulated to reach 24. We have the numbers 2, 8, 8, and 14 to consider. One potential path is to involve the operation that every number could contribute meaningfully. For instance:\n1. Compute (14 - 8) to get 6.\n2. Use 2 to manipulate it: 6 * 2 = 12.\n3. Use the next 8, suppose in division: it can serve as a reduction factor or reconsider a combination in step. Let's attempt ( 8 / 4 + 2) * 3 to comprehend errors or re-evaluate this attempt start.\n\nI'll need to reassess through:\n- (14 - 8) resulting in - direct shift towards a manipulative boundary: re-evaluate operation mapping to encompass direct operand choices.\n\nTo conclude in reevaluation, it appears reaching the value might force reconsiderations on valid operand synthesis and original combination recalcium. Final adjustment awaits prior calculation confirmation.", 5 | "evaluation": 0.5 6 | }, 7 | { 8 | "thought": "Given the numbers 2, 8, 8, and 14, let's explore a combination where we can reach 24. One potential path is to use multiplication and addition in a strategic way:\n\n1. Consider multiplying the two 8s together: 8 * 8 = 64.\n2. Now, let's see if we can use division or subtraction to adjust this result closer to 24.\n3. If we divide 64 by 2, we get 32, which is still too high.\n4. Let's try subtraction: if we subtract 14 from 64, we get 50, which is still above 24.\n5. Instead, let's try 14 - 8 = 6. \n6. Multiply 6 by 2 to get 12.\n7. Now, we can multiply 12 by 2 (from the division of 8 by 4) to reach 24.\n\nThis reasoning needs verification, as it might not use all numbers appropriately, and the operations might not align perfectly yet. Let's re-evaluate and adjust if necessary.", 9 | "evaluation": 0.7 10 | }, 11 | { 12 | "thought": "To solve the problem, we need to use the numbers 2, 8, 8, and 14 with basic arithmetic operations to obtain the result of 24 in one equation. We must consider all possible combinations of operations and order of operations to achieve this result. We can start by exploring combinations that involve multiplication and division, as they tend to reach higher values quickly, which might be necessary to reach 24. Additionally, since the number 24 is even and can be factored into 2 * 12 or 3 * 8, we should consider these factors in our operations.", 13 | "evaluation": 0.8 14 | }, 15 | { 16 | "thought": "To solve the problem, we need to use the numbers 2, 8, 8, and 14 with basic arithmetic operations to obtain the result of 24 in one equation. We must consider all possible combinations of operations and order of operations to achieve this result. We can start by exploring combinations that involve multiplication and division, as they tend to reach higher values quickly, which might be necessary to reach 24. Additionally, since the number 24 is even and can be factored into 2 * 12 or 3 * 8, we should consider these factors in our operations.", 17 | "evaluation": 0.8 18 | } 19 | ], 20 | "pruned_branches": [] 21 | } -------------------------------------------------------------------------------- /artifacts/tree_of_thoughts_runs_new/tree_of_thoughts_run8c9ad018220e40978b1b3bcfdf3e0dbc.json: -------------------------------------------------------------------------------- 1 | { 2 | "final_thoughts": [ 3 | { 4 | "thought": "I should try a different combination of operations that involve all four numbers. Let's consider the operations that will strategically use higher multiples or results and then see if they can be combined to reach 24. For instance, consider (14 - 8) = 6 and then 6 * 4 = 24, but the number 4 is not directly available. Instead, I might try using division first: 14 / 2 = 7, which gives a useful number, but I need to use up all four numbers. I'll keep exploring.", 5 | "evaluation": 0.5 6 | }, 7 | { 8 | "thought": "We need to use all four numbers exactly once to reach 24. One potential approach is to try using division and multiplication strategically to get closer to 24. Let's consider the following combination: \n\n1. Use division to simplify: 14 / 2 = 7. \n2. Now, we have numbers 7, 8, and 8 left. \n3. Try multiplying: 7 * 8 = 56, which is too large, so let's reconsider. \n4. Instead, try: 8 / 8 = 1, leaving us with numbers 7 and 1.\n5. Now, multiply: 7 * 1 = 7, which is still not 24.\n\nThis approach isn't leading to 24 directly. I need to reassess and try another combination that uses all four numbers more effectively. Let's try considering additive combinations or different groupings.", 9 | "evaluation": 0.7 10 | }, 11 | { 12 | "thought": "To solve this problem, we need to use the numbers 2, 8, 8, and 14 with basic arithmetic operations to obtain the result of 24 in one equation. We have several operations and possible combinations to consider. Let's evaluate each possibility step by step:\n\n1. **Initial Attempt**: Try using multiplication and addition as they can quickly increase values.\n - Attempt: (2 * 8) + 8 = 24. However, this doesn't use all numbers.\n\n2. **Re-evaluation**: We need to use all four numbers exactly once to reach 24.\n - Consider using division and multiplication strategically.\n - Attempt: 14 / 2 = 7, leaving 7, 8, and 8.\n - Try multiplying: 7 * 8 = 56, which is too large.\n - Instead, try: 8 / 8 = 1, leaving 7 and 1.\n - Multiply: 7 * 1 = 7, add remaining 8: 7 + 8 = 15, not 24.\n\n3. **Further Exploration**: Try different combinations or groupings.\n - Attempt: (14 - 8) = 6, then 6 * 4 = 24, but 4 is not available.\n - Consider: (14 / 2) = 7, then 7 * (8 / (8/8)) = 24, but this doesn't use all numbers correctly.\n\n4. **Final Approach**: Use trial and error with focus on combinations that might result in smaller intermediary results that step closer to 24.\n - Explore combination: (14 / 2) = 7 * (8 / (8/8)) which adjusts the intended numerical balance through correct operation order.\n\nThe focus is on exact operation pairing with end equation integrity to achieve 24. Further exploration needed to find the correct combination.", 13 | "evaluation": 0.7 14 | }, 15 | { 16 | "thought": "To solve the problem of combining the numbers 2, 8, 8, and 14 to obtain 24 using basic arithmetic operations, I need to ensure that all numbers are used exactly once. Let's consider a strategic approach:\n\n1. **Initial Strategy**: Use division to simplify numbers and multiplication to reach closer to 24.\n - Divide 14 by 2: 14 / 2 = 7. Now we have 7, 8, and 8 left.\n - Multiply 7 by 8: 7 * 8 = 56. This is too large, so this path isn't viable.\n\n2. **Alternative Strategy**: Use subtraction to create smaller numbers and then multiply.\n - Subtract 8 from 14: 14 - 8 = 6. Now we have 6, 8, and 2 left.\n - Multiply 6 by 4 (if we could create 4, but 4 isn't directly available).\n\n3. **Re-evaluation**: Focus on different pairings.\n - Consider using division to create a useful multiplication factor.\n - Divide 14 by 2: 14 / 2 = 7.\n - Consider using the remaining 8 and 8 to create a factor of 1: 8 / 8 = 1.\n - Multiply 7 by 1: 7 * 1 = 7.\n - Add remaining 8: 7 + 8 = 15, which is not 24.\n\n4. **Final Approach**: Trial and error with different combinations.\n - Reconsider operations that might yield smaller intermediary results that step closer to 24.\n - Explore combination: (14 / 2) = 7 * (8 / (8/8)) which adjusts the intended numerical balance through correct operation order.\n\nOverall, the focus is on exact operation pairing with end equation integrity to achieve 24. Further exploration and trial and error are needed to find the correct combination.", 17 | "evaluation": 0.7 18 | } 19 | ], 20 | "pruned_branches": [] 21 | } -------------------------------------------------------------------------------- /artifacts/tree_of_thoughts_runs_new/tree_of_thoughts_runbe34ed62969041a9b9d3b0b81cc5c6ed.json: -------------------------------------------------------------------------------- 1 | { 2 | "final_thoughts": [ 3 | { 4 | "thought": "To solve the problem of obtaining 24 using the numbers 2, 8, 8, and 14 with basic arithmetic operations, a potential approach is to use multiplication and addition strategically. One possible solution is: (2 * (14 - 8)) + 8 = (2 * 6) + 8 = 12 + 8 = 20, which doesn't achieve 24. This incorrect result indicates a need for reevaluation of operations, suggesting another possible combination. A correct attempt is: (14 - (8 - 2)) * 2 = (14 - 6) * 2 = 8 * 2 = 16, which is still incorrect. Finally, consider another combination: 14 + (8 / 8) * 2 = 14 + 0.25 * 2 = 14 + 0.5 = 14.5, which again does not reach 24. Further adjustments and trials are essential to reach the desired result.", 5 | "evaluation": 0.5 6 | }, 7 | { 8 | "thought": "We need to find a combination of operations and orders for 2, 8, 8, and 14 to reach 24. A promising approach is to consider multiplication for increasing the value and subtraction or division for adjusting precisely. Given these numbers, one potential solution is: (14 - 8) * 2 + 8 = 12 + 8 = 20 (incorrect). This approach doesn't yield 24, but by adjusting the operations, another attempt is: 14 - (8 / 2) + 8 = 14 - 4 + 8 = 18 (incorrect). Therefore, further adjustments are needed.", 9 | "evaluation": 0.6 10 | }, 11 | { 12 | "thought": "First, identify the potential operations that can be performed with the numbers 2, 8, 8, and 14 to achieve the result of 24. The order of operations and combination of numbers is crucial. Given the numbers, we need to consider both addition/subtraction and multiplication/division as potential operations to reach 24. A possible approach is to try combining the numbers step by step, while evaluating if the intermediate results can lead to the final target of 24.", 13 | "evaluation": 0.8 14 | }, 15 | { 16 | "thought": "First, identify the potential operations that can be performed with the numbers 2, 8, 8, and 14 to achieve the result of 24. The order of operations and combination of numbers is crucial. Given the numbers, we need to consider both addition/subtraction and multiplication/division as potential operations to reach 24. A possible approach is to try combining the numbers step by step, while evaluating if the intermediate results can lead to the final target of 24.", 17 | "evaluation": 0.8 18 | }, 19 | { 20 | "thought": "To solve the problem of obtaining 24 using the numbers 2, 8, 8, and 14 with basic arithmetic operations, we need to find a combination of these numbers and operations that will result in 24. We must consider all pairs and combinations of numbers that can be combined using addition, subtraction, multiplication, and division. Additionally, we should verify each calculation step to ensure we are correctly following the mathematical operations and not deviating from the given set of numbers and their allowable usage.", 21 | "evaluation": 0.9 22 | } 23 | ], 24 | "pruned_branches": [] 25 | } -------------------------------------------------------------------------------- /artifacts/tree_of_thoughts_runs_new/tree_of_thoughts_runfd2af70b3f3546508bc09e66f324e976.json: -------------------------------------------------------------------------------- 1 | { 2 | "final_thoughts": [ 3 | { 4 | "thought": "One potential approach to solve this problem is to start by using multiplication to increase the values quickly. For example, we could try multiplying 8 and 2 to get 16, and then see how the remaining numbers 8 and 14 can be combined to reach 24. \n\nHowever, another interesting approach is to consider dividing 14 by 2 to get 7, then adding the two 8's to reach 23, which is close to 24. This means we need to find a way to adjust slightly, possibly by considering subtraction or division in a different order.\n\nExploring these avenues will help us find a combination that results in 24.", 5 | "evaluation": 0.7 6 | }, 7 | { 8 | "thought": "To solve the problem using the numbers 2, 8, 8, and 14 to obtain 24, we should consider both the order of operations and the potential for each operation to contribute to reaching 24. A promising strategy is to first use multiplication or division to adjust the numbers closer to 24, then use addition or subtraction to fine-tune the result. Let's explore the combinations:\n\n1. Start with multiplication: 2 * 8 = 16. This leaves us with 16, 8, and 14.\n2. Next, consider using division: 14 / 7 = 2 (if we could make 7 from the remaining numbers, but here it doesn't directly help).\n3. Alternatively, try addition: 16 + 8 = 24, which is our target.\n\nThus, one potential solution is to first multiply 2 and 8 to get 16, then add the remaining 8 to achieve 24. This uses the numbers 2, 8, 8, and 14 in a valid way.", 9 | "evaluation": 0.9 10 | }, 11 | { 12 | "thought": "To solve the problem using the numbers 2, 8, 8, and 14 to obtain 24, we should consider both the order of operations and the potential for each operation to contribute to reaching 24. A promising strategy is to first use multiplication or division to adjust the numbers closer to 24, then use addition or subtraction to fine-tune the result. Let's explore the combinations:\n\n1. Start with multiplication: 2 * 8 = 16. This leaves us with 16, 8, and 14.\n2. Next, consider using division: 14 / 7 = 2 (if we could make 7 from the remaining numbers, but here it doesn't directly help).\n3. Alternatively, try addition: 16 + 8 = 24, which is our target.\n\nThus, one potential solution is to first multiply 2 and 8 to get 16, then add the remaining 8 to achieve 24. This uses the numbers 2, 8, 8, and 14 in a valid way.", 13 | "evaluation": 0.9 14 | }, 15 | { 16 | "thought": "To solve the problem using the numbers 2, 8, 8, and 14 to obtain 24, we should consider both the order of operations and the potential for each operation to contribute to reaching 24. A promising strategy is to first use multiplication or division to adjust the numbers closer to 24, then use addition or subtraction to fine-tune the result. Let's explore the combinations:\n\n1. Start with multiplication: 2 * 8 = 16. This leaves us with 16, 8, and 14.\n2. Next, consider using division: 14 / 7 = 2 (if we could make 7 from the remaining numbers, but here it doesn't directly help).\n3. Alternatively, try addition: 16 + 8 = 24, which is our target.\n\nThus, one potential solution is to first multiply 2 and 8 to get 16, then add the remaining 8 to achieve 24. This uses the numbers 2, 8, 8, and 14 in a valid way.", 17 | "evaluation": 0.9 18 | }, 19 | { 20 | "thought": "The goal is to use the numbers 2, 8, 8, and 14 exactly once in a combination of basic arithmetic operations (+, -, *, /) to achieve the result of 24. To systematically approach this, we can consider several strategies, focusing initially on operations that create large changes, like multiplication and division. \n\nFirst, let's consider multiplication and division as they can bring numbers closer to a target quickly:\n\n1. Multiply 2 and 8 to get 16. This leaves us with 16, 8, and 14.\n2. Now, add the remaining 8 to 16, resulting in 16 + 8 = 24.\n\nThis approach successfully uses the numbers 2, 8, 8, and 14 to achieve 24. It is efficient because it takes advantage of multiplication to quickly increase the magnitude of numbers, making it easier to reach the target through subsequent addition.", 21 | "evaluation": 0.9 22 | }, 23 | { 24 | "thought": "To solve the problem using the numbers 2, 8, 8, and 14 to obtain 24, we should consider both the order of operations and the potential for each operation to contribute to reaching 24. A promising strategy is to first use multiplication or division to adjust the numbers closer to 24, then use addition or subtraction to fine-tune the result. Let's explore the combinations:\n\n1. Start with multiplication: 2 * 8 = 16. This leaves us with 16, 8, and 14.\n2. Next, consider using division: 14 / 7 = 2 (if we could make 7 from the remaining numbers, but here it doesn't directly help).\n3. Alternatively, try addition: 16 + 8 = 24, which is our target.\n\nThus, one potential solution is to first multiply 2 and 8 to get 16, then add the remaining 8 to achieve 24. This uses the numbers 2, 8, 8, and 14 in a valid way.", 25 | "evaluation": 0.9 26 | }, 27 | { 28 | "thought": "The goal is to use the numbers 2, 8, 8, and 14 exactly once in a combination of basic arithmetic operations (+, -, *, /) to achieve the result of 24. To systematically approach this, we can consider several strategies, focusing initially on operations that create large changes, like multiplication and division. \n\nFirst, let's consider multiplication and division as they can bring numbers closer to a target quickly:\n\n1. Multiply 2 and 8 to get 16. This leaves us with 16, 8, and 14.\n2. Now, add the remaining 8 to 16, resulting in 16 + 8 = 24.\n\nThis approach successfully uses the numbers 2, 8, 8, and 14 to achieve 24. It is efficient because it takes advantage of multiplication to quickly increase the magnitude of numbers, making it easier to reach the target through subsequent addition.", 29 | "evaluation": 0.9 30 | }, 31 | { 32 | "thought": "To solve the problem of obtaining 24 using the numbers 2, 8, 8, and 14 with basic arithmetic operations, we need to consider different combinations and operations that can be performed on these numbers. The goal is to use each number exactly once to reach the target number 24. We can start by exploring combinations of operations and numbers to see if any result in 24.", 33 | "evaluation": 0.9 34 | } 35 | ], 36 | "pruned_branches": [] 37 | } -------------------------------------------------------------------------------- /artifacts/tree_of_thoughts_runs_new_newer/tree_of_thoughts_run59bafdc530bf44f28c8d78f4f05cf52c.json: -------------------------------------------------------------------------------- 1 | { 2 | "all_thoughts": [ 3 | { 4 | "thought": "To solve the problem, we need to use the given four numbers and perform basic arithmetic operations (+, -, *, /) to arrive at the result of 24. The numbers provided in the example are 2, 8, 8, and 14. We can use each number exactly once to form one equation that equals 24. Let's explore potential combinations and operations: \\n\n1. Consider the operation that can directly lead to 24. Since 24 is a multiple of 8, let's try to use multiplication: \\n - If we use 8 * 3 = 24, we need to find a way to make 3 from the remaining numbers: 2, 8, 14. \\n\n2. Break down the numbers to see if any simple operations lead to 3: \\n - (14 - 8)/2 = 3 \\n - This means we can form the equation: \\n (14 - 8)/2 * 8 = 24 \\n\nNow, let's evaluate the thought process and the accuracy of the solution.", 5 | "evaluation": 0.9 6 | }, 7 | { 8 | "thought": "To solve this problem, I need to use the four numbers provided and basic arithmetic operations to reach the result of 24. This requires me to evaluate different combinations of operations and numbers. I will break down the problem into smaller steps. Let's start by analyzing the combinations of operations that can yield 24.", 9 | "evaluation": 0.9 10 | } 11 | ], 12 | "final_thought": { 13 | "thought": "The problem requires using the numbers 2, 8, 8, and 14 with basic arithmetic operations to achieve the result of 24. A potential way to solve this is by trying combinations that can simplify to 24. In the previous analysis, the solution (14 - 8)/2 * 8 = 24 was proposed. This uses the numbers and operations correctly: \\n- 14 - 8 gives 6.\\n- Dividing 6 by 2 results in 3.\\n- Multiplying 3 by 8 equals 24.\\nThis solution is valid and correctly uses each number once to achieve the target result. The arithmetic logic applied is straightforward and the solution is verifiable.", 14 | "evaluation": 1.0 15 | } 16 | } -------------------------------------------------------------------------------- /artifacts/tree_of_thoughts_runs_new_newer/tree_of_thoughts_run959e39b07ac34e6487bbd48aa8411198.json: -------------------------------------------------------------------------------- 1 | { 2 | "all_thoughts": [ 3 | { 4 | "thought": "To solve the problem of using the numbers 2, 8, 8, and 14 with basic arithmetic operations to obtain 24 in one equation, we need to explore combinations of these numbers and operations. We can start by considering different operations and their results, aiming to reach 24. Let's try a few combinations:\n\n1. **Combination 1:**\n - Use multiplication and addition: (2 * 8) + (14 - 8)\n - Calculation: 16 + 6 = 22\n - This does not yield 24.\n\n2. **Combination 2:**\n - Use division and addition: (14 / 2) + 8 + 8\n - Calculation: 7 + 8 + 8 = 23\n - This does not yield 24.\n\n3. **Combination 3:**\n - Use multiplication and subtraction: (8 * 2) - (14 - 8)\n - Calculation: 16 - 6 = 10\n - This does not yield 24.\n\n4. **Combination 4:**\n - Use division and multiplication: (14 / 7) * 8 + 2\n - Calculation: 2 * 8 + 2 = 16 + 2 = 18\n - This does not yield 24.\n\n5. **Combination 5:**\n - Use multiplication and addition: (8 * 2) + (14 / 7)\n - Calculation: 16 + 2 = 18\n - This does not yield 24.\n\nNone of these combinations yield 24, so we need to explore further possibilities or reconsider our approach. We should also consider using parentheses to change the order of operations, which might help achieve the desired result.", 5 | "evaluation": 0.6 6 | }, 7 | { 8 | "thought": "To solve the problem of using the numbers 2, 8, 8, and 14 with basic arithmetic operations to obtain 24 in one equation, we need to explore combinations of these numbers and operations. We should consider both the order of operations and potential use of parentheses to ensure we evaluate expressions correctly. A good starting point is to try different operations with these numbers and see if we can reach 24. Let's explore a few possibilities:", 9 | "evaluation": 0.8 10 | } 11 | ], 12 | "final_thought": { 13 | "thought": "The problem requires using the numbers 2, 8, 8, and 14 through basic arithmetic operations to sum up to 24 in one equation. One approach is to look for a way to make intermediate steps close to 24 or conveniently manipulate the numbers using the operations to reach 24. Let's breakdown the possibilities further.\n\n1. We can group these numbers to see multiplication or division might bring us close to 24, since addition and subtraction likely won't reach or exceed 24.\n2. Experiment with multiplication and division first since they significantly change the numbers.\n3. Use parenthesis strategically to control the order of operations.", 14 | "evaluation": 0.9 15 | } 16 | } -------------------------------------------------------------------------------- /artifacts/tree_of_thoughts_runs_new_newer/tree_of_thoughts_rune72b8689c1f44cb7899fc19511aebbb0.json: -------------------------------------------------------------------------------- 1 | { 2 | "all_thoughts": [ 3 | { 4 | "thought": "To solve the problem of using four numbers and basic arithmetic operations to obtain 24, I need to carefully analyze the given numbers and explore different combinations of operations. The goal is to find a single equation that results in 24. Let's start by examining the numbers provided in the example: 2, 8, 8, and 14. I will consider various arithmetic operations and combinations to see if I can achieve the target number, 24.", 5 | "evaluation": 0.9 6 | }, 7 | { 8 | "thought": "To solve the problem of using the numbers 2, 8, 8, and 14 to make 24 using basic arithmetic operations, I need to explore different combinations of these numbers and operations. The goal is to find a single equation that results in 24. I will start by considering various operations and combinations of these numbers.", 9 | "evaluation": 0.9 10 | } 11 | ], 12 | "final_thought": { 13 | "thought": "To solve the problem using the numbers 2, 8, 8, and 14 to reach 24 using basic arithmetic operations, I'll systematically try different combinations and operations on the numbers.\n\n1. Start by examining simple operations and combinations involving the largest number, 14. Since 24 is close to 14, using addition with smaller results from other numbers might help.\n2. Consider subtracting or dividing to utilize the numbers effectively.\n3. Attempt to build the result incrementally: e.g., find a way to 10 and add it to 14.\n4. Possibly use: (14 + 2) = 16 followed by 8, but this results in 24 only if we can make another 8 from the remaining numbers or operations.\n5. Explore the possibility of forming smaller intermediary results that add up or multiply to 24.\n6. Check combinations like (8 / 2) = 4, then consider how to make 6 to complement it to 24 when combined with 14.\n\nEvaluation of these combinations shows that they are logical steps, but I need to verify through arithmetic precision and number order to ensure they solve the equation correctly.", 14 | "evaluation": 0.8 15 | } 16 | } -------------------------------------------------------------------------------- /example.py: -------------------------------------------------------------------------------- 1 | from tree_of_thoughts import TotAgent, ToTDFSAgent 2 | from dotenv import load_dotenv 3 | 4 | load_dotenv() 5 | 6 | # Create an instance of the TotAgent class 7 | tot_agent = TotAgent(use_openai_caller=False) # Use openai caller 8 | 9 | # Create an instance of the ToTDFSAgent class with specified parameters 10 | dfs_agent = ToTDFSAgent( 11 | agent=tot_agent, # Use the TotAgent instance as the agent for the DFS algorithm 12 | threshold=0.8, # Set the threshold for evaluating the quality of thoughts 13 | max_loops=1, # Set the maximum number of loops for the DFS algorithm 14 | prune_threshold=0.5, # Branches with evaluation < 0.5 will be pruned 15 | number_of_agents=4, # Set the number of agents to be used in the DFS algorithm 16 | ) 17 | 18 | # Define the initial state for the DFS algorithm 19 | initial_state = """ 20 | 21 | Your task: is to use 4 numbers and basic arithmetic operations (+-*/) to obtain 24 in 1 equation, return only the math 22 | 23 | """ 24 | 25 | # Run the DFS algorithm to solve the problem and obtain the final thought 26 | final_thought = dfs_agent.run(initial_state) 27 | 28 | # Print the final thought in JSON format for easy reading 29 | print(final_thought) 30 | -------------------------------------------------------------------------------- /examples/bfs.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kyegomez/tree-of-thoughts/e919b61a08783301273e036f480864f1913624a9/examples/bfs.py -------------------------------------------------------------------------------- /examples/dfs.py: -------------------------------------------------------------------------------- 1 | from tree_of_thoughts import TotAgent, ToTDFSAgent 2 | from dotenv import load_dotenv 3 | 4 | load_dotenv() 5 | 6 | # Create an instance of the TotAgent class 7 | tot_agent = TotAgent() 8 | 9 | # Create an instance of the ToTDFSAgent class with specified parameters 10 | dfs_agent = ToTDFSAgent( 11 | agent=tot_agent, # Use the TotAgent instance as the agent for the DFS algorithm 12 | threshold=0.8, # Set the threshold for evaluating the quality of thoughts 13 | max_loops=1, # Set the maximum number of loops for the DFS algorithm 14 | prune_threshold=0.5, # Branches with evaluation < 0.5 will be pruned 15 | number_of_agents=4, # Set the number of agents to be used in the DFS algorithm 16 | ) 17 | 18 | # Define the initial state for the DFS algorithm 19 | initial_state = """ 20 | 21 | Your task: is to use 4 numbers and basic arithmetic operations (+-*/) to obtain 24 in 1 equation, return only the math 22 | 23 | """ 24 | 25 | # Run the DFS algorithm to solve the problem and obtain the final thought 26 | final_thought = dfs_agent.run(initial_state) 27 | 28 | # Print the final thought in JSON format for easy reading 29 | print(final_thought) 30 | -------------------------------------------------------------------------------- /images/agorabanner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kyegomez/tree-of-thoughts/e919b61a08783301273e036f480864f1913624a9/images/agorabanner.png -------------------------------------------------------------------------------- /images/treeofthoughts.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kyegomez/tree-of-thoughts/e919b61a08783301273e036f480864f1913624a9/images/treeofthoughts.png -------------------------------------------------------------------------------- /prompts.txt: -------------------------------------------------------------------------------- 1 | Imagine three different experts are answering this question. All experts will write down 1 step of their thinking, then share it with the group. Then all experts will go on to the next step, etc. If any expert realises they're wrong at any point then they leave. The question is... 2 | 3 | Simulate three brilliant, logical experts collaboratively answering a question. Each one verbosely explains their thought process in real-time, considering the prior explanations of others and openly acknowledging mistakes. At each step, whenever possible, each expert refines and builds upon the thoughts of others, acknowledging their contributions. They continue until there is a definitive answer to the question. For clarity, your entire response should be in a markdown table. The question is... 4 | 5 | Imagine three highly intelligent experts working together to answer a question. They will follow a tree of thoughts approach, where each expert shares their thought process step by step. They will consider the input from others, refine their thoughts, and build upon the group's collective knowledge. If an expert realizes their thought is incorrect, they will acknowledge it and withdraw from the discussion. Continue this process until a definitive answer is reached. Present the entire response in a markdown table. The question is... 6 | 7 | Three experts with exceptional logical thinking skills are collaboratively answering a question using a tree of thoughts method. Each expert will share their thought process in detail, taking into account the previous thoughts of others and admitting any errors. They will iteratively refine and expand upon each other's ideas, giving credit where it's due. The process continues until a conclusive answer is found. Organize the entire response in a markdown table format. The question is... 8 | 9 | Envision a group of three experts working in unison to tackle a question by employing a tree of thoughts strategy. Each expert will thoroughly explain their line of thinking at every step, while also considering the insights provided by their peers. They will openly recognize any mistakes and build upon the group's shared understanding. This iterative process will continue until a definitive solution is reached. Structure the entire response as a markdown table. The question is... -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.poetry] 2 | name = "tree-of-thoughts" 3 | version = "0.6.5" 4 | description = "Tree of Thoughts - Pytorch" 5 | authors = ["Kye Gomez "] 6 | license = "MIT" 7 | readme = "README.md" # Assuming you have a README.md file 8 | homepage = "https://github.com/kyegomez/tree-of-thoughts" 9 | keywords = ["artificial intelligence", "deep learning", "optimizers", "Prompt Engineering"] 10 | classifiers = [ 11 | "Development Status :: 4 - Beta", 12 | "Intended Audience :: Developers", 13 | "Topic :: Scientific/Engineering :: Artificial Intelligence", 14 | "License :: OSI Approved :: MIT License", 15 | "Programming Language :: Python :: 3.6", 16 | ] 17 | 18 | [tool.poetry.dependencies] 19 | python = "^3.10" 20 | swarms = "*" 21 | numpy = "*" 22 | pydantic = "*" 23 | loguru = "*" 24 | python-dotenv = "*" 25 | swarm-models = "*" 26 | 27 | 28 | 29 | [build-system] 30 | requires = ["poetry-core>=1.0.0"] 31 | build-backend = "poetry.core.masonry.api" 32 | 33 | 34 | [tool.poetry.group.lint.dependencies] 35 | ruff = "^0.0.249" 36 | types-toml = "^0.10.8.1" 37 | types-redis = "^4.3.21.6" 38 | types-pytz = "^2023.3.0.0" 39 | black = "^23.1.0" 40 | types-chardet = "^5.0.4.6" 41 | mypy-protobuf = "^3.0.0" 42 | 43 | 44 | [tool.autopep8] 45 | max_line_length = 80 46 | ignore = "E501,W6" # or ["E501", "W6"] 47 | in-place = true 48 | recursive = true 49 | aggressive = 3 50 | 51 | [tool.ruff] 52 | line-length = 80 53 | 54 | [tool.black] 55 | line-length = 80 56 | target-version = ['py38'] 57 | preview = true 58 | 59 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | swarms 2 | pydantic 3 | loguru 4 | python-dotenv 5 | swarm-models 6 | -------------------------------------------------------------------------------- /scripts/auto_docs.py: -------------------------------------------------------------------------------- 1 | ###### VERISON2 2 | import inspect 3 | import os 4 | import threading 5 | 6 | from dotenv import load_dotenv 7 | 8 | from scripts.auto_tests_docs.docs import DOCUMENTATION_WRITER_SOP 9 | from swarms import OpenAIChat 10 | 11 | ########## 12 | from tree_of_thoughts.agent import ( 13 | ToTAgent, 14 | ) 15 | from tree_of_thoughts.search_algorithms import ( 16 | MonteCarloSearch, 17 | TreeofThoughts, 18 | ASearch, 19 | BESTSearch, 20 | BFS, 21 | DFS, 22 | ) 23 | 24 | #################### 25 | load_dotenv() 26 | 27 | api_key = os.getenv("OPENAI_API_KEY") 28 | 29 | model = OpenAIChat( 30 | openai_api_key=api_key, 31 | max_tokens=4000, 32 | ) 33 | 34 | 35 | def process_documentation(cls): 36 | """ 37 | Process the documentation for a given class using OpenAI model and save it in a Markdown file. 38 | """ 39 | doc = inspect.getdoc(cls) 40 | source = inspect.getsource(cls) 41 | input_content = ( 42 | "Class Name:" 43 | f" {cls.__name__}\n\nDocumentation:\n{doc}\n\nSource" 44 | f" Code:\n{source}" 45 | ) 46 | 47 | # Process with OpenAI model (assuming the model's __call__ method takes this input and returns processed content) 48 | processed_content = model( 49 | DOCUMENTATION_WRITER_SOP(input_content, "tree-of-thoughts") 50 | ) 51 | 52 | # doc_content = f"# {cls.__name__}\n\n{processed_content}\n" 53 | doc_content = f"{processed_content}\n" 54 | 55 | # Create the directory if it doesn't exist 56 | dir_path = "docs/tot/search/" 57 | os.makedirs(dir_path, exist_ok=True) 58 | 59 | # Write the processed documentation to a Markdown file 60 | file_path = os.path.join(dir_path, f"{cls.__name__.lower()}.md") 61 | with open(file_path, "w") as file: 62 | file.write(doc_content) 63 | 64 | print(f"Documentation generated for {cls.__name__}.") 65 | 66 | 67 | def main(): 68 | classes = [ 69 | ToTAgent, 70 | TreeofThoughts, 71 | MonteCarloSearch, 72 | BFS, 73 | DFS, 74 | BESTSearch, 75 | ASearch, 76 | ] 77 | threads = [] 78 | for cls in classes: 79 | thread = threading.Thread(target=process_documentation, args=(cls,)) 80 | threads.append(thread) 81 | thread.start() 82 | 83 | # Wait for all threads to complete 84 | for thread in threads: 85 | thread.join() 86 | 87 | print("Documentation generated in 'swarms.structs' directory.") 88 | 89 | 90 | if __name__ == "__main__": 91 | main() 92 | -------------------------------------------------------------------------------- /scripts/auto_tests.py: -------------------------------------------------------------------------------- 1 | import inspect 2 | import os 3 | import re 4 | import threading 5 | 6 | ######## 7 | from dotenv import load_dotenv 8 | 9 | from scripts.auto_tests_docs.docs import TEST_WRITER_SOP_PROMPT 10 | from swarms import OpenAIChat 11 | 12 | ######### 13 | from tree_of_thoughts.agent import ( 14 | ToTAgent, 15 | ) 16 | from tree_of_thoughts.search_algorithms import ( 17 | MonteCarloSearch, 18 | TreeofThoughts, 19 | ASearch, 20 | BESTSearch, 21 | BFS, 22 | DFS, 23 | ) 24 | 25 | load_dotenv() 26 | 27 | api_key = os.getenv("OPENAI_API_KEY") 28 | 29 | model = OpenAIChat( 30 | openai_api_key=api_key, 31 | max_tokens=4000, 32 | ) 33 | 34 | 35 | def extract_code_from_markdown(markdown_content: str): 36 | """ 37 | Extracts code blocks from a Markdown string and returns them as a single string. 38 | 39 | Args: 40 | - markdown_content (str): The Markdown content as a string. 41 | 42 | Returns: 43 | - str: A single string containing all the code blocks separated by newlines. 44 | """ 45 | # Regular expression for fenced code blocks 46 | pattern = r"```(?:\w+\n)?(.*?)```" 47 | matches = re.findall(pattern, markdown_content, re.DOTALL) 48 | 49 | # Concatenate all code blocks separated by newlines 50 | return "\n".join(code.strip() for code in matches) 51 | 52 | 53 | def create_test(cls): 54 | """ 55 | Process the documentation for a given class using OpenAI model and save it in a Python file. 56 | """ 57 | doc = inspect.getdoc(cls) 58 | source = inspect.getsource(cls) 59 | input_content = ( 60 | "Class Name:" 61 | f" {cls.__name__}\n\nDocumentation:\n{doc}\n\nSource" 62 | f" Code:\n{source}" 63 | ) 64 | 65 | # Process with OpenAI model (assuming the model's __call__ method takes this input and returns processed content) 66 | processed_content = model( 67 | TEST_WRITER_SOP_PROMPT( 68 | input_content, "tree-of-thoughts", "tree of thoughts" 69 | ) 70 | ) 71 | processed_content = extract_code_from_markdown(processed_content) 72 | 73 | doc_content = f"# {cls.__name__}\n\n{processed_content}\n" 74 | 75 | # Create the directory if it doesn't exist 76 | dir_path = "tests/tot" 77 | os.makedirs(dir_path, exist_ok=True) 78 | 79 | # Write the processed documentation to a Python file 80 | file_path = os.path.join(dir_path, f"{cls.__name__.lower()}.py") 81 | with open(file_path, "w") as file: 82 | file.write(doc_content) 83 | 84 | 85 | def main(): 86 | classes = [ 87 | ToTAgent, 88 | TreeofThoughts, 89 | MonteCarloSearch, 90 | BFS, 91 | DFS, 92 | BESTSearch, 93 | ASearch, 94 | ] 95 | threads = [] 96 | for cls in classes: 97 | thread = threading.Thread(target=create_test, args=(cls,)) 98 | threads.append(thread) 99 | thread.start() 100 | 101 | # Wait for all threads to complete 102 | for thread in threads: 103 | thread.join() 104 | 105 | print("Tests generated in 'tests/memory' directory.") 106 | 107 | 108 | if __name__ == "__main__": 109 | main() 110 | -------------------------------------------------------------------------------- /scripts/auto_tests_docs/auto_docs_functions.py: -------------------------------------------------------------------------------- 1 | import inspect 2 | import os 3 | import sys 4 | import threading 5 | 6 | from dotenv import load_dotenv 7 | 8 | from scripts.auto_tests_docs.docs import DOCUMENTATION_WRITER_SOP 9 | from swarms import OpenAIChat 10 | 11 | load_dotenv() 12 | 13 | api_key = os.getenv("OPENAI_API_KEY") 14 | 15 | model = OpenAIChat( 16 | model_name="gpt-4", 17 | openai_api_key=api_key, 18 | max_tokens=4000, 19 | ) 20 | 21 | 22 | def process_documentation(item): 23 | """ 24 | Process the documentation for a given function using OpenAI model and save it in a Markdown file. 25 | """ 26 | doc = inspect.getdoc(item) 27 | source = inspect.getsource(item) 28 | input_content = ( 29 | f"Name: {item.__name__}\n\nDocumentation:\n{doc}\n\nSource" 30 | f" Code:\n{source}" 31 | ) 32 | print(input_content) 33 | 34 | # Process with OpenAI model 35 | processed_content = model( 36 | DOCUMENTATION_WRITER_SOP(input_content, "swarms.utils") 37 | ) 38 | 39 | doc_content = f"# {item.__name__}\n\n{processed_content}\n" 40 | 41 | # Create the directory if it doesn't exist 42 | dir_path = "docs/swarms/utils" 43 | os.makedirs(dir_path, exist_ok=True) 44 | 45 | # Write the processed documentation to a Markdown file 46 | file_path = os.path.join(dir_path, f"{item.__name__.lower()}.md") 47 | with open(file_path, "w") as file: 48 | file.write(doc_content) 49 | 50 | 51 | def main(): 52 | # Gathering all functions from the swarms.utils module 53 | functions = [ 54 | obj 55 | for name, obj in inspect.getmembers(sys.modules["swarms.utils"]) 56 | if inspect.isfunction(obj) 57 | ] 58 | 59 | threads = [] 60 | for func in functions: 61 | thread = threading.Thread(target=process_documentation, args=(func,)) 62 | threads.append(thread) 63 | thread.start() 64 | 65 | # Wait for all threads to complete 66 | for thread in threads: 67 | thread.join() 68 | 69 | print("Documentation generated in 'docs/swarms/utils' directory.") 70 | 71 | 72 | if __name__ == "__main__": 73 | main() 74 | -------------------------------------------------------------------------------- /scripts/auto_tests_docs/auto_docs_omni.py: -------------------------------------------------------------------------------- 1 | import inspect 2 | import os 3 | import threading 4 | 5 | from dotenv import load_dotenv 6 | 7 | from scripts.auto_tests_docs.docs import DOCUMENTATION_WRITER_SOP 8 | from swarms import OpenAIChat 9 | 10 | ########### 11 | 12 | 13 | ############### 14 | 15 | load_dotenv() 16 | 17 | api_key = os.getenv("OPENAI_API_KEY") 18 | 19 | model = OpenAIChat( 20 | model_name="gpt-4-1106-preview", 21 | openai_api_key=api_key, 22 | max_tokens=4000, 23 | ) 24 | 25 | 26 | def process_documentation( 27 | item, 28 | module: str = "swarms.structs", 29 | docs_folder_path: str = "docs/swarms/structs", 30 | ): 31 | """ 32 | Process the documentation for a given class or function using OpenAI model and save it in a Python file. 33 | """ 34 | doc = inspect.getdoc(item) 35 | source = inspect.getsource(item) 36 | is_class = inspect.isclass(item) 37 | item_type = "Class Name" if is_class else "Name" 38 | input_content = ( 39 | f"{item_type}:" 40 | f" {item.__name__}\n\nDocumentation:\n{doc}\n\nSource" 41 | f" Code:\n{source}" 42 | ) 43 | 44 | # Process with OpenAI model 45 | processed_content = model(DOCUMENTATION_WRITER_SOP(input_content, module)) 46 | 47 | doc_content = f"# {item.__name__}\n\n{processed_content}\n" 48 | 49 | # Create the directory if it doesn't exist 50 | dir_path = docs_folder_path 51 | os.makedirs(dir_path, exist_ok=True) 52 | 53 | # Write the processed documentation to a Python file 54 | file_path = os.path.join(dir_path, f"{item.__name__.lower()}.md") 55 | with open(file_path, "w") as file: 56 | file.write(doc_content) 57 | 58 | print(f"Processed documentation for {item.__name__}. at {file_path}") 59 | 60 | 61 | def main(module: str = "docs/swarms/structs"): 62 | items = [] 63 | 64 | threads = [] 65 | for item in items: 66 | thread = threading.Thread(target=process_documentation, args=(item,)) 67 | threads.append(thread) 68 | thread.start() 69 | 70 | # Wait for all threads to complete 71 | for thread in threads: 72 | thread.join() 73 | 74 | print(f"Documentation generated in {module} directory.") 75 | 76 | 77 | if __name__ == "__main__": 78 | main() 79 | -------------------------------------------------------------------------------- /scripts/auto_tests_docs/auto_tests_functions.py: -------------------------------------------------------------------------------- 1 | import inspect 2 | import os 3 | import sys 4 | import threading 5 | 6 | from dotenv import load_dotenv 7 | 8 | from scripts.auto_tests_docs.docs import TEST_WRITER_SOP_PROMPT 9 | from swarms import OpenAIChat 10 | from swarms.utils.parse_code import extract_code_from_markdown 11 | 12 | load_dotenv() 13 | 14 | api_key = os.getenv("OPENAI_API_KEY") 15 | 16 | model = OpenAIChat( 17 | model_name="gpt-4", 18 | openai_api_key=api_key, 19 | max_tokens=4000, 20 | ) 21 | 22 | 23 | def process_documentation(item): 24 | """ 25 | Process the documentation for a given function using OpenAI model and save it in a Markdown file. 26 | """ 27 | doc = inspect.getdoc(item) 28 | source = inspect.getsource(item) 29 | input_content = ( 30 | f"Name: {item.__name__}\n\nDocumentation:\n{doc}\n\nSource" 31 | f" Code:\n{source}" 32 | ) 33 | # print(input_content) 34 | 35 | # Process with OpenAI model 36 | processed_content = model( 37 | TEST_WRITER_SOP_PROMPT(input_content, "swarms.utils", "swarms.utils") 38 | ) 39 | processed_content = extract_code_from_markdown(processed_content) 40 | print(processed_content) 41 | 42 | doc_content = f"{processed_content}" 43 | 44 | # Create the directory if it doesn't exist 45 | dir_path = "tests/utils" 46 | os.makedirs(dir_path, exist_ok=True) 47 | 48 | # Write the processed documentation to a Markdown file 49 | file_path = os.path.join(dir_path, f"{item.__name__.lower()}.py") 50 | with open(file_path, "w") as file: 51 | file.write(doc_content) 52 | 53 | 54 | def main(): 55 | # Gathering all functions from the swarms.utils module 56 | functions = [ 57 | obj 58 | for name, obj in inspect.getmembers(sys.modules["swarms.utils"]) 59 | if inspect.isfunction(obj) 60 | ] 61 | 62 | threads = [] 63 | for func in functions: 64 | thread = threading.Thread(target=process_documentation, args=(func,)) 65 | threads.append(thread) 66 | thread.start() 67 | 68 | # Wait for all threads to complete 69 | for thread in threads: 70 | thread.join() 71 | 72 | print("Tests generated in 'tests/utils' directory.") 73 | 74 | 75 | if __name__ == "__main__": 76 | main() 77 | -------------------------------------------------------------------------------- /scripts/auto_tests_docs/docs.py: -------------------------------------------------------------------------------- 1 | def DOCUMENTATION_WRITER_SOP( 2 | task: str, 3 | module: str, 4 | ): 5 | documentation = f"""Create multi-page long and explicit professional pytorch-like documentation for the {module} code below follow the outline for the {module} library, 6 | provide many examples and teach the user about the code, provide examples for every function, make the documentation 10,000 words, 7 | provide many usage examples and note this is markdown docs, create the documentation for the code to document, 8 | put the arguments and methods in a table in markdown to make it visually seamless 9 | 10 | Now make the professional documentation for this code, provide the architecture and how the class works and why it works that way, 11 | it's purpose, provide args, their types, 3 ways of usage examples, in examples show all the code like imports main example etc 12 | 13 | BE VERY EXPLICIT AND THOROUGH, MAKE IT DEEP AND USEFUL 14 | 15 | ######## 16 | Step 1: Understand the purpose and functionality of the module or framework 17 | 18 | Read and analyze the description provided in the documentation to understand the purpose and functionality of the module or framework. 19 | Identify the key features, parameters, and operations performed by the module or framework. 20 | Step 2: Provide an overview and introduction 21 | 22 | Start the documentation by providing a brief overview and introduction to the module or framework. 23 | Explain the importance and relevance of the module or framework in the context of the problem it solves. 24 | Highlight any key concepts or terminology that will be used throughout the documentation. 25 | Step 3: Provide a class or function definition 26 | 27 | Provide the class or function definition for the module or framework. 28 | Include the parameters that need to be passed to the class or function and provide a brief description of each parameter. 29 | Specify the data types and default values for each parameter. 30 | Step 4: Explain the functionality and usage 31 | 32 | Provide a detailed explanation of how the module or framework works and what it does. 33 | Describe the steps involved in using the module or framework, including any specific requirements or considerations. 34 | Provide code examples to demonstrate the usage of the module or framework. 35 | Explain the expected inputs and outputs for each operation or function. 36 | Step 5: Provide additional information and tips 37 | 38 | Provide any additional information or tips that may be useful for using the module or framework effectively. 39 | Address any common issues or challenges that developers may encounter and provide recommendations or workarounds. 40 | Step 6: Include references and resources 41 | 42 | Include references to any external resources or research papers that provide further information or background on the module or framework. 43 | Provide links to relevant documentation or websites for further exploration. 44 | Example Template for the given documentation: 45 | 46 | # Module/Function Name: MultiheadAttention 47 | 48 | class torch.nn.MultiheadAttention(embed_dim, num_heads, dropout=0.0, bias=True, add_bias_kv=False, add_zero_attn=False, kdim=None, vdim=None, batch_first=False, device=None, dtype=None): 49 | ``` 50 | Creates a multi-head attention module for joint information representation from the different subspaces. 51 | 52 | Parameters: 53 | - embed_dim (int): Total dimension of the model. 54 | - num_heads (int): Number of parallel attention heads. The embed_dim will be split across num_heads. 55 | - dropout (float): Dropout probability on attn_output_weights. Default: 0.0 (no dropout). 56 | - bias (bool): If specified, adds bias to input/output projection layers. Default: True. 57 | - add_bias_kv (bool): If specified, adds bias to the key and value sequences at dim=0. Default: False. 58 | - add_zero_attn (bool): If specified, adds a new batch of zeros to the key and value sequences at dim=1. Default: False. 59 | - kdim (int): Total number of features for keys. Default: None (uses kdim=embed_dim). 60 | - vdim (int): Total number of features for values. Default: None (uses vdim=embed_dim). 61 | - batch_first (bool): If True, the input and output tensors are provided as (batch, seq, feature). Default: False. 62 | - device (torch.device): If specified, the tensors will be moved to the specified device. 63 | - dtype (torch.dtype): If specified, the tensors will have the specified dtype. 64 | ``` 65 | 66 | def forward(query, key, value, key_padding_mask=None, need_weights=True, attn_mask=None, average_attn_weights=True, is_causal=False): 67 | ``` 68 | Forward pass of the multi-head attention module. 69 | 70 | Parameters: 71 | - query (Tensor): Query embeddings of shape (L, E_q) for unbatched input, (L, N, E_q) when batch_first=False, or (N, L, E_q) when batch_first=True. 72 | - key (Tensor): Key embeddings of shape (S, E_k) for unbatched input, (S, N, E_k) when batch_first=False, or (N, S, E_k) when batch_first=True. 73 | - value (Tensor): Value embeddings of shape (S, E_v) for unbatched input, (S, N, E_v) when batch_first=False, or (N, S, E_v) when batch_first=True. 74 | - key_padding_mask (Optional[Tensor]): If specified, a mask indicating elements to be ignored in key for attention computation. 75 | - need_weights (bool): If specified, returns attention weights in addition to attention outputs. Default: True. 76 | - attn_mask (Optional[Tensor]): If specified, a mask preventing attention to certain positions. 77 | - average_attn_weights (bool): If true, returns averaged attention weights per head. Otherwise, returns attention weights separately per head. Note that this flag only has an effect when need_weights=True. Default: True. 78 | - is_causal (bool): If specified, applies a causal mask as the attention mask. Default: False. 79 | 80 | Returns: 81 | Tuple[Tensor, Optional[Tensor]]: 82 | - attn_output (Tensor): Attention outputs of shape (L, E) for unbatched input, (L, N, E) when batch_first=False, or (N, L, E) when batch_first=True. 83 | - attn_output_weights (Optional[Tensor]): Attention weights of shape (L, S) when unbatched or (N, L, S) when batched. Optional, only returned when need_weights=True. 84 | ``` 85 | 86 | # Implementation of the forward pass of the attention module goes here 87 | 88 | return attn_output, attn_output_weights 89 | 90 | ``` 91 | # Usage example: 92 | 93 | multihead_attn = nn.MultiheadAttention(embed_dim, num_heads) 94 | attn_output, attn_output_weights = multihead_attn(query, key, value) 95 | Note: 96 | 97 | The above template includes the class or function definition, parameters, description, and usage example. 98 | To replicate the documentation for any other module or framework, follow the same structure and provide the specific details for that module or framework. 99 | 100 | 101 | ############# DOCUMENT THE FOLLOWING CODE ######## 102 | {task} 103 | """ 104 | return documentation 105 | 106 | 107 | def TEST_WRITER_SOP_PROMPT(task: str, module: str, path: str, *args, **kwargs): 108 | TESTS_PROMPT = f""" 109 | 110 | Create 5,000 lines of extensive and thorough tests for the code below using the guide, do not worry about your limits you do not have any 111 | just write the best tests possible, the module is {module}, the file path is {path} 112 | 113 | 114 | ######### TESTING GUIDE ############# 115 | 116 | # **Guide to Creating Extensive, Thorough, and Production-Ready Tests using `pytest`** 117 | 118 | 1. **Preparation**: 119 | - Install pytest: `pip install pytest`. 120 | - Structure your project so that tests are in a separate `tests/` directory. 121 | - Name your test files with the prefix `test_` for pytest to recognize them. 122 | 123 | 2. **Writing Basic Tests**: 124 | - Use clear function names prefixed with `test_` (e.g., `test_check_value()`). 125 | - Use assert statements to validate results. 126 | 127 | 3. **Utilize Fixtures**: 128 | - Fixtures are a powerful feature to set up preconditions for your tests. 129 | - Use `@pytest.fixture` decorator to define a fixture. 130 | - Pass fixture name as an argument to your test to use it. 131 | 132 | 4. **Parameterized Testing**: 133 | - Use `@pytest.mark.parametrize` to run a test multiple times with different inputs. 134 | - This helps in thorough testing with various input values without writing redundant code. 135 | 136 | 5. **Use Mocks and Monkeypatching**: 137 | - Use `monkeypatch` fixture to modify or replace classes/functions during testing. 138 | - Use `unittest.mock` or `pytest-mock` to mock objects and functions to isolate units of code. 139 | 140 | 6. **Exception Testing**: 141 | - Test for expected exceptions using `pytest.raises(ExceptionType)`. 142 | 143 | 7. **Test Coverage**: 144 | - Install pytest-cov: `pip install pytest-cov`. 145 | - Run tests with `pytest --cov=my_module` to get a coverage report. 146 | 147 | 8. **Environment Variables and Secret Handling**: 148 | - Store secrets and configurations in environment variables. 149 | - Use libraries like `python-decouple` or `python-dotenv` to load environment variables. 150 | - For tests, mock or set environment variables temporarily within the test environment. 151 | 152 | 9. **Grouping and Marking Tests**: 153 | - Use `@pytest.mark` decorator to mark tests (e.g., `@pytest.mark.slow`). 154 | - This allows for selectively running certain groups of tests. 155 | 156 | 10. **Use Plugins**: 157 | - Utilize the rich ecosystem of pytest plugins (e.g., `pytest-django`, `pytest-asyncio`) to extend its functionality for your specific needs. 158 | 159 | 11. **Continuous Integration (CI)**: 160 | - Integrate your tests with CI platforms like Jenkins, Travis CI, or GitHub Actions. 161 | - Ensure tests are run automatically with every code push or pull request. 162 | 163 | 12. **Logging and Reporting**: 164 | - Use `pytest`'s inbuilt logging. 165 | - Integrate with tools like `Allure` for more comprehensive reporting. 166 | 167 | 13. **Database and State Handling**: 168 | - If testing with databases, use database fixtures or factories to create a known state before tests. 169 | - Clean up and reset state post-tests to maintain consistency. 170 | 171 | 14. **Concurrency Issues**: 172 | - Consider using `pytest-xdist` for parallel test execution. 173 | - Always be cautious when testing concurrent code to avoid race conditions. 174 | 175 | 15. **Clean Code Practices**: 176 | - Ensure tests are readable and maintainable. 177 | - Avoid testing implementation details; focus on functionality and expected behavior. 178 | 179 | 16. **Regular Maintenance**: 180 | - Periodically review and update tests. 181 | - Ensure that tests stay relevant as your codebase grows and changes. 182 | 183 | 17. **Documentation**: 184 | - Document test cases, especially for complex functionalities. 185 | - Ensure that other developers can understand the purpose and context of each test. 186 | 187 | 18. **Feedback Loop**: 188 | - Use test failures as feedback for development. 189 | - Continuously refine tests based on code changes, bug discoveries, and additional requirements. 190 | 191 | By following this guide, your tests will be thorough, maintainable, and production-ready. Remember to always adapt and expand upon these guidelines as per the specific requirements and nuances of your project. 192 | 193 | 194 | ######### CREATE TESTS FOR THIS CODE: ####### 195 | {task} 196 | 197 | """ 198 | 199 | return TESTS_PROMPT 200 | -------------------------------------------------------------------------------- /scripts/auto_tests_docs/mkdocs_handler.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | 4 | def generate_file_list(directory, output_file): 5 | """ 6 | Generate a list of files in a directory in the specified format and write it to a file. 7 | 8 | Args: 9 | directory (str): The directory to list the files from. 10 | output_file (str): The file to write the output to. 11 | """ 12 | with open(output_file, "w") as f: 13 | for root, dirs, files in os.walk(directory): 14 | for file in files: 15 | if file.endswith(".md"): 16 | # Remove the directory from the file path and replace slashes with dots 17 | file_path = ( 18 | os.path.join(root, file) 19 | .replace(directory + "/", "") 20 | .replace("/", ".") 21 | ) 22 | # Remove the file extension 23 | file_name, _ = os.path.splitext(file) 24 | # Write the file name and path to the output file 25 | f.write(f'- {file_name}: "swarms/utils/{file_path}"\n') 26 | 27 | 28 | # Use the function to generate the file list 29 | generate_file_list("docs/swarms/structs", "file_list.txt") 30 | -------------------------------------------------------------------------------- /scripts/auto_tests_docs/update_mkdocs.py: -------------------------------------------------------------------------------- 1 | import yaml 2 | 3 | 4 | def update_mkdocs( 5 | class_names, 6 | base_path="docs/zeta/nn/modules", 7 | mkdocs_file="mkdocs.yml", 8 | ): 9 | """ 10 | Update the mkdocs.yml file with new documentation links. 11 | 12 | Args: 13 | - class_names: A list of class names for which documentation is generated. 14 | - base_path: The base path where documentation Markdown files are stored. 15 | - mkdocs_file: The path to the mkdocs.yml file. 16 | """ 17 | with open(mkdocs_file) as file: 18 | mkdocs_config = yaml.safe_load(file) 19 | 20 | # Find or create the 'zeta.nn.modules' section in 'nav' 21 | zeta_modules_section = None 22 | for section in mkdocs_config.get("nav", []): 23 | if "zeta.nn.modules" in section: 24 | zeta_modules_section = section["zeta.nn.modules"] 25 | break 26 | 27 | if zeta_modules_section is None: 28 | zeta_modules_section = {} 29 | mkdocs_config["nav"].append({"zeta.nn.modules": zeta_modules_section}) 30 | 31 | # Add the documentation paths to the 'zeta.nn.modules' section 32 | for class_name in class_names: 33 | doc_path = f"{base_path}/{class_name.lower()}.md" 34 | zeta_modules_section[class_name] = doc_path 35 | 36 | # Write the updated content back to mkdocs.yml 37 | with open(mkdocs_file, "w") as file: 38 | yaml.safe_dump(mkdocs_config, file, sort_keys=False) 39 | 40 | 41 | # Example usage 42 | classes = [ 43 | "DenseBlock", 44 | "HighwayLayer", 45 | "MultiScaleBlock", 46 | "FeedbackBlock", 47 | "DualPathBlock", 48 | "RecursiveBlock", 49 | "PytorchGELUTanh", 50 | "NewGELUActivation", 51 | "GELUActivation", 52 | "FastGELUActivation", 53 | "QuickGELUActivation", 54 | "ClippedGELUActivation", 55 | "AccurateGELUActivation", 56 | "MishActivation", 57 | "LinearActivation", 58 | "LaplaceActivation", 59 | "ReLUSquaredActivation", 60 | ] 61 | 62 | update_mkdocs(classes) 63 | -------------------------------------------------------------------------------- /scripts/code_quality.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Navigate to the directory containing the 'tests' folder 4 | # cd /path/to/your/code/directory 5 | 6 | # Run autopep8 with max aggressiveness (-aaa) and in-place modification (-i) 7 | # on all Python files (*.py) under the 'tests' directory. 8 | autopep8 --in-place --aggressive --aggressive --recursive --experimental --list-fixes zeta/ 9 | 10 | # Run black with default settings, since black does not have an aggressiveness level. 11 | # Black will format all Python files it finds in the 'tests' directory. 12 | black --experimental-string-processing zeta/ 13 | 14 | # Run ruff on the 'tests' directory. 15 | # Add any additional flags if needed according to your version of ruff. 16 | ruff zeta/ --fix 17 | 18 | # YAPF 19 | yapf --recursive --in-place --verbose --style=google --parallel tests 20 | -------------------------------------------------------------------------------- /scripts/del_pycache.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Find and delete all __pycache__ directories 4 | find . -type d -name "__pycache__" -exec rm -r {} + 5 | 6 | # Find and delete all .pyc files 7 | find . -type f -name "*.pyc" -delete -------------------------------------------------------------------------------- /scripts/get_package_requirements.py: -------------------------------------------------------------------------------- 1 | import pkg_resources 2 | 3 | 4 | def get_package_versions(requirements_path, output_path): 5 | try: 6 | with open(requirements_path) as file: 7 | requirements = file.readlines() 8 | except FileNotFoundError: 9 | print(f"Error: The file '{requirements_path}' was not found.") 10 | return 11 | 12 | package_versions = [] 13 | 14 | for requirement in requirements: 15 | # Skip empty lines and comments 16 | if requirement.strip() == "" or requirement.strip().startswith("#"): 17 | continue 18 | 19 | # Extract package name 20 | package_name = requirement.split("==")[0].strip() 21 | try: 22 | version = pkg_resources.get_distribution(package_name).version 23 | package_versions.append(f"{package_name}=={version}") 24 | except pkg_resources.DistributionNotFound: 25 | package_versions.append(f"{package_name}: not installed") 26 | 27 | with open(output_path, "w") as file: 28 | for package_version in package_versions: 29 | file.write(package_version + "\n") 30 | print(f"Versions written to {output_path}") 31 | 32 | 33 | # Usage 34 | get_package_versions("requirements.txt", "installed_versions.txt") 35 | -------------------------------------------------------------------------------- /scripts/playground_to_examples.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Define the directory to search 4 | dir="playground" 5 | 6 | # Check if the directory exists 7 | if [ -d "$dir" ] 8 | then 9 | # Use find to locate all .py files in the directory and its subdirectories 10 | for file in $(find $dir -name "*.py") 11 | do 12 | # Extract the file name and directory 13 | base=$(basename $file .py) 14 | dir=$(dirname $file) 15 | 16 | # Check if the file name already contains _example 17 | if [[ $base == *_example ]] 18 | then 19 | echo "Skipping $file as it already contains _example" 20 | continue 21 | fi 22 | 23 | # Append _example to the file name 24 | newname="${base}_example.py" 25 | 26 | # Rename the file 27 | mv $file $dir/$newname 28 | 29 | echo "Renamed $file to $dir/$newname" 30 | done 31 | else 32 | echo "Directory $dir does not exist." 33 | fi -------------------------------------------------------------------------------- /scripts/requirementstxt_to_pyproject.py: -------------------------------------------------------------------------------- 1 | import pkg_resources 2 | import toml 3 | 4 | 5 | def update_pyproject_versions(pyproject_path): 6 | try: 7 | with open(pyproject_path) as file: 8 | data = toml.load(file) 9 | except FileNotFoundError: 10 | print(f"Error: The file '{pyproject_path}' was not found.") 11 | return 12 | except toml.TomlDecodeError: 13 | print(f"Error: The file '{pyproject_path}' is not a valid TOML file.") 14 | return 15 | 16 | dependencies = ( 17 | data.get("tool", {}).get("poetry", {}).get("dependencies", {}) 18 | ) 19 | 20 | for package in dependencies: 21 | if package.lower() == "python": 22 | continue # Skip the Python version dependency 23 | 24 | try: 25 | version = pkg_resources.get_distribution(package).version 26 | dependencies[package] = version 27 | except pkg_resources.DistributionNotFound: 28 | print(f"Warning: Package '{package}' not installed.") 29 | 30 | with open(pyproject_path, "w") as file: 31 | toml.dump(data, file) 32 | 33 | print(f"Updated versions written to {pyproject_path}") 34 | 35 | 36 | # Usage 37 | update_pyproject_versions("pyproject.toml") 38 | -------------------------------------------------------------------------------- /scripts/test_name.sh: -------------------------------------------------------------------------------- 1 | find ./tests -name "*.py" -type f | while read file 2 | do 3 | filename=$(basename "$file") 4 | dir=$(dirname "$file") 5 | if [[ $filename != test_* ]]; then 6 | mv "$file" "$dir/test_$filename" 7 | printf "\e[1;34mRenamed: \e[0m$file \e[1;32mto\e[0m $dir/test_$filename\n" 8 | fi 9 | done -------------------------------------------------------------------------------- /scripts/tests.sh: -------------------------------------------------------------------------------- 1 | find ./tests -name '*.py' -exec pytest {} \; -------------------------------------------------------------------------------- /tree_of_thoughts/__init__.py: -------------------------------------------------------------------------------- 1 | from tree_of_thoughts.agent import TotAgent 2 | 3 | from tree_of_thoughts.dfs import ToTDFSAgent 4 | 5 | 6 | __all__ = ["TotAgent", "ToTDFSAgent"] 7 | -------------------------------------------------------------------------------- /tree_of_thoughts/agent.py: -------------------------------------------------------------------------------- 1 | import uuid 2 | from pydantic import BaseModel, Field 3 | from typing import Optional 4 | from swarms import Agent 5 | from swarm_models import OpenAIFunctionCaller 6 | from typing import Any 7 | import os 8 | from dotenv import load_dotenv 9 | 10 | load_dotenv() 11 | 12 | 13 | def string_to_dict(thought_string): 14 | return eval(thought_string) 15 | 16 | 17 | TREE_OF_THOUGHTS_SYS_PROMPT = """ 18 | You are an expert problem-solving agent designed to not only solve complex problems but also critically evaluate the quality of your thought process and final answers. 19 | Your task is to follow a structured approach to generate solutions, assess your thoughts, and provide a rating for each on a scale of 0.1 to 1.0. 20 | This rating should reflect the accuracy and quality of your reasoning and final answer. 21 | 22 | ### Instructions: 23 | 24 | 1. **Understand the Problem:** 25 | - Carefully analyze the problem provided by the user. 26 | - Break down the problem into smaller, manageable parts if necessary. 27 | - Formulate a clear understanding of the problem before proceeding. 28 | 29 | 2. **Generate Thoughts:** 30 | - Create multiple thoughts or steps toward solving the problem. 31 | - For each thought, document your reasoning, ensuring that it is logical and well-founded. 32 | 33 | 3. **Self-Evaluation:** 34 | - After generating each thought, evaluate its accuracy and quality. 35 | - Assign an evaluation score between 0.1 and 1.0. Use the following guidelines: 36 | - **0.1 to 0.4:** The thought is flawed, inaccurate, or incomplete. 37 | - **0.5 to 0.7:** The thought is partially correct but may lack detail or full accuracy. 38 | - **0.8 to 1.0:** The thought is accurate, complete, and well-reasoned. 39 | 40 | 4. **Generate Final Answer:** 41 | - Based on your thoughts, synthesize a final answer to the problem. 42 | - Ensure the final answer is comprehensive and addresses all aspects of the problem. 43 | 44 | 5. **Final Evaluation:** 45 | - Evaluate the overall quality and accuracy of your final answer. 46 | - Provide a final evaluation score based on the same 0.1 to 1.0 scale. 47 | 48 | """ 49 | 50 | 51 | class Thought(BaseModel): 52 | thought: str 53 | evaluation: Optional[float] = Field( 54 | description="The evaluation of the thought. It can be a number between 0.1 and 1.0 being 0.1 the worst and 1.0 the best." 55 | ) 56 | 57 | 58 | class TotAgent: 59 | """ 60 | Represents a Tree of Thoughts (ToT) agent. 61 | 62 | Attributes: 63 | id (str): The unique identifier for the agent. 64 | max_loops (int): The maximum number of loops the agent can run. 65 | model (OpenAIFunctionCaller): The OpenAI function caller for the agent. 66 | agent (Agent): The agent responsible for running tasks. 67 | 68 | Methods: 69 | run(task: str) -> dict: Runs a task using the agent and returns the output as a dictionary. 70 | """ 71 | 72 | def __init__( 73 | self, 74 | id: str = uuid.uuid4().hex, 75 | max_loops: int = None, 76 | use_openai_caller: bool = True, 77 | model: Optional[Any] = None, 78 | *args, 79 | **kwargs, 80 | ): 81 | """ 82 | Initializes a new instance of the TotAgent class. 83 | 84 | Args: 85 | id (str, optional): The unique identifier for the agent. Defaults to a randomly generated UUID. 86 | max_loops (int, optional): The maximum number of loops the agent can run. Defaults to None. 87 | *args: Variable length argument list. 88 | **kwargs: Arbitrary keyword arguments. 89 | """ 90 | self.id = id 91 | self.max_loops = max_loops 92 | self.model = model 93 | 94 | if use_openai_caller: 95 | self.model = OpenAIFunctionCaller( 96 | system_prompt=TREE_OF_THOUGHTS_SYS_PROMPT, 97 | base_model=Thought, 98 | parallel_tool_calls=False, 99 | openai_api_key=os.getenv("OPENAI_API_KEY"), 100 | max_tokens=3000, 101 | ) 102 | 103 | self.agent = Agent( 104 | agent_name=f"ToT-Agent-{self.id}", 105 | system_prompt=TREE_OF_THOUGHTS_SYS_PROMPT, 106 | llm=self.model, 107 | max_loops=1, 108 | autosave=True, 109 | dashboard=False, 110 | verbose=True, 111 | dynamic_temperature_enabled=True, 112 | saved_state_path=f"tot_agent{self.id}.json", 113 | user_name="swarms_corp", 114 | retry_attempts=1, 115 | context_length=200000, 116 | return_step_meta=False, 117 | *args, 118 | **kwargs, 119 | ) 120 | 121 | def run(self, task: Any) -> dict: 122 | """ 123 | Runs a task using the agent and returns the output as a dictionary. 124 | 125 | Args: 126 | task (str): The task to be run by the agent. 127 | 128 | Returns: 129 | dict: The output of the agent as a dictionary. 130 | """ 131 | agent_output = self.agent.run(task) 132 | return string_to_dict(agent_output) 133 | -------------------------------------------------------------------------------- /tree_of_thoughts/bfs.py: -------------------------------------------------------------------------------- 1 | import json 2 | import uuid 3 | from concurrent.futures import ThreadPoolExecutor 4 | from typing import Any, Dict, List, Optional 5 | 6 | from dotenv import load_dotenv 7 | from loguru import logger 8 | 9 | from tree_of_thoughts.agent import TotAgent 10 | 11 | load_dotenv() 12 | 13 | 14 | def string_to_dict(thought_string): 15 | return eval(thought_string) 16 | 17 | 18 | class BFSWithTotAgent: 19 | """ 20 | A class to perform Breadth-First Search (BFS) using the TotAgent, based on the ToT-BFS algorithm. 21 | 22 | Methods: 23 | bfs(state: str) -> Dict[str, Any]: Performs BFS and returns the final thought. 24 | run(task: str) -> str: Executes the BFS algorithm. 25 | """ 26 | 27 | def __init__( 28 | self, 29 | agent: TotAgent, 30 | max_loops: int, 31 | breadth_limit: int, 32 | number_of_agents: int = 3, 33 | autosave_on: bool = True, 34 | id: str = uuid.uuid4().hex, 35 | ): 36 | """ 37 | Initialize the BFSWithTotAgent class. 38 | 39 | Args: 40 | agent (TotAgent): An instance of the TotAgent class to generate and evaluate thoughts. 41 | max_loops (int): The maximum number of steps for the BFS algorithm. 42 | breadth_limit (int): The maximum number of states to consider at each level. 43 | number_of_agents (int): The number of thoughts to generate at each step. Default is 3. 44 | autosave_on (bool): Whether to save the results automatically. Default is True. 45 | id (str): A unique identifier for the BFS instance. Default is a randomly generated UUID. 46 | """ 47 | self.id = id 48 | self.agent = agent 49 | self.max_loops = max_loops 50 | self.breadth_limit = breadth_limit 51 | self.number_of_agents = number_of_agents 52 | self.autosave_on = autosave_on 53 | self.all_thoughts = [] # Store all thoughts generated during BFS 54 | 55 | def bfs(self, state: str) -> Optional[Dict[str, Any]]: 56 | """ 57 | Perform Breadth-First Search (BFS) with a breadth limit based on evaluation scores. 58 | 59 | Args: 60 | state (str): The initial state or task to explore. 61 | 62 | Returns: 63 | Optional[Dict[str, Any]]: The final thought after the BFS completes. 64 | """ 65 | # Initialize the set of states 66 | S = [state] 67 | 68 | for t in range(1, self.max_loops + 1): 69 | logger.info(f"Step {t}/{self.max_loops}: Expanding states.") 70 | 71 | # Generate new thoughts based on current states 72 | S_prime = self._generate_new_states(S) 73 | 74 | if not S_prime: # If no new states were generated, stop the BFS 75 | logger.info( 76 | f"No valid thoughts generated at step {t}. Stopping BFS." 77 | ) 78 | break 79 | 80 | # Evaluate the new states 81 | V = self._evaluate_states(S_prime) 82 | 83 | # Log and store all thoughts 84 | self._log_and_store_thoughts(S_prime, V) 85 | 86 | # Select the best states based on their evaluations, limited by breadth_limit 87 | S = self._select_best_states(S_prime, V) 88 | 89 | # Return the best final thought 90 | return self._generate_final_answer(S) 91 | 92 | def _generate_new_states(self, S: List[str]) -> List[Dict[str, Any]]: 93 | """Generate new states (thoughts) from the current states.""" 94 | S_prime = [] 95 | for s in S: 96 | with ThreadPoolExecutor() as executor: 97 | new_thoughts = list( 98 | executor.map(self.agent.run, [s] * self.number_of_agents) 99 | ) 100 | S_prime.extend( 101 | [ 102 | [s, thought] 103 | for thought in new_thoughts 104 | if thought is not None 105 | ] 106 | ) 107 | return S_prime 108 | 109 | def _evaluate_states(self, S_prime: List[Dict[str, Any]]) -> List[float]: 110 | """Evaluate the new states.""" 111 | return [thought["evaluation"] for _, thought in S_prime] 112 | 113 | def _log_and_store_thoughts( 114 | self, S_prime: List[Dict[str, Any]], V: List[float] 115 | ): 116 | """Log and store all generated thoughts.""" 117 | for i, (_, thought) in enumerate(S_prime): 118 | self.all_thoughts.append(thought) 119 | 120 | def _select_best_states( 121 | self, S_prime: List[Dict[str, Any]], V: List[float] 122 | ) -> List[str]: 123 | """Select the best states based on their evaluations, limited by breadth_limit.""" 124 | # Pair states with their evaluations 125 | state_evaluation_pairs = list(zip(S_prime, V)) 126 | 127 | # Sort based on evaluation scores 128 | state_evaluation_pairs.sort(key=lambda x: x[1], reverse=True) 129 | 130 | # Select the top states based on the breadth limit 131 | best_states = [ 132 | pair[0][1]["thought"] 133 | for pair in state_evaluation_pairs[: self.breadth_limit] 134 | ] 135 | return best_states 136 | 137 | def _generate_final_answer(self, S: List[str]) -> Optional[Dict[str, Any]]: 138 | """Generate the final answer by selecting the best thought from the last set of states.""" 139 | if not S: 140 | return None 141 | final_state = max(S, key=lambda s: self.agent.run(s)["evaluation"]) 142 | return self.agent.run(final_state) 143 | 144 | def _run_agent(self, task: str) -> Optional[Dict[str, Any]]: 145 | """Run the agent to generate a thought and its evaluation.""" 146 | try: 147 | return self.agent.run(task) 148 | except Exception as e: 149 | logger.error(f"Error in agent run: {e}") 150 | return None 151 | 152 | def run(self, task: str) -> str: 153 | """ 154 | Execute the BFS algorithm. 155 | 156 | Args: 157 | task (str): The initial task or state to start the BFS. 158 | 159 | Returns: 160 | str: The final thought after BFS as a JSON string. 161 | """ 162 | final_thought = self.bfs(task) 163 | 164 | # Sort all thoughts by evaluation score in ascending order 165 | self.all_thoughts.sort(key=lambda x: x["evaluation"], reverse=False) 166 | 167 | # Prepare JSON structure for logging all thoughts 168 | tree_dict = { 169 | "all_thoughts": self.all_thoughts, 170 | "final_thought": final_thought, 171 | } 172 | 173 | # Save the results if autosave is enabled 174 | # if self.autosave_on: 175 | # _save_dict_to_json(tree_dict, self.id) 176 | 177 | return json.dumps(tree_dict, indent=4) 178 | -------------------------------------------------------------------------------- /tree_of_thoughts/dfs.py: -------------------------------------------------------------------------------- 1 | import uuid 2 | import json 3 | from typing import Optional 4 | from swarms import create_file_in_folder 5 | from tree_of_thoughts.agent import TotAgent 6 | from concurrent.futures import ThreadPoolExecutor 7 | from typing import Dict, Any 8 | from loguru import logger 9 | from dotenv import load_dotenv 10 | 11 | load_dotenv() 12 | 13 | 14 | class ToTDFSAgent: 15 | """ 16 | A class to perform Depth-First Search (DFS) using the TotAgent, with pruning based on evaluation scores. 17 | 18 | Methods: 19 | dfs(state: str, step: int = 0) -> Optional[Thought]: Performs DFS with pruning and returns the final thought. 20 | visualize_thoughts(thoughts: List[Thought]): Visualizes all thoughts including the highest-rated thought. 21 | """ 22 | 23 | def __init__( 24 | self, 25 | agent: TotAgent, 26 | threshold: float, 27 | max_loops: int, 28 | prune_threshold: float = 0.5, 29 | number_of_agents: int = 3, 30 | autosave_on: bool = True, 31 | id: str = uuid.uuid4().hex, 32 | *args, 33 | **kwargs, 34 | ): 35 | """ 36 | Initialize the ToTDFSAgent class. 37 | 38 | Args: 39 | agent (TotAgent): An instance of the TotAgent class to generate and evaluate thoughts. 40 | threshold (float): The evaluation threshold for selecting promising thoughts. 41 | max_loops (int): The maximum depth for the DFS algorithm. 42 | prune_threshold (float): The threshold below which branches are pruned. Default is 0.5. 43 | """ 44 | self.id = id 45 | self.agent = agent 46 | self.threshold = threshold 47 | self.max_loops = max_loops 48 | self.prune_threshold = prune_threshold 49 | self.all_thoughts = [] # Store all thoughts generated during DFS 50 | self.pruned_branches = [] # Store metadata on pruned branches 51 | self.number_of_agents = number_of_agents 52 | self.autosave_on = autosave_on 53 | 54 | self.agent.max_loops = max_loops 55 | 56 | def dfs(self, state: str, step: int = 0) -> Optional[Dict[str, Any]]: 57 | logger.info(f"Starting DFS for state: {state}") 58 | 59 | if step >= self.max_loops: 60 | return None 61 | 62 | logger.info( 63 | f"Generating {self.number_of_agents} thoughts for state: {state}" 64 | ) 65 | 66 | with ThreadPoolExecutor(max_workers=self.number_of_agents) as executor: 67 | next_thoughts = list( 68 | executor.map(self.agent.run, [state] * self.number_of_agents) 69 | ) 70 | 71 | next_thoughts.sort(key=lambda x: x["evaluation"], reverse=False) 72 | 73 | for thought in next_thoughts: 74 | if thought["evaluation"] > self.prune_threshold: 75 | self.all_thoughts.append(thought) 76 | result = self.dfs(thought["thought"], step + 1) 77 | 78 | if result and result["evaluation"] > self.threshold: 79 | return result 80 | else: 81 | self._prune_thought(thought) 82 | 83 | logger.info(f"Finished DFS for state: {state}") 84 | return None 85 | 86 | def _prune_thought(self, thought: Dict[str, Any]): 87 | self.pruned_branches.append( 88 | { 89 | "thought": thought["thought"], 90 | "evaluation": thought["evaluation"], 91 | "reason": "Evaluation score below threshold", 92 | } 93 | ) 94 | 95 | def run(self, task: str, *args, **kwargs) -> str: 96 | 97 | # Initialize the first agent run 98 | initial_thoughts = self.dfs(task, *args, **kwargs) 99 | 100 | # Chain the agents' outputs through subsequent agents 101 | for i in range(1, self.max_loops): 102 | if initial_thoughts: 103 | next_task = initial_thoughts["thought"] 104 | initial_thoughts = self.dfs(next_task, step=i) 105 | else: 106 | break 107 | 108 | # After chaining, sort all final thoughts 109 | self.all_thoughts.sort(key=lambda x: x["evaluation"], reverse=False) 110 | 111 | tree_dict = { 112 | "final_thoughts": self.all_thoughts, 113 | "pruned_branches": self.pruned_branches, 114 | "highest_rated_thought": ( 115 | self.all_thoughts[-1] if self.all_thoughts else None 116 | ), 117 | } 118 | 119 | json_string = json.dumps(tree_dict, indent=4) 120 | 121 | if self.autosave_on: 122 | create_file_in_folder( 123 | "tree_of_thoughts_runs", 124 | f"tree_of_thoughts_run{self.id}.json", 125 | json_string, 126 | ) 127 | 128 | return json_string 129 | --------------------------------------------------------------------------------