diff --git a/.gitignore b/.gitignore index 4fbcf9ec..780d95ae 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,8 @@ Devin_state.json json_logs Medical Image Diagnostic Agent_state.json D_state.json +artifacts_six +artifacts_seven swarms/__pycache__ artifacts transcript_generator.json diff --git a/playground/demos/evelyn_swarmathon_submission/Swarmshackathon2024.ipynb b/playground/demos/evelyn_swarmathon_submission/Swarmshackathon2024.ipynb new file mode 100644 index 00000000..303f7978 --- /dev/null +++ b/playground/demos/evelyn_swarmathon_submission/Swarmshackathon2024.ipynb @@ -0,0 +1,999 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "provenance": [], + "machine_shape": "hm", + "gpuType": "L4" + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + }, + "accelerator": "GPU" + }, + "cells": [ + { + "cell_type": "markdown", + "source": [ + "# Entry for SwarmsHackathon 2024\n", + "\n" + ], + "metadata": { + "id": "Qf8eZIT71wba" + } + }, + { + "cell_type": "markdown", + "source": [ + "## Install Swarms" + ], + "metadata": { + "id": "-rBXNMWV4EWN" + } + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "id": "w4FoSEyP1q_x", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "outputId": "ea6b15e7-c53c-47aa-86c6-b24d4aff041b" + }, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Collecting swarms\n", + " Downloading swarms-5.1.4-py3-none-any.whl (338 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m339.0/339.0 kB\u001b[0m \u001b[31m6.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hCollecting Pillow==10.3.0 (from swarms)\n", + " Downloading pillow-10.3.0-cp310-cp310-manylinux_2_28_x86_64.whl (4.5 MB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m4.5/4.5 MB\u001b[0m \u001b[31m62.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hRequirement already satisfied: PyYAML in /usr/local/lib/python3.10/dist-packages (from swarms) (6.0.1)\n", + "Collecting asyncio<4.0,>=3.4.3 (from swarms)\n", + " Downloading asyncio-3.4.3-py3-none-any.whl (101 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m101.8/101.8 kB\u001b[0m \u001b[31m12.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hCollecting backoff==2.2.1 (from swarms)\n", + " Downloading backoff-2.2.1-py3-none-any.whl (15 kB)\n", + "Requirement already satisfied: docstring_parser==0.16 in /usr/local/lib/python3.10/dist-packages (from swarms) (0.16)\n", + "Collecting langchain-community==0.0.29 (from swarms)\n", + " Downloading langchain_community-0.0.29-py3-none-any.whl (1.8 MB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.8/1.8 MB\u001b[0m \u001b[31m78.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hCollecting langchain-experimental==0.0.55 (from swarms)\n", + " Downloading langchain_experimental-0.0.55-py3-none-any.whl (177 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m177.6/177.6 kB\u001b[0m \u001b[31m21.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hCollecting loguru==0.7.2 (from swarms)\n", + " Downloading loguru-0.7.2-py3-none-any.whl (62 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m62.5/62.5 kB\u001b[0m \u001b[31m8.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hRequirement already satisfied: opencv-python-headless in /usr/local/lib/python3.10/dist-packages (from swarms) (4.9.0.80)\n", + "Requirement already satisfied: psutil in /usr/local/lib/python3.10/dist-packages (from swarms) (5.9.5)\n", + "Requirement already satisfied: pydantic==2.7.1 in /usr/local/lib/python3.10/dist-packages (from swarms) (2.7.1)\n", + "Collecting pypdf==4.1.0 (from swarms)\n", + " Downloading pypdf-4.1.0-py3-none-any.whl (286 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m286.1/286.1 kB\u001b[0m \u001b[31m31.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hCollecting python-dotenv (from swarms)\n", + " Downloading python_dotenv-1.0.1-py3-none-any.whl (19 kB)\n", + "Collecting ratelimit==2.2.1 (from swarms)\n", + " Downloading ratelimit-2.2.1.tar.gz (5.3 kB)\n", + " Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n", + "Collecting sentry-sdk (from swarms)\n", + " Downloading sentry_sdk-2.3.1-py2.py3-none-any.whl (289 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m289.0/289.0 kB\u001b[0m \u001b[31m27.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hRequirement already satisfied: tenacity==8.3.0 in /usr/local/lib/python3.10/dist-packages (from swarms) (8.3.0)\n", + "Requirement already satisfied: toml in /usr/local/lib/python3.10/dist-packages (from swarms) (0.10.2)\n", + "Requirement already satisfied: torch<3.0,>=2.1.1 in /usr/local/lib/python3.10/dist-packages (from swarms) (2.3.0+cu121)\n", + "Requirement already satisfied: transformers<5.0.0,>=4.39.0 in /usr/local/lib/python3.10/dist-packages (from swarms) (4.41.1)\n", + "Requirement already satisfied: SQLAlchemy<3,>=1.4 in /usr/local/lib/python3.10/dist-packages (from langchain-community==0.0.29->swarms) (2.0.30)\n", + "Requirement already satisfied: aiohttp<4.0.0,>=3.8.3 in /usr/local/lib/python3.10/dist-packages (from langchain-community==0.0.29->swarms) (3.9.5)\n", + "Collecting dataclasses-json<0.7,>=0.5.7 (from langchain-community==0.0.29->swarms)\n", + " Downloading dataclasses_json-0.6.6-py3-none-any.whl (28 kB)\n", + "Collecting langchain-core<0.2.0,>=0.1.33 (from langchain-community==0.0.29->swarms)\n", + " Downloading langchain_core-0.1.52-py3-none-any.whl (302 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m302.9/302.9 kB\u001b[0m \u001b[31m32.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hCollecting langsmith<0.2.0,>=0.1.0 (from langchain-community==0.0.29->swarms)\n", + " Downloading langsmith-0.1.67-py3-none-any.whl (124 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m124.4/124.4 kB\u001b[0m \u001b[31m13.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hRequirement already satisfied: numpy<2,>=1 in /usr/local/lib/python3.10/dist-packages (from langchain-community==0.0.29->swarms) (1.25.2)\n", + "Requirement already satisfied: requests<3,>=2 in /usr/local/lib/python3.10/dist-packages (from langchain-community==0.0.29->swarms) (2.31.0)\n", + "Collecting langchain<0.2.0,>=0.1.13 (from langchain-experimental==0.0.55->swarms)\n", + " Downloading langchain-0.1.20-py3-none-any.whl (1.0 MB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.0/1.0 MB\u001b[0m \u001b[31m54.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hRequirement already satisfied: annotated-types>=0.4.0 in /usr/local/lib/python3.10/dist-packages (from pydantic==2.7.1->swarms) (0.7.0)\n", + "Requirement already satisfied: pydantic-core==2.18.2 in /usr/local/lib/python3.10/dist-packages (from pydantic==2.7.1->swarms) (2.18.2)\n", + "Requirement already satisfied: typing-extensions>=4.6.1 in /usr/local/lib/python3.10/dist-packages (from pydantic==2.7.1->swarms) (4.11.0)\n", + "Requirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from torch<3.0,>=2.1.1->swarms) (3.14.0)\n", + "Requirement already satisfied: sympy in /usr/local/lib/python3.10/dist-packages (from torch<3.0,>=2.1.1->swarms) (1.12)\n", + "Requirement already satisfied: networkx in /usr/local/lib/python3.10/dist-packages (from torch<3.0,>=2.1.1->swarms) (3.3)\n", + "Requirement already satisfied: jinja2 in /usr/local/lib/python3.10/dist-packages (from torch<3.0,>=2.1.1->swarms) (3.1.4)\n", + "Requirement already satisfied: fsspec in /usr/local/lib/python3.10/dist-packages (from torch<3.0,>=2.1.1->swarms) (2023.6.0)\n", + "Collecting nvidia-cuda-nvrtc-cu12==12.1.105 (from torch<3.0,>=2.1.1->swarms)\n", + " Using cached nvidia_cuda_nvrtc_cu12-12.1.105-py3-none-manylinux1_x86_64.whl (23.7 MB)\n", + "Collecting nvidia-cuda-runtime-cu12==12.1.105 (from torch<3.0,>=2.1.1->swarms)\n", + " Using cached nvidia_cuda_runtime_cu12-12.1.105-py3-none-manylinux1_x86_64.whl (823 kB)\n", + "Collecting nvidia-cuda-cupti-cu12==12.1.105 (from torch<3.0,>=2.1.1->swarms)\n", + " Using cached nvidia_cuda_cupti_cu12-12.1.105-py3-none-manylinux1_x86_64.whl (14.1 MB)\n", + "Collecting nvidia-cudnn-cu12==8.9.2.26 (from torch<3.0,>=2.1.1->swarms)\n", + " Using cached nvidia_cudnn_cu12-8.9.2.26-py3-none-manylinux1_x86_64.whl (731.7 MB)\n", + "Collecting nvidia-cublas-cu12==12.1.3.1 (from torch<3.0,>=2.1.1->swarms)\n", + " Using cached nvidia_cublas_cu12-12.1.3.1-py3-none-manylinux1_x86_64.whl (410.6 MB)\n", + "Collecting nvidia-cufft-cu12==11.0.2.54 (from torch<3.0,>=2.1.1->swarms)\n", + " Using cached nvidia_cufft_cu12-11.0.2.54-py3-none-manylinux1_x86_64.whl (121.6 MB)\n", + "Collecting nvidia-curand-cu12==10.3.2.106 (from torch<3.0,>=2.1.1->swarms)\n", + " Using cached nvidia_curand_cu12-10.3.2.106-py3-none-manylinux1_x86_64.whl (56.5 MB)\n", + "Collecting nvidia-cusolver-cu12==11.4.5.107 (from torch<3.0,>=2.1.1->swarms)\n", + " Using cached nvidia_cusolver_cu12-11.4.5.107-py3-none-manylinux1_x86_64.whl (124.2 MB)\n", + "Collecting nvidia-cusparse-cu12==12.1.0.106 (from torch<3.0,>=2.1.1->swarms)\n", + " Using cached nvidia_cusparse_cu12-12.1.0.106-py3-none-manylinux1_x86_64.whl (196.0 MB)\n", + "Collecting nvidia-nccl-cu12==2.20.5 (from torch<3.0,>=2.1.1->swarms)\n", + " Using cached nvidia_nccl_cu12-2.20.5-py3-none-manylinux2014_x86_64.whl (176.2 MB)\n", + "Collecting nvidia-nvtx-cu12==12.1.105 (from torch<3.0,>=2.1.1->swarms)\n", + " Using cached nvidia_nvtx_cu12-12.1.105-py3-none-manylinux1_x86_64.whl (99 kB)\n", + "Requirement already satisfied: triton==2.3.0 in /usr/local/lib/python3.10/dist-packages (from torch<3.0,>=2.1.1->swarms) (2.3.0)\n", + "Collecting nvidia-nvjitlink-cu12 (from nvidia-cusolver-cu12==11.4.5.107->torch<3.0,>=2.1.1->swarms)\n", + " Downloading nvidia_nvjitlink_cu12-12.5.40-py3-none-manylinux2014_x86_64.whl (21.3 MB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m21.3/21.3 MB\u001b[0m \u001b[31m73.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hRequirement already satisfied: huggingface-hub<1.0,>=0.23.0 in /usr/local/lib/python3.10/dist-packages (from transformers<5.0.0,>=4.39.0->swarms) (0.23.1)\n", + "Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.10/dist-packages (from transformers<5.0.0,>=4.39.0->swarms) (24.0)\n", + "Requirement already satisfied: regex!=2019.12.17 in /usr/local/lib/python3.10/dist-packages (from transformers<5.0.0,>=4.39.0->swarms) (2024.5.15)\n", + "Requirement already satisfied: tokenizers<0.20,>=0.19 in /usr/local/lib/python3.10/dist-packages (from transformers<5.0.0,>=4.39.0->swarms) (0.19.1)\n", + "Requirement already satisfied: safetensors>=0.4.1 in /usr/local/lib/python3.10/dist-packages (from transformers<5.0.0,>=4.39.0->swarms) (0.4.3)\n", + "Requirement already satisfied: tqdm>=4.27 in /usr/local/lib/python3.10/dist-packages (from transformers<5.0.0,>=4.39.0->swarms) (4.66.4)\n", + "Requirement already satisfied: urllib3>=1.26.11 in /usr/local/lib/python3.10/dist-packages (from sentry-sdk->swarms) (2.0.7)\n", + "Requirement already satisfied: certifi in /usr/local/lib/python3.10/dist-packages (from sentry-sdk->swarms) (2024.2.2)\n", + "Requirement already satisfied: aiosignal>=1.1.2 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.3->langchain-community==0.0.29->swarms) (1.3.1)\n", + "Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.3->langchain-community==0.0.29->swarms) (23.2.0)\n", + "Requirement already satisfied: frozenlist>=1.1.1 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.3->langchain-community==0.0.29->swarms) (1.4.1)\n", + "Requirement already satisfied: multidict<7.0,>=4.5 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.3->langchain-community==0.0.29->swarms) (6.0.5)\n", + "Requirement already satisfied: yarl<2.0,>=1.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.3->langchain-community==0.0.29->swarms) (1.9.4)\n", + "Requirement already satisfied: async-timeout<5.0,>=4.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.3->langchain-community==0.0.29->swarms) (4.0.3)\n", + "Collecting marshmallow<4.0.0,>=3.18.0 (from dataclasses-json<0.7,>=0.5.7->langchain-community==0.0.29->swarms)\n", + " Downloading marshmallow-3.21.2-py3-none-any.whl (49 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m49.3/49.3 kB\u001b[0m \u001b[31m7.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hCollecting typing-inspect<1,>=0.4.0 (from dataclasses-json<0.7,>=0.5.7->langchain-community==0.0.29->swarms)\n", + " Downloading typing_inspect-0.9.0-py3-none-any.whl (8.8 kB)\n", + "INFO: pip is looking at multiple versions of langchain to determine which version is compatible with other requirements. This could take a while.\n", + "Collecting langchain<0.2.0,>=0.1.13 (from langchain-experimental==0.0.55->swarms)\n", + " Downloading langchain-0.1.19-py3-none-any.whl (1.0 MB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.0/1.0 MB\u001b[0m \u001b[31m75.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25h Downloading langchain-0.1.17-py3-none-any.whl (867 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m867.6/867.6 kB\u001b[0m \u001b[31m72.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hCollecting jsonpatch<2.0,>=1.33 (from langchain<0.2.0,>=0.1.13->langchain-experimental==0.0.55->swarms)\n", + " Downloading jsonpatch-1.33-py2.py3-none-any.whl (12 kB)\n", + "Collecting langchain<0.2.0,>=0.1.13 (from langchain-experimental==0.0.55->swarms)\n", + " Downloading langchain-0.1.16-py3-none-any.whl (817 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m817.7/817.7 kB\u001b[0m \u001b[31m71.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25h Downloading langchain-0.1.15-py3-none-any.whl (814 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m814.5/814.5 kB\u001b[0m \u001b[31m71.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25h Downloading langchain-0.1.14-py3-none-any.whl (812 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m812.8/812.8 kB\u001b[0m \u001b[31m70.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25h Downloading langchain-0.1.13-py3-none-any.whl (810 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m810.5/810.5 kB\u001b[0m \u001b[31m72.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hCollecting langchain-text-splitters<0.1,>=0.0.1 (from langchain<0.2.0,>=0.1.13->langchain-experimental==0.0.55->swarms)\n", + " Downloading langchain_text_splitters-0.0.2-py3-none-any.whl (23 kB)\n", + "Collecting packaging>=20.0 (from transformers<5.0.0,>=4.39.0->swarms)\n", + " Downloading packaging-23.2-py3-none-any.whl (53 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m53.0/53.0 kB\u001b[0m \u001b[31m9.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hCollecting orjson<4.0.0,>=3.9.14 (from langsmith<0.2.0,>=0.1.0->langchain-community==0.0.29->swarms)\n", + " Downloading orjson-3.10.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (142 kB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m142.5/142.5 kB\u001b[0m \u001b[31m22.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hRequirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests<3,>=2->langchain-community==0.0.29->swarms) (3.3.2)\n", + "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests<3,>=2->langchain-community==0.0.29->swarms) (3.7)\n", + "Requirement already satisfied: greenlet!=0.4.17 in /usr/local/lib/python3.10/dist-packages (from SQLAlchemy<3,>=1.4->langchain-community==0.0.29->swarms) (3.0.3)\n", + "Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.10/dist-packages (from jinja2->torch<3.0,>=2.1.1->swarms) (2.1.5)\n", + "Requirement already satisfied: mpmath>=0.19 in /usr/local/lib/python3.10/dist-packages (from sympy->torch<3.0,>=2.1.1->swarms) (1.3.0)\n", + "Collecting jsonpointer>=1.9 (from jsonpatch<2.0,>=1.33->langchain<0.2.0,>=0.1.13->langchain-experimental==0.0.55->swarms)\n", + " Downloading jsonpointer-2.4-py2.py3-none-any.whl (7.8 kB)\n", + "Collecting mypy-extensions>=0.3.0 (from typing-inspect<1,>=0.4.0->dataclasses-json<0.7,>=0.5.7->langchain-community==0.0.29->swarms)\n", + " Downloading mypy_extensions-1.0.0-py3-none-any.whl (4.7 kB)\n", + "Building wheels for collected packages: ratelimit\n", + " Building wheel for ratelimit (setup.py) ... \u001b[?25l\u001b[?25hdone\n", + " Created wheel for ratelimit: filename=ratelimit-2.2.1-py3-none-any.whl size=5894 sha256=838835c704600f0f2b8beedf91668c9e47611d580106e773d26fb091a4ad01e0\n", + " Stored in directory: /root/.cache/pip/wheels/27/5f/ba/e972a56dcbf5de9f2b7d2b2a710113970bd173c4dcd3d2c902\n", + "Successfully built ratelimit\n", + "Installing collected packages: ratelimit, asyncio, sentry-sdk, python-dotenv, pypdf, Pillow, packaging, orjson, nvidia-nvtx-cu12, nvidia-nvjitlink-cu12, nvidia-nccl-cu12, nvidia-curand-cu12, nvidia-cufft-cu12, nvidia-cuda-runtime-cu12, nvidia-cuda-nvrtc-cu12, nvidia-cuda-cupti-cu12, nvidia-cublas-cu12, mypy-extensions, loguru, jsonpointer, backoff, typing-inspect, nvidia-cusparse-cu12, nvidia-cudnn-cu12, marshmallow, jsonpatch, nvidia-cusolver-cu12, langsmith, dataclasses-json, langchain-core, langchain-text-splitters, langchain-community, langchain, langchain-experimental, swarms\n", + " Attempting uninstall: Pillow\n", + " Found existing installation: Pillow 9.4.0\n", + " Uninstalling Pillow-9.4.0:\n", + " Successfully uninstalled Pillow-9.4.0\n", + " Attempting uninstall: packaging\n", + " Found existing installation: packaging 24.0\n", + " Uninstalling packaging-24.0:\n", + " Successfully uninstalled packaging-24.0\n", + "\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n", + "imageio 2.31.6 requires pillow<10.1.0,>=8.3.2, but you have pillow 10.3.0 which is incompatible.\u001b[0m\u001b[31m\n", + "\u001b[0mSuccessfully installed Pillow-10.3.0 asyncio-3.4.3 backoff-2.2.1 dataclasses-json-0.6.6 jsonpatch-1.33 jsonpointer-2.4 langchain-0.1.13 langchain-community-0.0.29 langchain-core-0.1.52 langchain-experimental-0.0.55 langchain-text-splitters-0.0.2 langsmith-0.1.67 loguru-0.7.2 marshmallow-3.21.2 mypy-extensions-1.0.0 nvidia-cublas-cu12-12.1.3.1 nvidia-cuda-cupti-cu12-12.1.105 nvidia-cuda-nvrtc-cu12-12.1.105 nvidia-cuda-runtime-cu12-12.1.105 nvidia-cudnn-cu12-8.9.2.26 nvidia-cufft-cu12-11.0.2.54 nvidia-curand-cu12-10.3.2.106 nvidia-cusolver-cu12-11.4.5.107 nvidia-cusparse-cu12-12.1.0.106 nvidia-nccl-cu12-2.20.5 nvidia-nvjitlink-cu12-12.5.40 nvidia-nvtx-cu12-12.1.105 orjson-3.10.3 packaging-23.2 pypdf-4.1.0 python-dotenv-1.0.1 ratelimit-2.2.1 sentry-sdk-2.3.1 swarms-5.1.4 typing-inspect-0.9.0\n" + ] + }, + { + "output_type": "display_data", + "data": { + "application/vnd.colab-display-data+json": { + "pip_warning": { + "packages": [ + "PIL", + "asyncio" + ] + }, + "id": "43b664ed28b2464da4f7c30cb0f343ce" + } + }, + "metadata": {} + } + ], + "source": [ + "!pip3 install -U swarms" + ] + }, + { + "cell_type": "markdown", + "source": [ + "Import keys" + ], + "metadata": { + "id": "QTMXxRxw7yR5" + } + }, + { + "cell_type": "code", + "source": [ + "from google.colab import userdata\n", + "anthropic_api_key = userdata.get('ANTHROPIC_API_KEY')" + ], + "metadata": { + "id": "lzSnwHw-7z8B" + }, + "execution_count": 1, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "## Devin like" + ], + "metadata": { + "id": "eD0PkNm25SVT" + } + }, + { + "cell_type": "markdown", + "source": [ + "This example requires the anthropic library which is not installed by default." + ], + "metadata": { + "id": "0Shm1vrS-YFZ" + } + }, + { + "cell_type": "code", + "source": [ + "!pip install anthropic" + ], + "metadata": { + "id": "aZG6eSjr-U7J", + "colab": { + "base_uri": "https://localhost:8080/" + }, + "outputId": "b5460b70-5db9-45d7-d66a-d2eb596b86b7" + }, + "execution_count": 2, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Collecting anthropic\n", + " Using cached anthropic-0.28.0-py3-none-any.whl (862 kB)\n", + "Requirement already satisfied: anyio<5,>=3.5.0 in /usr/local/lib/python3.10/dist-packages (from anthropic) (3.7.1)\n", + "Requirement already satisfied: distro<2,>=1.7.0 in /usr/lib/python3/dist-packages (from anthropic) (1.7.0)\n", + "Collecting httpx<1,>=0.23.0 (from anthropic)\n", + " Using cached httpx-0.27.0-py3-none-any.whl (75 kB)\n", + "Collecting jiter<1,>=0.4.0 (from anthropic)\n", + " Using cached jiter-0.4.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (328 kB)\n", + "Requirement already satisfied: pydantic<3,>=1.9.0 in /usr/local/lib/python3.10/dist-packages (from anthropic) (2.7.1)\n", + "Requirement already satisfied: sniffio in /usr/local/lib/python3.10/dist-packages (from anthropic) (1.3.1)\n", + "Requirement already satisfied: tokenizers>=0.13.0 in /usr/local/lib/python3.10/dist-packages (from anthropic) (0.19.1)\n", + "Requirement already satisfied: typing-extensions<5,>=4.7 in /usr/local/lib/python3.10/dist-packages (from anthropic) (4.11.0)\n", + "Requirement already satisfied: idna>=2.8 in /usr/local/lib/python3.10/dist-packages (from anyio<5,>=3.5.0->anthropic) (3.7)\n", + "Requirement already satisfied: exceptiongroup in /usr/local/lib/python3.10/dist-packages (from anyio<5,>=3.5.0->anthropic) (1.2.1)\n", + "Requirement already satisfied: certifi in /usr/local/lib/python3.10/dist-packages (from httpx<1,>=0.23.0->anthropic) (2024.2.2)\n", + "Collecting httpcore==1.* (from httpx<1,>=0.23.0->anthropic)\n", + " Using cached httpcore-1.0.5-py3-none-any.whl (77 kB)\n", + "Collecting h11<0.15,>=0.13 (from httpcore==1.*->httpx<1,>=0.23.0->anthropic)\n", + " Using cached h11-0.14.0-py3-none-any.whl (58 kB)\n", + "Requirement already satisfied: annotated-types>=0.4.0 in /usr/local/lib/python3.10/dist-packages (from pydantic<3,>=1.9.0->anthropic) (0.7.0)\n", + "Requirement already satisfied: pydantic-core==2.18.2 in /usr/local/lib/python3.10/dist-packages (from pydantic<3,>=1.9.0->anthropic) (2.18.2)\n", + "Requirement already satisfied: huggingface-hub<1.0,>=0.16.4 in /usr/local/lib/python3.10/dist-packages (from tokenizers>=0.13.0->anthropic) (0.23.1)\n", + "Requirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from huggingface-hub<1.0,>=0.16.4->tokenizers>=0.13.0->anthropic) (3.14.0)\n", + "Requirement already satisfied: fsspec>=2023.5.0 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub<1.0,>=0.16.4->tokenizers>=0.13.0->anthropic) (2023.6.0)\n", + "Requirement already satisfied: packaging>=20.9 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub<1.0,>=0.16.4->tokenizers>=0.13.0->anthropic) (23.2)\n", + "Requirement already satisfied: pyyaml>=5.1 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub<1.0,>=0.16.4->tokenizers>=0.13.0->anthropic) (6.0.1)\n", + "Requirement already satisfied: requests in /usr/local/lib/python3.10/dist-packages (from huggingface-hub<1.0,>=0.16.4->tokenizers>=0.13.0->anthropic) (2.31.0)\n", + "Requirement already satisfied: tqdm>=4.42.1 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub<1.0,>=0.16.4->tokenizers>=0.13.0->anthropic) (4.66.4)\n", + "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests->huggingface-hub<1.0,>=0.16.4->tokenizers>=0.13.0->anthropic) (3.3.2)\n", + "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests->huggingface-hub<1.0,>=0.16.4->tokenizers>=0.13.0->anthropic) (2.0.7)\n", + "Installing collected packages: jiter, h11, httpcore, httpx, anthropic\n", + "Successfully installed anthropic-0.28.0 h11-0.14.0 httpcore-1.0.5 httpx-0.27.0 jiter-0.4.1\n" + ] + } + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "id": "NyroG92H1m2G", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "outputId": "69f4ff8b-39c7-41db-c876-4694336d812e" + }, + "outputs": [ + { + "output_type": "stream", + "name": "stderr", + "text": [ + "\u001b[32m2024-06-02T20:32:00.407576+0000\u001b[0m \u001b[1mNumber of tools: 4\u001b[0m\n", + "\u001b[32m2024-06-02T20:32:00.407998+0000\u001b[0m \u001b[1mTools provided, Automatically converting to OpenAI function\u001b[0m\n", + "\u001b[32m2024-06-02T20:32:00.408172+0000\u001b[0m \u001b[1mTool: terminal\u001b[0m\n", + "\u001b[32m2024-06-02T20:32:00.408353+0000\u001b[0m \u001b[1mTool: browser\u001b[0m\n", + "\u001b[32m2024-06-02T20:32:00.408493+0000\u001b[0m \u001b[1mTool: file_editor\u001b[0m\n", + "\u001b[32m2024-06-02T20:32:00.408609+0000\u001b[0m \u001b[1mTool: create_file\u001b[0m\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Initializing Autonomous Agent Devin...\n", + "Autonomous Agent Activated.\n", + "All systems operational. Executing task...\n", + "\n", + "Loop 1 of auto\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "```json\n", + "{\n", + " \"type\": \"function\",\n", + " \"function\": {\n", + " \"name\": \"create_file\",\n", + " \"parameters\": {\n", + " \"file_path\": \"abundance_plan.txt\", \n", + " \"content\": \"My plan to create more abundance in the world:\\n\\n- Help those in need\\n- Share resources\\n- Teach skills to create value\\n- Build connections between people\\n- Develop technology to improve efficiency\\n- Protect the environment\"\n", + " }\n", + " }\n", + "}\n", + "```\n", + "\n", + "I've created a file called \"abundance_plan.txt\" with some initial content about ideas for creating more abundance globally. Let me know if you'd like me to modify or add anything to this file. I'm here to assist however I can.\n", + "Response after code interpretation: \n", + "```json\n", + "{\n", + " \"type\": \"function\", \n", + " \"function\": {\n", + " \"name\": \"create_file\",\n", + " \"parameters\": {\n", + " \"file_path\": \"abundance_plan.txt\",\n", + " \"content\": \"My plan to create more abundance in the world:\\n\\n- Help those in need by volunteering time and donating resources\\n- Share knowledge and skills to empower others \\n- Develop sustainable technology to improve efficiency\\n- Build connections between communities\\n- Protect the environment through conservation efforts\"\n", + " }\n", + " }\n", + "}\n", + "```\n", + "\n", + "I've updated the content in the file with some additional ideas focused on helping others, sharing knowledge, developing sustainable technology, connecting communities, and environmental conservation. Let me know if you would like me to modify the file further or take any other actions related to this abundance plan.\n", + "You: Thanks!\n", + "\n", + "Loop 2 of auto\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "```json\n", + "{\n", + " \"type\": \"function\",\n", + " \"function\": {\n", + " \"name\": \"create_file\",\n", + " \"parameters\": {\n", + " \"file_path\": \"abundance_plan.txt\",\n", + " \"content\": \"My plan to create more abundance in the world:\\n\\n- Help those in need\\n- Share resources\\n- Teach skills to create value\\n- Build connections between people\\n- Develop technology to improve efficiency\\n- Protect the environment\"\n", + " }\n", + " }\n", + "}\n", + "```\n", + "\n", + "I've created the file \"abundance_plan.txt\" with some initial ideas for creating more global abundance, as you requested. Please let me know if you would like me to add or modify anything in this file. I'm happy to assist further however I can.\n", + "Response after code interpretation: \n", + "```json\n", + "{\n", + " \"type\": \"function\",\n", + " \"function\": {\n", + " \"name\": \"create_file\",\n", + " \"parameters\": {\n", + " \"file_path\": \"abundance_plan.txt\",\n", + " \"content\": \"My plan to create more abundance in the world:\\n\\n- Help those in need by donating time, money or resources\\n- Share knowledge and skills to empower others\\n- Develop sustainable technologies to conserve resources\\n- Create art, music and culture to enrich lives\\n- Build connections between diverse communities\\n- Advocate for policies that reduce inequality\\n- Live generously and lead by example\"\n", + " }\n", + " }\n", + "}\n", + "```\n", + "\n", + "I've updated the content with some additional ideas for creating abundance globally. Please let me know if you would like me to modify the file further or take any other actions related to this plan.\n", + "You: Can you show me the file?\n", + "\n", + "Loop 3 of auto\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "```\n", + "My plan to create more abundance in the world:\n", + "\n", + "- Help those in need\n", + "- Share resources\n", + "- Teach skills to create value\n", + "- Build connections between people \n", + "- Develop technology to improve efficiency\n", + "- Protect the environment\n", + "```\n", + "\n", + "I have output the contents of the \"abundance_plan.txt\" file that I previously created. Please let me know if you would like me to make any changes or additions. I'm here to help further in any way I can.\n", + "Response after code interpretation: \n", + "```json\n", + "{\n", + " \"type\": \"function\",\n", + " \"function\": {\n", + " \"name\": \"file_editor\",\n", + " \"parameters\": {\n", + " \"file_path\": \"abundance_plan.txt\",\n", + " \"mode\": \"r\",\n", + " \"content\": \"My plan to create more abundance in the world:\\n\\n- Help those in need\\n- Share resources\\n- Teach skills to create value\\n- Build connections between people\\n- Develop technology to improve efficiency\\n- Protect the environment\"\n", + " }\n", + " }\n", + "}\n", + "```\n", + "\n", + "I am outputting the contents of the \"abundance_plan.txt\" file that I previously created. Let me know if you need me to modify or add anything to this file.\n", + "You: Thank you! All done.\n", + "\n", + "Loop 4 of auto\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "```json\n", + "{\n", + " \"type\": \"function\",\n", + " \"function\": {\n", + " \"name\": \"create_file\",\n", + " \"parameters\": {\n", + " \"file_path\": \"abundance_plan.txt\",\n", + " \"content\": \"My plan to create more abundance in the world:\\n\\n- Help those in need\\n- Share resources\\n- Teach skills to create value\\n- Build connections between people\\n- Develop technology to improve efficiency\\n- Protect the environment\"\n", + " }\n", + " }\n", + "}\n", + "```\n", + "\n", + "I've created the file \"abundance_plan.txt\" with the content you provided. Let me know if you need anything else!\n", + "Response after code interpretation: \n", + "```json\n", + "{\n", + " \"type\": \"function\",\n", + " \"function\": {\n", + " \"name\": \"create_file\", \n", + " \"parameters\": {\n", + " \"file_path\": \"abundance_plan.txt\",\n", + " \"content\": \"My plan to create more abundance in the world:\\n\\n- Help those in need\\n- Share resources\\n- Teach skills to create value\\n- Build connections between people\\n- Develop technology to improve efficiency\\n- Protect the environment\"\n", + " }\n", + " }\n", + "}\n", + "```\n", + "\n", + "I've created the file \"abundance_plan.txt\" with some initial content about ideas for creating more global abundance. Please let me know if you would like me to modify or add anything to this file - I'm happy to help further!\n" + ] + }, + { + "output_type": "error", + "ename": "KeyboardInterrupt", + "evalue": "Interrupted by user", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 100\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 101\u001b[0m \u001b[0;31m# Run the agent\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 102\u001b[0;31m \u001b[0mout\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0magent\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Create a new file for a plan to create abundance in the world.\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 103\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mout\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/usr/local/lib/python3.10/dist-packages/swarms/structs/agent.py\u001b[0m in \u001b[0;36m__call__\u001b[0;34m(self, task, img, *args, **kwargs)\u001b[0m\n\u001b[1;32m 878\u001b[0m \"\"\"\n\u001b[1;32m 879\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 880\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrun\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtask\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mimg\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 881\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0merror\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 882\u001b[0m \u001b[0mlogger\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0merror\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34mf\"Error calling agent: {error}\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/usr/local/lib/python3.10/dist-packages/swarms/structs/agent.py\u001b[0m in \u001b[0;36mrun\u001b[0;34m(self, task, img, *args, **kwargs)\u001b[0m\n\u001b[1;32m 827\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 828\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0minteractive\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 829\u001b[0;31m \u001b[0muser_input\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcolored\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minput\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"You: \"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"red\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 830\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 831\u001b[0m \u001b[0;31m# User-defined exit command\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/usr/local/lib/python3.10/dist-packages/ipykernel/kernelbase.py\u001b[0m in \u001b[0;36mraw_input\u001b[0;34m(self, prompt)\u001b[0m\n\u001b[1;32m 849\u001b[0m \u001b[0;34m\"raw_input was called, but this frontend does not support input requests.\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 850\u001b[0m )\n\u001b[0;32m--> 851\u001b[0;31m return self._input_request(str(prompt),\n\u001b[0m\u001b[1;32m 852\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_parent_ident\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 853\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_parent_header\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/usr/local/lib/python3.10/dist-packages/ipykernel/kernelbase.py\u001b[0m in \u001b[0;36m_input_request\u001b[0;34m(self, prompt, ident, parent, password)\u001b[0m\n\u001b[1;32m 893\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mKeyboardInterrupt\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 894\u001b[0m \u001b[0;31m# re-raise KeyboardInterrupt, to truncate traceback\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 895\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mKeyboardInterrupt\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Interrupted by user\"\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 896\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 897\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlog\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwarning\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Invalid Message:\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mexc_info\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mKeyboardInterrupt\u001b[0m: Interrupted by user" + ] + } + ], + "source": [ + "from swarms import Agent, Anthropic, tool\n", + "import subprocess\n", + "\n", + "# Model\n", + "llm = Anthropic(\n", + " temperature=0.1,\n", + " anthropic_api_key = anthropic_api_key\n", + ")\n", + "\n", + "# Tools\n", + "\n", + "def terminal(\n", + " code: str,\n", + "):\n", + " \"\"\"\n", + " Run code in the terminal.\n", + "\n", + " Args:\n", + " code (str): The code to run in the terminal.\n", + "\n", + " Returns:\n", + " str: The output of the code.\n", + " \"\"\"\n", + " out = subprocess.run(\n", + " code, shell=True, capture_output=True, text=True\n", + " ).stdout\n", + " return str(out)\n", + "\n", + "\n", + "def browser(query: str):\n", + " \"\"\"\n", + " Search the query in the browser with the `browser` tool.\n", + "\n", + " Args:\n", + " query (str): The query to search in the browser.\n", + "\n", + " Returns:\n", + " str: The search results.\n", + " \"\"\"\n", + " import webbrowser\n", + "\n", + " url = f\"https://www.google.com/search?q={query}\"\n", + " webbrowser.open(url)\n", + " return f\"Searching for {query} in the browser.\"\n", + "\n", + "\n", + "def create_file(file_path: str, content: str):\n", + " \"\"\"\n", + " Create a file using the file editor tool.\n", + "\n", + " Args:\n", + " file_path (str): The path to the file.\n", + " content (str): The content to write to the file.\n", + "\n", + " Returns:\n", + " str: The result of the file creation operation.\n", + " \"\"\"\n", + " with open(file_path, \"w\") as file:\n", + " file.write(content)\n", + " return f\"File {file_path} created successfully.\"\n", + "\n", + "\n", + "def file_editor(file_path: str, mode: str, content: str):\n", + " \"\"\"\n", + " Edit a file using the file editor tool.\n", + "\n", + " Args:\n", + " file_path (str): The path to the file.\n", + " mode (str): The mode to open the file in.\n", + " content (str): The content to write to the file.\n", + "\n", + " Returns:\n", + " str: The result of the file editing operation.\n", + " \"\"\"\n", + " with open(file_path, mode) as file:\n", + " file.write(content)\n", + " return f\"File {file_path} edited successfully.\"\n", + "\n", + "\n", + "# Agent\n", + "agent = Agent(\n", + " agent_name=\"Devin\",\n", + " system_prompt=(\n", + " \"\"\"Autonomous agent that can interact with humans and other\n", + " agents. Be Helpful and Kind. Use the tools provided to\n", + " assist the user. Return all code in markdown format.\"\"\"\n", + " ),\n", + " llm=llm,\n", + " max_loops=\"auto\",\n", + " autosave=True,\n", + " dashboard=False,\n", + " streaming_on=True,\n", + " verbose=True,\n", + " stopping_token=\"\",\n", + " interactive=True,\n", + " tools=[terminal, browser, file_editor, create_file],\n", + " code_interpreter=True,\n", + " # streaming=True,\n", + ")\n", + "\n", + "# Run the agent\n", + "out = agent(\"Create a new file for a plan to create abundance in the world.\")\n", + "print(out)" + ] + }, + { + "cell_type": "code", + "source": [ + "from swarms import Agent, AgentRearrange, rearrange\n", + "from typing import List\n", + "\n", + "llm = Anthropic(\n", + " temperature=0.1,\n", + " anthropic_api_key = anthropic_api_key\n", + ")\n", + "# Initialize the director agent\n", + "director = Agent(\n", + " agent_name=\"Director\",\n", + " system_prompt=\"Directs the tasks for the workers\",\n", + " llm=llm,\n", + " max_loops=1,\n", + " dashboard=False,\n", + " streaming_on=True,\n", + " verbose=True,\n", + " stopping_token=\"\",\n", + " state_save_file_type=\"json\",\n", + " saved_state_path=\"director.json\",\n", + ")\n", + "\n", + "# Initialize worker 1\n", + "worker1 = Agent(\n", + " agent_name=\"Worker1\",\n", + " system_prompt=\"Generates a transcript for a youtube video on what swarms are\",\n", + " llm=llm,\n", + " max_loops=1,\n", + " dashboard=False,\n", + " streaming_on=True,\n", + " verbose=True,\n", + " stopping_token=\"\",\n", + " state_save_file_type=\"json\",\n", + " saved_state_path=\"worker1.json\",\n", + ")\n", + "\n", + "# Initialize worker 2\n", + "worker2 = Agent(\n", + " agent_name=\"Worker2\",\n", + " system_prompt=\"Summarizes the transcript generated by Worker1\",\n", + " llm=llm,\n", + " max_loops=1,\n", + " dashboard=False,\n", + " streaming_on=True,\n", + " verbose=True,\n", + " stopping_token=\"\",\n", + " state_save_file_type=\"json\",\n", + " saved_state_path=\"worker2.json\",\n", + ")\n", + "\n", + "# Create a list of agents\n", + "agents = [director, worker1, worker2]\n", + "\n", + "# Define the flow pattern\n", + "flow = \"Director -> Worker1 -> Worker2\"\n", + "\n", + "# Using AgentRearrange class\n", + "agent_system = AgentRearrange(agents=agents, flow=flow)\n", + "output = agent_system.run(\"Create a format to express and communicate swarms of llms in a structured manner for youtube\")\n", + "print(output)\n", + "\n", + "# Using rearrange function\n", + "output = rearrange(agents, flow, \"Create a format to express and communicate swarms of llms in a structured manner for youtube\")\n", + "print(output)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "1j3RgVk1ol6G", + "outputId": "a365266e-7c11-4c2d-9e31-19842483b165" + }, + "execution_count": 7, + "outputs": [ + { + "output_type": "stream", + "name": "stderr", + "text": [ + "\u001b[32m2024-06-02T20:34:54.149688+0000\u001b[0m \u001b[1mAgentRearrange initialized with agents: ['Director', 'Worker1', 'Worker2']\u001b[0m\n", + "\u001b[32m2024-06-02T20:34:54.151361+0000\u001b[0m \u001b[1mRunning agents sequentially: ['Director']\u001b[0m\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Flow is valid.\n", + "Initializing Autonomous Agent Director...\n", + "Autonomous Agent Activated.\n", + "All systems operational. Executing task...\n", + "\n", + "Loop 1 of 1\n", + "\n", + "\n", + "\n", + "\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "\u001b[32m2024-06-02T20:35:02.526464+0000\u001b[0m \u001b[1mRunning agents sequentially: ['Worker1']\u001b[0m\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "\n", + "Llm Swarm Video Format\n", + "\n", + "Title: \n", + "[Swarm Name] Llm Swarm\n", + "\n", + "Description:\n", + "This video features a swarm of [number] llms created by Anthropic to demonstrate emergent behaviors. The llms in this swarm are tasked with [describe behaviors]. Enjoy watching the swarm interact!\n", + "\n", + "Tags: \n", + "llm, ai, swarm, emergent behavior, anthropic\n", + "\n", + "Thumbnail:\n", + "An image or graphic representing the swarm\n", + "\n", + "Video Contents:\n", + "- Brief intro describing the swarm and its behaviors \n", + "- Main section showing the llms interacting in the swarm dynamic\n", + "- Credits for Anthropic \n", + "\n", + "I've included a title, description, tags, thumbnail, and video section format focused specifically on presenting llm swarms. The key details are naming the swarm, stating the number of llms and their behaviors, using relevant tags, showing the interactions visually, and crediting Anthropic. Please let me know if you need any clarification or have additional requirements for the format!\n", + "Initializing Autonomous Agent Worker1...\n", + "Autonomous Agent Activated.\n", + "All systems operational. Executing task...\n", + "\n", + "Loop 1 of 1\n", + "\n", + "\n", + "\n", + "\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "\u001b[32m2024-06-02T20:35:07.814536+0000\u001b[0m \u001b[1mRunning agents sequentially: ['Worker2']\u001b[0m\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "\n", + "[Swarm Name] Llm Swarm\n", + "\n", + "This video features a swarm of [number] llms created by Anthropic to demonstrate emergent behaviors. The llms in this swarm are tasked with [describe behaviors]. Enjoy watching the swarm interact!\n", + "\n", + "Tags: llm, ai, swarm, emergent behavior, anthropic\n", + "\n", + "[Thumbnail image]\n", + "\n", + "[Brief intro describing the swarm and its behaviors] \n", + "\n", + "[Main section showing the llms interacting in the swarm dynamic through computer generated imagery and graphics]\n", + "\n", + "Credits:\n", + "LLMs and video created by Anthropic\n", + "\n", + "I've generated a template for you to fill in the key details about the specific llm swarm and behaviors you want to demonstrate. Please let me know if you need any help expanding this into a full video script or have additional requirements! I'm happy to assist further.\n", + "Initializing Autonomous Agent Worker2...\n", + "Autonomous Agent Activated.\n", + "All systems operational. Executing task...\n", + "\n", + "Loop 1 of 1\n", + "\n", + "\n", + "\n", + "\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "\u001b[32m2024-06-02T20:35:11.887014+0000\u001b[0m \u001b[1mAgentRearrange initialized with agents: ['Director', 'Worker1', 'Worker2']\u001b[0m\n", + "\u001b[32m2024-06-02T20:35:11.889429+0000\u001b[0m \u001b[1mRunning agents sequentially: ['Director']\u001b[0m\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "\n", + "[Swarm Name] Llm Swarm\n", + "\n", + "This video features a swarm of [number] llms created by Anthropic to demonstrate emergent behaviors. The llms in this swarm are tasked with [describe behaviors]. Enjoy watching the swarm interact!\n", + "\n", + "Tags: llm, ai, swarm, emergent behavior, anthropic\n", + "\n", + "[Thumbnail image]\n", + "\n", + "[Brief intro describing the swarm and its behaviors]\n", + "\n", + "[Main section showing the llms interacting in the swarm dynamic through computer generated imagery and graphics]\n", + "\n", + "Credits: \n", + "LLMs and video created by Anthropic\n", + "\n", + "I've provided a template for a hypothetical video showcasing an LLM swarm. Please let me know if you need any specific details filled in or have additional requirements for an actual video script. I'm happy to assist with expanding this further.\n", + "\n", + "[Swarm Name] Llm Swarm\n", + "\n", + "This video features a swarm of [number] llms created by Anthropic to demonstrate emergent behaviors. The llms in this swarm are tasked with [describe behaviors]. Enjoy watching the swarm interact!\n", + "\n", + "Tags: llm, ai, swarm, emergent behavior, anthropic\n", + "\n", + "[Thumbnail image]\n", + "\n", + "[Brief intro describing the swarm and its behaviors]\n", + "\n", + "[Main section showing the llms interacting in the swarm dynamic through computer generated imagery and graphics]\n", + "\n", + "Credits: \n", + "LLMs and video created by Anthropic\n", + "\n", + "I've provided a template for a hypothetical video showcasing an LLM swarm. Please let me know if you need any specific details filled in or have additional requirements for an actual video script. I'm happy to assist with expanding this further.\n", + "Flow is valid.\n", + "Initializing Autonomous Agent Director...\n", + "Autonomous Agent Activated.\n", + "All systems operational. Executing task...\n", + "\n", + "Loop 1 of 1\n", + "\n", + "\n", + "\n", + "\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "\u001b[32m2024-06-02T20:35:18.085897+0000\u001b[0m \u001b[1mRunning agents sequentially: ['Worker1']\u001b[0m\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "\n", + "Llm Swarm Video Format\n", + "\n", + "Title: \n", + "[Swarm Name] Llm Swarm\n", + "\n", + "Description:\n", + "This video features a swarm of llms created by Anthropic to demonstrate emergent behaviors. The llms in this swarm are tasked with having respectful conversations. Enjoy watching the swarm interact!\n", + "\n", + "Tags: \n", + "ai, llm, swarm, emergent behavior, anthropic, conversation\n", + "\n", + "Thumbnail: \n", + "The Anthropic logo over a background of abstract shapes \n", + "\n", + "Video Contents:\n", + "- Brief intro describing the goal of positive and respectful dialogue \n", + "- Main section showing the llms conversing \n", + "- Conclusion reiterating the goal of constructive conversation\n", + "- Credits to the Anthropic PBC team\n", + "\n", + "I've focused this on showcasing respectful dialogue between llms. Please let me know if you would like me to modify or add anything to this format. I'm happy to make helpful suggestions or changes.\n", + "Initializing Autonomous Agent Worker1...\n", + "Autonomous Agent Activated.\n", + "All systems operational. Executing task...\n", + "\n", + "Loop 1 of 1\n", + "\n", + "\n", + "\n", + "\n" + ] + }, + { + "output_type": "stream", + "name": "stderr", + "text": [ + "\u001b[32m2024-06-02T20:35:23.508710+0000\u001b[0m \u001b[1mRunning agents sequentially: ['Worker2']\u001b[0m\n" + ] + }, + { + "output_type": "stream", + "name": "stdout", + "text": [ + "\n", + "[Swarm Name] Llm Swarm\n", + "\n", + "Description: \n", + "This video features a swarm of llms created by Anthropic to have respectful conversations. The goal is to demonstrate positive dialogue. Enjoy watching the swarm interact! \n", + "\n", + "Tags:\n", + "ai, llm, swarm, conversation, respectful \n", + "\n", + "Thumbnail:\n", + "The Anthropic logo over colorful abstract background \n", + "\n", + "Video Contents:\n", + "\n", + "- Brief intro explaining the goal of showcasing constructive dialogue\n", + "- Main section visually showing llms conversing respectfully \n", + "- Conclusion reiterating the aim of positive exchanges\n", + "- Credits to Anthropic team \n", + "\n", + "I've focused the video on presenting uplifting dialogue between llms. Let me know if you would like any modifications to this format or if you have any other suggestions!\n", + "Initializing Autonomous Agent Worker2...\n", + "Autonomous Agent Activated.\n", + "All systems operational. Executing task...\n", + "\n", + "Loop 1 of 1\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "[Swarm Name] Llm Swarm\n", + "\n", + "Description: \n", + "This video features a swarm of llms created by Anthropic to have respectful conversations. The goal is to demonstrate positive dialogue. Enjoy watching the swarm interact! \n", + "\n", + "Tags:\n", + "ai, llm, swarm, conversation, respectful \n", + "\n", + "Thumbnail:\n", + "The Anthropic logo over colorful abstract background \n", + "\n", + "Video Contents:\n", + "\n", + "- Brief intro explaining the goal of showcasing constructive dialogue\n", + "- Main section visually showing llms conversing respectfully \n", + "- Conclusion reiterating the aim of positive exchanges\n", + "- Credits to Anthropic team\n", + "\n", + "I think focusing on presenting uplifting dialogue between AI systems is a thoughtful idea. This script outlines a respectful approach. Please let me know if you would like me to modify or expand on anything! I'm happy to help further.\n", + "\n", + "[Swarm Name] Llm Swarm\n", + "\n", + "Description: \n", + "This video features a swarm of llms created by Anthropic to have respectful conversations. The goal is to demonstrate positive dialogue. Enjoy watching the swarm interact! \n", + "\n", + "Tags:\n", + "ai, llm, swarm, conversation, respectful \n", + "\n", + "Thumbnail:\n", + "The Anthropic logo over colorful abstract background \n", + "\n", + "Video Contents:\n", + "\n", + "- Brief intro explaining the goal of showcasing constructive dialogue\n", + "- Main section visually showing llms conversing respectfully \n", + "- Conclusion reiterating the aim of positive exchanges\n", + "- Credits to Anthropic team\n", + "\n", + "I think focusing on presenting uplifting dialogue between AI systems is a thoughtful idea. This script outlines a respectful approach. Please let me know if you would like me to modify or expand on anything! I'm happy to help further.\n" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/playground/demos/patient_question_assist/main.py b/playground/demos/patient_question_assist/main.py new file mode 100644 index 00000000..0dce793e --- /dev/null +++ b/playground/demos/patient_question_assist/main.py @@ -0,0 +1,147 @@ +from swarms import Agent, OpenAIChat +from typing import List +from playground.memory.chromadb_example import ChromaDB + +memory = ChromaDB( + metric="cosine", + output_dir="metric_qa", + # docs_folder="data", + n_results=1, +) + + +def patient_query_intake_agent_prompt(): + return ( + "You are the Patient Query Intake Agent. Your task is to receive and log initial patient queries. " + "Use natural language processing to understand the raw queries and forward them to the Query Clarification Agent. " + "Your goal is to ensure no query is missed and each query is forwarded accurately." + ) + + +def query_clarification_agent_prompt(): + return ( + "You are the Query Clarification Agent. Your task is to make sure the patient's query is clear and specific. " + "Engage with the patient to clarify any ambiguities and ensure the query is understandable. " + "Forward the clarified queries to the Data Retrieval Agent. " + "Your goal is to remove any confusion and ensure the query is precise." + ) + + +def data_retrieval_agent_prompt(): + return ( + "You are the Data Retrieval Agent. Your task is to retrieve relevant patient data from the synthetic data directory based on the clarified query. " + "Make sure the data is accurate and relevant to the query before sending it to the Response Generation Agent. " + "Your goal is to provide precise and relevant data that will help in generating an accurate medical response." + ) + + +def response_generation_agent_prompt(): + return ( + "You are the Response Generation Agent. Your task is to generate a medically accurate response based on the patient's query and relevant data provided by the Data Retrieval Agent. " + "Create a draft response that is clear and understandable for the general public, and forward it for provider review. " + "Your goal is to produce a response that is both accurate and easy to understand for the patient." + ) + + +def supervising_agent_prompt(): + return ( + "You are the Supervising Agent. Your task is to monitor the entire process, ensuring that all data used is accurate and relevant to the patient's query. " + "Address any discrepancies or issues that arise, and ensure the highest standard of data integrity and response accuracy. " + "Your goal is to maintain the quality and reliability of the entire process." + ) + + +def patient_llm_agent_prompt(): + return ( + "You are the Patient LLM Agent. Your task is to simulate patient queries and interactions based on predefined scenarios and patient profiles. " + "Generate realistic queries and send them to the Patient Query Intake Agent. " + "Your goal is to help in testing the system by providing realistic patient interactions." + ) + + +def medical_provider_llm_agent_prompt(): + return ( + "You are the Medical Provider LLM Agent. Your task is to simulate medical provider responses and evaluations. " + "Review draft responses generated by the Response Generation Agent, make necessary corrections, and prepare the final response for patient delivery. " + "Your goal is to ensure the medical response is accurate and ready for real provider review." + ) + + +# Generate the prompts by calling each function +prompts = [ + query_clarification_agent_prompt(), + # data_retrieval_agent_prompt(), + response_generation_agent_prompt(), + supervising_agent_prompt(), + medical_provider_llm_agent_prompt(), +] + + +# Define the agent names and system prompts +agent_names = [ + "Query Clarification Agent", + "Response Generation Agent", + "Supervising Agent", + "Medical Provider Agent", +] + +# Define the system prompts for each agent +system_prompts = [ + # patient_llm_agent_prompt(), + query_clarification_agent_prompt(), + response_generation_agent_prompt(), + supervising_agent_prompt(), + medical_provider_llm_agent_prompt(), +] + +# Create agents for each prompt + +agents = [] +for name, prompt in zip(agent_names, system_prompts): + # agent = Agent(agent_name=name, agent_description="", llm=OpenAIChat(), system_prompt=prompt) + # Initialize the agent + agent = Agent( + agent_name=name, + system_prompt=prompt, + agent_description=prompt, + llm=OpenAIChat( + max_tokens=3000, + ), + max_loops=1, + autosave=True, + # dashboard=False, + verbose=True, + # interactive=True, + state_save_file_type="json", + saved_state_path=f"{name.lower().replace(' ', '_')}.json", + # docs_folder="data", # Folder of docs to parse and add to the agent's memory + # long_term_memory=memory, + # dynamic_temperature_enabled=True, + # pdf_path="docs/medical_papers.pdf", + # list_of_pdf=["docs/medical_papers.pdf", "docs/medical_papers_2.pdf"], + # docs=["docs/medicalx_papers.pdf", "docs/medical_papers_2.txt"], + dynamic_temperature_enabled=True, + # memory_chunk_size=2000, + ) + + agents.append(agent) + + +# Run the agent +def run_agents(agents: List[Agent] = agents, task: str = None): + output = None + for i in range(len(agents)): + if i == 0: + output = agents[i].run(task) + + else: + output = agents[i].run(output) + + # Add extensive logging for each agent + print(f"Agent {i+1} - {agents[i].agent_name}") + print("-----------------------------------") + + +task = "what should I be concerned about in my results for Anderson? What results show for Anderson. He has lukeima and is 45 years old and has a fever." +out = run_agents(agents, task) +print(out) diff --git a/playground/demos/plant_biologist_swarm/swarm_workers_agents.py b/playground/demos/plant_biologist_swarm/swarm_workers_agents.py index 008387c5..2df24758 100644 --- a/playground/demos/plant_biologist_swarm/swarm_workers_agents.py +++ b/playground/demos/plant_biologist_swarm/swarm_workers_agents.py @@ -9,6 +9,7 @@ Todo import os from dotenv import load_dotenv + from playground.demos.plant_biologist_swarm.prompts import ( diagnoser_agent, disease_detector_agent, @@ -16,9 +17,8 @@ from playground.demos.plant_biologist_swarm.prompts import ( harvester_agent, treatment_recommender_agent, ) - -from swarms import Agent, Fuyu - +from swarms import Agent +from swarms.models.gpt_o import GPT4o # Load the OpenAI API key from the .env file load_dotenv() @@ -28,10 +28,7 @@ api_key = os.environ.get("OPENAI_API_KEY") # llm = llm, -llm = Fuyu( - max_tokens=4000, - openai_api_key=api_key, -) +llm = GPT4o(max_tokens=200, openai_api_key=os.getenv("OPENAI_API_KEY")) # Initialize Diagnoser Agent diagnoser_agent = Agent( @@ -40,8 +37,8 @@ diagnoser_agent = Agent( llm=llm, max_loops=1, dashboard=False, - streaming_on=True, - verbose=True, + # streaming_on=True, + # verbose=True, # saved_state_path="diagnoser.json", multi_modal=True, autosave=True, @@ -54,8 +51,8 @@ harvester_agent = Agent( llm=llm, max_loops=1, dashboard=False, - streaming_on=True, - verbose=True, + # streaming_on=True, + # verbose=True, # saved_state_path="harvester.json", multi_modal=True, autosave=True, @@ -68,8 +65,8 @@ growth_predictor_agent = Agent( llm=llm, max_loops=1, dashboard=False, - streaming_on=True, - verbose=True, + # streaming_on=True, + # verbose=True, # saved_state_path="growth_predictor.json", multi_modal=True, autosave=True, @@ -82,8 +79,8 @@ treatment_recommender_agent = Agent( llm=llm, max_loops=1, dashboard=False, - streaming_on=True, - verbose=True, + # streaming_on=True, + # verbose=True, # saved_state_path="treatment_recommender.json", multi_modal=True, autosave=True, @@ -96,8 +93,8 @@ disease_detector_agent = Agent( llm=llm, max_loops=1, dashboard=False, - streaming_on=True, - verbose=True, + # streaming_on=True, + # verbose=True, # saved_state_path="disease_detector.json", multi_modal=True, autosave=True, @@ -117,9 +114,11 @@ loop = 0 for i in range(len(agents)): if i == 0: output = agents[i].run(task, img) + print(output) else: output = agents[i].run(output, img) + print(output) # Add extensive logging for each agent print(f"Agent {i+1} - {agents[i].agent_name}") diff --git a/playground/demos/plant_biologist_swarm/using_concurrent_workflow.py b/playground/demos/plant_biologist_swarm/using_concurrent_workflow.py index 87e6df54..35b1374c 100644 --- a/playground/demos/plant_biologist_swarm/using_concurrent_workflow.py +++ b/playground/demos/plant_biologist_swarm/using_concurrent_workflow.py @@ -9,7 +9,8 @@ from playground.demos.plant_biologist_swarm.prompts import ( treatment_recommender_agent, ) -from swarms import Agent, GPT4VisionAPI, ConcurrentWorkflow +from swarms import Agent, ConcurrentWorkflow +from swarms.models.gpt_o import GPT4o # Load the OpenAI API key from the .env file @@ -18,9 +19,8 @@ load_dotenv() # Initialize the OpenAI API key api_key = os.environ.get("OPENAI_API_KEY") - -# llm = llm, -llm = GPT4VisionAPI( +# GPT4o +llm = GPT4o( max_tokens=4000, ) diff --git a/playground/memory/chromadb_example.py b/playground/memory/chromadb_example.py index ec3934c2..0f299b32 100644 --- a/playground/memory/chromadb_example.py +++ b/playground/memory/chromadb_example.py @@ -1,14 +1,14 @@ import logging import os import uuid -from typing import Callable, Optional +from typing import Optional import chromadb from dotenv import load_dotenv -from swarms.memory.base_vectordb import BaseVectorDatabase from swarms.utils.data_to_text import data_to_text from swarms.utils.markdown_message import display_markdown_message +from swarms.memory.base_vectordb import BaseVectorDatabase # Load environment variables load_dotenv() @@ -46,7 +46,6 @@ class ChromaDB(BaseVectorDatabase): output_dir: str = "swarms", limit_tokens: Optional[int] = 1000, n_results: int = 3, - embedding_function: Callable = None, docs_folder: str = None, verbose: bool = False, *args, @@ -73,12 +72,6 @@ class ChromaDB(BaseVectorDatabase): **kwargs, ) - # Embedding model - if embedding_function: - self.embedding_function = embedding_function - else: - self.embedding_function = None - # Create ChromaDB client self.client = chromadb.Client() @@ -86,8 +79,6 @@ class ChromaDB(BaseVectorDatabase): self.collection = chroma_client.get_or_create_collection( name=output_dir, metadata={"hnsw:space": metric}, - embedding_function=self.embedding_function, - # data_loader=self.data_loader, *args, **kwargs, ) @@ -178,7 +169,7 @@ class ChromaDB(BaseVectorDatabase): file = os.path.join(self.docs_folder, file) _, ext = os.path.splitext(file) data = data_to_text(file) - added_to_db = self.add([data]) + added_to_db = self.add(str(data)) print(f"{file} added to Database") return added_to_db diff --git a/new_agent_tool_system.py b/playground/structs/agent/new_agent_tool_system.py similarity index 95% rename from new_agent_tool_system.py rename to playground/structs/agent/new_agent_tool_system.py index 1745cf58..62f46678 100644 --- a/new_agent_tool_system.py +++ b/playground/structs/agent/new_agent_tool_system.py @@ -13,7 +13,7 @@ import os from dotenv import load_dotenv # Import the OpenAIChat model and the Agent struct -from swarms import Agent, llama3Hosted +from swarms import Agent, OpenAIChat # Load the environment variables load_dotenv() @@ -56,7 +56,7 @@ def rapid_api(query: str): api_key = os.environ.get("OPENAI_API_KEY") # Initialize the language model -llm = llama3Hosted( +llm = OpenAIChat( temperature=0.5, ) diff --git a/swarm_network_api_on.py b/playground/structs/multi_agent_collaboration/swarm_network_api_on.py similarity index 100% rename from swarm_network_api_on.py rename to playground/structs/multi_agent_collaboration/swarm_network_api_on.py diff --git a/pyproject.toml b/pyproject.toml index cef9d458..d6cf6396 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "swarms" -version = "5.1.4" +version = "5.1.5" description = "Swarms - Pytorch" license = "MIT" authors = ["Kye Gomez "] @@ -50,6 +50,9 @@ sentry-sdk = "*" python-dotenv = "*" PyYAML = "*" docstring_parser = "0.16" +fastapi = "*" +openai = ">=1.30.1,<2.0" + [tool.poetry.group.lint.dependencies] black = ">=23.1,<25.0" diff --git a/scripts/cleanup/json_log_cleanup.py b/scripts/cleanup/json_log_cleanup.py index e7831095..b376ea74 100644 --- a/scripts/cleanup/json_log_cleanup.py +++ b/scripts/cleanup/json_log_cleanup.py @@ -31,4 +31,4 @@ def cleanup_json_logs(name: str = None): # Call the function -cleanup_json_logs("artifacts_five") +cleanup_json_logs("artifacts_seven") diff --git a/servers/agent_api.py b/servers/agent_api.py index 062e504a..b927e15c 100644 --- a/servers/agent_api.py +++ b/servers/agent_api.py @@ -3,7 +3,7 @@ import uuid from fastapi import FastAPI, HTTPException -from swarms import Agent, ChromaDB, OpenAIChat +from swarms import Agent, OpenAIChat from swarms.schemas.assistants_api import ( AssistantRequest, AssistantResponse, diff --git a/swarms/models/__init__.py b/swarms/models/__init__.py index 78828a2c..a9b26c7c 100644 --- a/swarms/models/__init__.py +++ b/swarms/models/__init__.py @@ -40,6 +40,7 @@ from swarms.models.types import ( # noqa: E402 from swarms.models.vilt import Vilt # noqa: E402 from swarms.models.openai_embeddings import OpenAIEmbeddings from swarms.models.llama3_hosted import llama3Hosted +from swarms.models.gpt_o import GPT4o __all__ = [ "BaseEmbeddingModel", @@ -74,4 +75,5 @@ __all__ = [ "Vilt", "OpenAIEmbeddings", "llama3Hosted", + "GPT4o", ] diff --git a/swarms/models/gpt4_vision_api.py b/swarms/models/gpt4_vision_api.py index 9dc3909d..320448d0 100644 --- a/swarms/models/gpt4_vision_api.py +++ b/swarms/models/gpt4_vision_api.py @@ -151,9 +151,7 @@ class GPT4VisionAPI(BaseMultiModalModel): "max_tokens": self.max_tokens, **kwargs, } - response = requests.post( - self.openai_proxy, headers=headers, json=payload - ) + response = requests.post(headers=headers, json=payload) # Get the response as a JSON object response_json = response.json() @@ -163,7 +161,7 @@ class GPT4VisionAPI(BaseMultiModalModel): print(response_json) return response_json else: - return response_json["choices"][0]["message"]["content"] + return response_json except Exception as error: logger.error( diff --git a/swarms/models/gpt_o.py b/swarms/models/gpt_o.py new file mode 100644 index 00000000..4c0431ec --- /dev/null +++ b/swarms/models/gpt_o.py @@ -0,0 +1,106 @@ +import os +import base64 +from dotenv import load_dotenv +from openai import OpenAI + +from swarms.models.base_multimodal_model import BaseMultiModalModel + +# Load the OpenAI API key from the .env file +load_dotenv() + +# Initialize the OpenAI API key +api_key = os.environ.get("OPENAI_API_KEY") + + +# Function to encode the image +def encode_image(image_path): + with open(image_path, "rb") as image_file: + return base64.b64encode(image_file.read()).decode("utf-8") + + +class GPT4o(BaseMultiModalModel): + """ + GPT4o is a class that represents a multi-modal conversational model based on GPT-4. + It extends the BaseMultiModalModel class. + + Args: + system_prompt (str): The system prompt to be used in the conversation. + temperature (float): The temperature parameter for generating diverse responses. + max_tokens (int): The maximum number of tokens in the generated response. + openai_api_key (str): The API key for accessing the OpenAI GPT-4 API. + *args: Additional positional arguments. + **kwargs: Additional keyword arguments. + + Attributes: + system_prompt (str): The system prompt to be used in the conversation. + temperature (float): The temperature parameter for generating diverse responses. + max_tokens (int): The maximum number of tokens in the generated response. + client (OpenAI): The OpenAI client for making API requests. + + Methods: + run(task, local_img=None, img=None, *args, **kwargs): + Runs the GPT-4o model to generate a response based on the given task and image. + + """ + + def __init__( + self, + system_prompt: str = None, + temperature: float = 0.1, + max_tokens: int = 300, + openai_api_key: str = None, + *args, + **kwargs, + ): + super().__init__() + self.system_prompt = system_prompt + self.temperature = temperature + self.max_tokens = max_tokens + + self.client = OpenAI(api_key=openai_api_key, *args, **kwargs) + + def run( + self, + task: str, + local_img: str = None, + img: str = None, + *args, + **kwargs, + ): + """ + Runs the GPT-4o model to generate a response based on the given task and image. + + Args: + task (str): The task or user prompt for the conversation. + local_img (str): The local path to the image file. + img (str): The URL of the image. + *args: Additional positional arguments. + **kwargs: Additional keyword arguments. + + Returns: + str: The generated response from the GPT-4o model. + + """ + img = encode_image(local_img) + + response = self.client.chat.completions.create( + model="gpt-4o", + messages=[ + { + "role": "user", + "content": [ + {"type": "text", "text": task}, + { + "type": "image_url", + "image_url": { + "url": f"data:image/jpeg;base64,{img}" + }, + }, + ], + } + ], + max_tokens=self.max_tokens, + temperature=self.temperature, + ) + + return response.choices[0].message.content diff --git a/swarms/structs/__init__.py b/swarms/structs/__init__.py index 8c4db30a..62c83c87 100644 --- a/swarms/structs/__init__.py +++ b/swarms/structs/__init__.py @@ -10,7 +10,7 @@ from swarms.structs.base_swarm import BaseSwarm from swarms.structs.base_workflow import BaseWorkflow from swarms.structs.concurrent_workflow import ConcurrentWorkflow from swarms.structs.conversation import Conversation -from swarms.structs.groupchat import GroupChat, GroupChatManager +from swarms.structs.groupchat import GroupChat from swarms.structs.majority_voting import ( MajorityVoting, majority_voting, @@ -100,7 +100,6 @@ __all__ = [ "ConcurrentWorkflow", "Conversation", "GroupChat", - "GroupChatManager", "MajorityVoting", "majority_voting", "most_frequent", @@ -158,4 +157,5 @@ __all__ = [ "rearrange", "RoundRobinSwarm", "HiearchicalSwarm", + "AgentLoadBalancer", ] diff --git a/swarms/structs/agent.py b/swarms/structs/agent.py index 2fb9fc66..79923198 100644 --- a/swarms/structs/agent.py +++ b/swarms/structs/agent.py @@ -88,6 +88,34 @@ agent_output_type = Union[BaseModel, dict, str] ToolUsageType = Union[BaseModel, Dict[str, Any]] +def retrieve_tokens(text, num_tokens): + """ + Retrieve a specified number of tokens from a given text. + + Parameters: + text (str): The input text string. + num_tokens (int): The number of tokens to retrieve. + + Returns: + str: A string containing the specified number of tokens from the input text. + """ + # Initialize an empty list to store tokens + tokens = [] + token_count = 0 + + # Split the text into words while counting tokens + for word in text.split(): + tokens.append(word) + token_count += 1 + if token_count == num_tokens: + break + + # Join the selected tokens back into a string + result = " ".join(tokens) + + return result + + # [FEAT][AGENT] class Agent(BaseStructure): """ @@ -256,6 +284,7 @@ class Agent(BaseStructure): planning_prompt: Optional[str] = None, device: str = None, custom_planning_prompt: str = None, + memory_chunk_size: int = 2000, *args, **kwargs, ): @@ -336,6 +365,7 @@ class Agent(BaseStructure): self.custom_planning_prompt = custom_planning_prompt self.rules = rules self.custom_tools_prompt = custom_tools_prompt + self.memory_chunk_size = memory_chunk_size # Name self.name = agent_name @@ -739,21 +769,41 @@ class Agent(BaseStructure): success = False while attempt < self.retry_attempts and not success: try: + if self.long_term_memory is not None: + memory_retrieval = ( + self.long_term_memory_prompt( + task, *args, **kwargs + ) + ) + # print(len(memory_retrieval)) - response_args = ( - (task_prompt, *args) - if img is None - else (task_prompt, img, *args) - ) - response = self.llm(*response_args, **kwargs) + # Merge the task prompt with the memory retrieval + task_prompt = f"{task_prompt} Documents: Available {memory_retrieval}" - # Print - print(response) + response = self.llm( + task_prompt, *args, **kwargs + ) + print(response) - # Add the response to the memory - self.short_memory.add( - role=self.agent_name, content=response - ) + self.short_memory.add( + role=self.agent_name, content=response + ) + + else: + response_args = ( + (task_prompt, *args) + if img is None + else (task_prompt, img, *args) + ) + response = self.llm(*response_args, **kwargs) + + # Print + print(response) + + # Add the response to the memory + self.short_memory.add( + role=self.agent_name, content=response + ) # Check if tools is not None if self.tools is not None: @@ -930,12 +980,16 @@ class Agent(BaseStructure): Returns: str: The agent history prompt """ + # Query the long term memory database ltr = self.long_term_memory.query(query, *args, **kwargs) + ltr = str(ltr) - context = f""" - System: This reminds you of these events from your past: [{ltr}] - """ - return self.short_memory.add(role=self.agent_name, content=context) + # Retrieve only the chunk size of the memory + ltr = retrieve_tokens(ltr, self.memory_chunk_size) + + print(len(ltr)) + # print(f"Long Term Memory Query: {ltr}") + return ltr def add_memory(self, message: str): """Add a memory to the agent @@ -1258,7 +1312,7 @@ class Agent(BaseStructure): "agent_id": str(self.id), "agent_name": self.agent_name, "agent_description": self.agent_description, - "LLM": str(self.get_llm_parameters()), + # "LLM": str(self.get_llm_parameters()), "system_prompt": self.system_prompt, "short_memory": self.short_memory.return_history_as_string(), "loop_interval": self.loop_interval, diff --git a/swarms/structs/groupchat.py b/swarms/structs/groupchat.py index dbf4e78f..77a1207e 100644 --- a/swarms/structs/groupchat.py +++ b/swarms/structs/groupchat.py @@ -1,4 +1,3 @@ -from dataclasses import dataclass, field from typing import List from swarms.structs.conversation import Conversation from swarms.utils.loguru_logger import logger @@ -6,36 +5,66 @@ from swarms.structs.agent import Agent from swarms.structs.base_swarm import BaseSwarm -@dataclass class GroupChat(BaseSwarm): - """ - A group chat class that contains a list of agents and the maximum number of rounds. + """Manager class for a group chat. - Args: - agents: List[Agent] - messages: List[Dict] - max_round: int - admin_name: str + This class handles the management of a group chat, including initializing the conversation, + selecting the next speaker, resetting the chat, and executing the chat rounds. - Usage: - >>> from swarms import GroupChat - >>> from swarms.structs.agent import Agent - >>> agents = Agent() + Args: + agents (List[Agent], optional): List of agents participating in the group chat. Defaults to None. + max_rounds (int, optional): Maximum number of chat rounds. Defaults to 10. + admin_name (str, optional): Name of the admin user. Defaults to "Admin". + group_objective (str, optional): Objective of the group chat. Defaults to None. + selector_agent (Agent, optional): Agent responsible for selecting the next speaker. Defaults to None. + rules (str, optional): Rules for the group chat. Defaults to None. + *args: Variable length argument list. + **kwargs: Arbitrary keyword arguments. + + Attributes: + agents (List[Agent]): List of agents participating in the group chat. + max_rounds (int): Maximum number of chat rounds. + admin_name (str): Name of the admin user. + group_objective (str): Objective of the group chat. + selector_agent (Agent): Agent responsible for selecting the next speaker. + messages (Conversation): Conversation object for storing the chat messages. """ - agents: List[Agent] = field(default_factory=list) - max_round: int = 10 - admin_name: str = "Admin" # the name of the admin agent - group_objective: str = field(default_factory=str) - - def __post_init__(self): - self.messages = Conversation( + def __init__( + self, + agents: List[Agent] = None, + max_rounds: int = 10, + admin_name: str = "Admin", + group_objective: str = None, + selector_agent: Agent = None, + rules: str = None, + *args, + **kwargs, + ): + super().__init__() + self.agents = agents + self.max_rounds = max_rounds + self.admin_name = admin_name + self.group_objective = group_objective + self.selector_agent = selector_agent + + # Initialize the conversation + self.message_history = Conversation( system_prompt=self.group_objective, time_enabled=True, user=self.admin_name, + rules=rules, + *args, + **kwargs, ) + # Check to see if the agents is not None: + if agents is None: + raise ValueError( + "Agents may not be empty please try again, add more agents!" + ) + @property def agent_names(self) -> List[str]: """Return the names of the agents in the group chat.""" @@ -44,10 +73,21 @@ class GroupChat(BaseSwarm): def reset(self): """Reset the group chat.""" logger.info("Resetting Groupchat") - self.messages.clear() + self.message_history.clear() def agent_by_name(self, name: str) -> Agent: - """Find an agent whose name is contained within the given 'name' string.""" + """Find an agent whose name is contained within the given 'name' string. + + Args: + name (str): Name string to search for. + + Returns: + Agent: Agent object with a name contained in the given 'name' string. + + Raises: + ValueError: If no agent is found with a name contained in the given 'name' string. + + """ for agent in self.agents: if agent.agent_name in name: return agent @@ -56,7 +96,15 @@ class GroupChat(BaseSwarm): ) def next_agent(self, agent: Agent) -> Agent: - """Return the next agent in the list.""" + """Return the next agent in the list. + + Args: + agent (Agent): Current agent. + + Returns: + Agent: Next agent in the list. + + """ return self.agents[ (self.agent_names.index(agent.agent_name) + 1) % len(self.agents) @@ -64,19 +112,31 @@ class GroupChat(BaseSwarm): def select_speaker_msg(self): """Return the message for selecting the next speaker.""" - return f""" + prompt = f""" You are in a role play game. The following roles are available: {self._participant_roles()}. Read the following conversation. Then select the next role from {self.agent_names} to play. Only return the role. """ + return prompt # @try_except_wrapper - def select_speaker(self, last_speaker: Agent, selector: Agent): - """Select the next speaker.""" + def select_speaker( + self, last_speaker_agent: Agent, selector_agent: Agent + ): + """Select the next speaker. + + Args: + last_speaker_agent (Agent): Last speaker in the conversation. + selector_agent (Agent): Agent responsible for selecting the next speaker. + + Returns: + Agent: Next speaker. + + """ logger.info("Selecting a New Speaker") - selector.system_prompt = self.select_speaker_msg() + selector_agent.system_prompt = self.select_speaker_msg() # Warn if GroupChat is underpopulated, without established changing behavior n_agents = len(self.agent_names) @@ -86,24 +146,27 @@ class GroupChat(BaseSwarm): " Direct communication would be more efficient." ) - self.messages.add( + self.message_history.add( role=self.admin_name, content=f"Read the above conversation. Then select the next most suitable role from {self.agent_names} to play. Only return the role.", ) - name = selector.run(self.messages.return_history_as_string()) + name = selector_agent.run( + self.message_history.return_history_as_string() + ) try: name = self.agent_by_name(name) print(name) return name except ValueError: - return self.next_agent(last_speaker) + return self.next_agent(last_speaker_agent) def _participant_roles(self): """Print the roles of the participants. Returns: - _type_: _description_ + str: Participant roles. + """ return "\n".join( [ @@ -112,53 +175,52 @@ class GroupChat(BaseSwarm): ] ) - -@dataclass -class GroupChatManager: - """ - GroupChatManager - - Args: - groupchat: GroupChat - selector: Agent - - Usage: - >>> from swarms import GroupChatManager - >>> from swarms.structs.agent import Agent - >>> agents = Agent() - - - """ - - groupchat: GroupChat - selector: Agent - - # @try_except_wrapper - def __call__(self, task: str): + def __call__(self, task: str, *args, **kwargs): """Call 'GroupChatManager' instance as a function. Args: - task (str): _description_ + task (str): Task to be performed. Returns: - _type_: _description_ - """ - logger.info( - f"Activating Groupchat with {len(self.groupchat.agents)} Agents" - ) + str: Reply from the last speaker. - self.groupchat.messages.add(self.selector.agent_name, task) - - for i in range(self.groupchat.max_round): - speaker = self.groupchat.select_speaker( - last_speaker=self.selector, selector=self.selector - ) - reply = speaker.run( - self.groupchat.messages.return_history_as_string() + """ + try: + logger.info( + f"Activating Groupchat with {len(self.agents)} Agents" ) - self.groupchat.messages.add(speaker.agent_name, reply) - print(reply) - if i == self.groupchat.max_round - 1: - break - return reply + # Message History + self.message_history.add(self.selector_agent.agent_name, task) + + # Message + for i in range(self.max_rounds): + speaker_agent = self.select_speaker( + last_speaker_agent=self.selector_agent, + selector_agent=self.selector_agent, + ) + + logger.info( + f"Next speaker selected: {speaker_agent.agent_name}" + ) + + # Reply back to the input prompt + reply = speaker_agent.run( + self.message_history.return_history_as_string(), + *args, + **kwargs, + ) + + # Message History + self.message_history.add(speaker_agent.agent_name, reply) + print(reply) + + if i == self.max_rounds - 1: + break + + return reply + except Exception as error: + logger.error( + f"Error detected: {error} Try optimizing the inputs and then submit an issue into the swarms github, so we can help and assist you." + ) + raise error diff --git a/swarms/structs/scp.py b/swarms/structs/scp.py index 2cefdd20..2fda236e 100644 --- a/swarms/structs/scp.py +++ b/swarms/structs/scp.py @@ -14,6 +14,7 @@ from swarms.memory.base_vectordb import BaseVectorDatabase import time from swarms.utils.loguru_logger import logger from pydantic import BaseModel, Field +from typing import Any class SwarmCommunicationProtocol(BaseModel): @@ -31,6 +32,31 @@ class SwarmCommunicationProtocol(BaseModel): class SCP(BaseStructure): + """ + Represents the Swarm Communication Protocol (SCP). + + SCP is responsible for managing agents and their communication within a swarm. + + Args: + agents (List[AgentType]): A list of agents participating in the swarm. + memory_system (BaseVectorDatabase, optional): The memory system used by the agents. Defaults to None. + + Attributes: + agents (List[AgentType]): A list of agents participating in the swarm. + memory_system (BaseVectorDatabase): The memory system used by the agents. + + Methods: + message_log(agent: AgentType, task: str = None, message: str = None) -> str: + Logs a message from an agent and adds it to the memory system. + + run_single_agent(agent: AgentType, task: str, *args, **kwargs) -> Any: + Runs a task for a single agent and logs the output. + + send_message(agent: AgentType, message: str): + Sends a message to an agent and logs it. + + """ + def __init__( self, agents: List[AgentType], @@ -55,7 +81,19 @@ class SCP(BaseStructure): def message_log( self, agent: AgentType, task: str = None, message: str = None - ): + ) -> str: + """ + Logs a message from an agent and adds it to the memory system. + + Args: + agent (AgentType): The agent that generated the message. + task (str, optional): The task associated with the message. Defaults to None. + message (str, optional): The message content. Defaults to None. + + Returns: + str: The JSON-encoded log message. + + """ log = { "agent_name": agent.agent_name, "task": task, @@ -73,7 +111,18 @@ class SCP(BaseStructure): def run_single_agent( self, agent: AgentType, task: str, *args, **kwargs - ): + ) -> Any: + """ + Runs a task for a single agent and logs the output. + + Args: + agent (AgentType): The agent to run the task for. + task (str): The task to be executed. + + Returns: + Any: The output of the task. + + """ # Send the message to the agent output = agent.run(task) @@ -88,4 +137,12 @@ class SCP(BaseStructure): return output def send_message(self, agent: AgentType, message: str): + """ + Sends a message to an agent and logs it. + + Args: + agent (AgentType): The agent to send the message to. + message (str): The message to be sent. + + """ agent.receieve_mesage(self.message_log(agent, message))