{"id":13651108,"url":"https://github.com/farizrahman4u/loopgpt","last_synced_at":"2025-05-15T20:04:49.347Z","repository":{"id":153543003,"uuid":"628087446","full_name":"farizrahman4u/loopgpt","owner":"farizrahman4u","description":"Modular Auto-GPT Framework","archived":false,"fork":false,"pushed_at":"2024-03-10T11:21:44.000Z","size":571,"stargazers_count":1450,"open_issues_count":25,"forks_count":131,"subscribers_count":32,"default_branch":"main","last_synced_at":"2025-04-08T01:38:56.816Z","etag":null,"topics":["chatgpt","gpt","gpt4","llms"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/farizrahman4u.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":".github/SUPPORT.md","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["farizrahman4u"]}},"created_at":"2023-04-14T22:11:29.000Z","updated_at":"2025-04-07T10:58:54.000Z","dependencies_parsed_at":"2023-05-19T07:31:17.938Z","dependency_job_id":"6e5ce037-7185-4da1-a4cd-8fbc17a065ac","html_url":"https://github.com/farizrahman4u/loopgpt","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/farizrahman4u%2Floopgpt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/farizrahman4u%2Floopgpt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/farizrahman4u%2Floopgpt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/farizrahman4u%2Floopgpt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/farizrahman4u","download_url":"https://codeload.github.com/farizrahman4u/loopgpt/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254414499,"owners_count":22067272,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chatgpt","gpt","gpt4","llms"],"created_at":"2024-08-02T02:00:45.253Z","updated_at":"2025-05-15T20:04:42.643Z","avatar_url":"https://github.com/farizrahman4u.png","language":"Python","funding_links":["https://github.com/sponsors/farizrahman4u"],"categories":["Python","GitHub projects","Learning","Frameworks and Platforms","A01_文本生成_文本对话","SDK, Libraries, Frameworks","排行榜 [2025-03-18]","AI Agents"],"sub_categories":["Repositories","大语言对话模型及数据","Python library, sdk or frameworks"],"readme":"\n\u003cH1\u003e\n\u003cp align=\"center\"\u003e\n  L♾️pGPT\n\u003c/p\u003e\n\u003c/H1\u003e\n\u003cp align=\"center\"\u003e\n    \u003cb\u003eA Modular Auto-GPT Framework\u003c/b\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://discord.gg/rqs26cqx7v\"\u003e\n        \u003cimg src=\"https://img.shields.io/discord/1098162593291587594?style=for-the-badge\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n\n\n\nL♾️pGPT is a re-implementation of the popular [Auto-GPT](https://github.com/Significant-Gravitas/Auto-GPT) project as a proper python package, written with modularity and extensibility in mind.\n\n## 🚀 Features 🚀\n\n*  **\"Plug N Play\" API** - Extensible and modular \"Pythonic\" framework, not just a command line tool. Easy to add new features, integrations and custom agent capabilities, all from python code, no nasty config files!\n*  **GPT 3.5 friendly** - Better results than Auto-GPT for those who don't have GPT-4 access yet!\n*  **Minimal prompt overhead** - Every token counts. We are continuously working on getting the best results with the least possible number of tokens.\n*  **Human in the Loop** - Ability to \"course correct\" agents who go astray via human feedback.\n*  **Full state serialization** - Pick up where you left off; L♾️pGPT can save the complete state of an agent, including memory and the states of its tools to a file or python object. No external databases or vector stores required (but they are still supported)!\n\n\n## 🧑‍💻 Installation\n\n### Install from PyPI\n\n📗 **This installs the latest stable version of L♾️pGPT. This is recommended for most users:**\n\n```bash\npip install loopgpt\n```\n\n📕 The below two methods install the latest development version of L♾️pGPT. Note that this version maybe unstable:\n\n### Install from source\n\n```bash\npip install git+https://www.github.com/farizrahman4u/loopgpt.git@main\n```\n\n### Install from source (dev)\n\n```bash\ngit clone https://www.github.com/farizrahman4u/loopgpt.git\ncd  loopgpt\npip install -e .\n```\n\n### Install from source (dev) using Docker\n```bash\ngit clone https://www.github.com/farizrahman4u/loopgpt.git\ncd  loopgpt\ndocker build -t loopgpt:local-dev .\n```\n\n## 🏎️ Getting Started\n\n### Setup your OpenAI API Key 🔑\n\n#### Option 1️⃣: Via a `.env` file\n\nCreate a `.env` file in your current working directory (wherever you are going to run L♾️pGPT from) and add the following line to it:\n\n```bash\nOPENAI_API_KEY=\"\u003cyour-openai-api-key\u003e\"\n```\n\n🛑 **IMPORTANT** 🛑\n\nWindows users, please make sure \"show file extensions\" is enabled in your file explorer. Otherwise, your file will be named `.env.txt` instead of `.env`.\n\n#### Option 2️⃣: Via environment variables\n\nSet an environment variable called `OPENAI_API_KEY` to your OpenAI API Key.\n\nHow to set environment variables:\n- [Windows](https://www.architectryan.com/2018/08/31/how-to-change-environment-variables-on-windows-10/)\n- [Linux](https://www.freecodecamp.org/news/how-to-set-an-environment-variable-in-linux/)\n- [Mac](https://phoenixnap.com/kb/set-environment-variable-mac)\n\n### Create a new L♾️pGPT Agent🕵️:\n\nLet's create an agent in a new [Python](https://python.org) script.\n\n```python\nfrom loopgpt.agent import Agent\n\nagent = Agent()\n```\n\nL♾️pGPT uses `gpt-3.5-turbo` by default and all outputs shown here are made using it. GPT-4 users can set `model=\"gpt-4\"` instead:\n\n```python\nagent = Agent(model=\"gpt-4\")\n```\n\n\n### Setup the Agent🕵️'s attributes:\n\n```python\nagent.name = \"ResearchGPT\"\nagent.description = \"an AI assistant that researches and finds the best tech products\"\nagent.goals = [\n    \"Search for the best headphones on Google\",\n    \"Analyze specs, prices and reviews to find the top 5 best headphones\",\n    \"Write the list of the top 5 best headphones and their prices to a file\",\n    \"Summarize the pros and cons of each headphone and write it to a different file called 'summary.txt'\",\n]\n```\n\nAnd we're off! Let's run the Agent🕵️'s CLI:\n\n```python\nagent.cli()\n```\n\nSave your Python file as `research_gpt.py` and run it:\n\n```bash\npython research_gpt.py\n```\n\n\u003cimg src=\"/docs/assets/imgs/loopgpt_demo_pic.png?raw=true\" height=\"350\"\u003e\n\nYou can exit the CLI by typing \"exit\".\n\n### 🔁 Continuous Mode 🔁\n\nIf `continuous` is set to `True`, the agent will not ask for the user's permission to execute commands. It may go into infinite loops, so use it at your own risk!\n\n```python\nagent.cli(continuous=True)\n```\n\n### 💻 Command Line Only Mode\n\nYou can run L♾️pGPT directly from the command line without having to write any python code as well:\n\n```bash\nloopgpt run\n```\n\nRun `loopgpt --help` to see all the available options.\n\n### 🐋 Docker Mode\n\nYou can run L♾️pGPT in the previously mentioned modes, using Docker:\n\n```bash\n# CLI mode\ndocker run -i --rm loopgpt:local-dev loopgpt run\n\n# Script mode example\ndocker run -i --rm -v \"$(pwd)/scripts:/scripts\" loopgpt:local-dev python /scripts/myscript.py\n\n```\n\n## ⚒️ Adding custom tools ⚒️\n\nL♾️pGPT agents come with a set of builtin tools which allows them to perform various basic tasks such as searching the web, filesystem operations, etc. You can view these tools with `print(agent.tools)`.\n\nIn addition to these builtin tools, you can also add your own tools to the agent's toolbox.\n\n### Example: WeatherGPT 🌦️\n\nLet's create WeatherGPT, an AI assistant for all things weather.\n\nA tool inherits from `BaseTool` and you only need to write a docstring to get your tool up and running!\n\n```python\nfrom loopgpt.tools import BaseTool\n\nclass GetWeather(BaseTool):\n    \"\"\"Quickly get the weather for a given city\n\n    Args:\n        city (str): name of the city\n    \n    Returns:\n        dict: The weather report for the city\n    \"\"\"\n    \n    def run(self, city):\n        ...\n```\n\nL♾️pGPT gives a default ID to your tool but you can override them if you'd like:\n\n```python\nclass GetWeather(BaseTool):\n    \"\"\"Quickly get the weather for a given city\n\n    Args:\n        city (str): name of the city\n    \n    Returns:\n        dict: The weather report for the city\n    \"\"\"\n\n    @property\n    def id(self):\n        return \"get_weather_command\"\n```\n\nNow let's define what our tool will do in its `run` method:\n\n```python\nimport requests\n\n# Define your custom tool\nclass GetWeather(BaseTool):\n    \"\"\"Quickly get the weather for a given city\n\n    Args:\n        city (str): name of the city\n    \n    Returns:\n        dict: The weather report for the city\n    \"\"\"\n    \n    def run(self, city):\n        try:\n            url = \"https://wttr.in/{}?format=%l+%C+%h+%t+%w+%p+%P\".format(city)\n            data = requests.get(url).text.split(\" \")\n            keys = (\"location\", \"condition\", \"humidity\", \"temperature\", \"wind\", \"precipitation\", \"pressure\")\n            data = dict(zip(keys, data))\n            return data\n        except Exception as e:\n            return f\"An error occurred while getting the weather: {e}.\"\n```\n\nThat's it! You've built your first custom tool. Let's register it with a new agent and run it:\n\n```python\nfrom loopgpt.tools import WriteToFile\nimport loopgpt\n\n# Register custom tool type\n# This is actually not required here, but is required when you load a saved agent with custom tools.\nloopgpt.tools.register_tool_type(GetWeather)\n\n# Create Agent\nagent = loopgpt.Agent(tools=[GetWeather, WriteToFile])\nagent.name = \"WeatherGPT\"\nagent.description = \"an AI assistant that tells you the weather\"\nagent.goals = [\n    \"Get the weather for NewYork and Beijing\",\n    \"Give the user tips on how to dress for the weather in NewYork and Beijing\",\n    \"Write the tips to a file called 'dressing_tips.txt'\"\n]\n\n# Run the agent's CLI\nagent.cli()\n```\n\nLet's take a look at the `dressing_tips.txt` file that WeatherGPT wrote for us:\n\ndressing_tips.txt\n```\n- It's Clear outside with a temperature of +10°C in Beijing. Wearing a light jacket and pants is recommended.\n- It's Overcast outside with a temperature of +11°C in New York. Wearing a light jacket, pants, and an umbrella is recommended.\n```\n\n## 🚢 Course Correction\n\nUnlike Auto-GPT, the agent does not terminate when the user denies the execution of a command. Instead it asks the user for feedback to correct its course.\n\nTo correct the agent's course, just deny execution and provide feedback:\n\n\u003cimg src=\"/docs/assets/imgs/course_correction_1.png?raw=true\"\u003e\n\nThe agent has updated its course of action:\n\n\u003cimg src=\"/docs/assets/imgs/course_correction_2.png?raw=true\"\u003e\n\n\n## 💾 Saving and Loading Agent State 💾\n\nYou can save an agent's state to a json file with:\n\n```python\nagent.save(\"ResearchGPT.json\")\n```\n\nThis saves the agent's configuration (model, name, description etc) as well as its internal state (conversation state, memory, tool states etc).\nYou can also save just the confifguration by passing `include_state=False` to `agent.save()`:\n\n```python\nagent.save(\"ResearchGPT.json\", include_state=False)\n```\n\nThen pick up where you left off with:\n\n```python\nimport loopgpt\nagent = loopgpt.Agent.load(\"ResearchGPT.json\")\nagent.cli()\n```\n\nor by running the saved agent from the command line:\n\n```bash\nloopgpt run ResearchGPT.json\n```\n\nYou can convert the agent state to a json compatible python dictionary instead of writing to a file:\n\n```python\nagent_config = agent.config()\n```\n\nTo get just the configuration without the internal state:\n\n```python\nagent_config = agent.config(include_state=False)\n```\n\n\nTo reload the agent from the config, use:\n\n```python\nimport loopgpt\n\nagent = loopgpt.Agent.from_config(agent_config)\n```\n\n## 📋 Requirements\n\n- Python 3.8+\n- [An OpenAI API Key](https://platform.openai.com/account/api-keys)\n- Google Chrome\n\n### Optional Requirements\n\nFor official google search support you will need to setup two environment variable keys `GOOGLE_API_KEY` and `CUSTOM_SEARCH_ENGINE_ID`, here is how to get them:\n\n1. Create an application on the [Google Developers Console][google-console].\n2. Create your custom search engine using [Google Custom Search][google-custom-search].\n3. Once your custom search engine is created, select it and get into the details page of the search engine.\n    - On the \"Basic\" section, you will find the \"Search engine ID\" field, that value is what you will use for the `CUSTOM_SEARCH_ENGINE_ID` environment variable.\n    - Now go to the \"Programmatic Access\" section at the bottom of the page.\n        - Create a \"Custom Search JSON API\"\n        - Follow the dialog by selecting the application you created on step #1 and when you get your API key use it to populate the `GOOGLE_API_KEY` environment variable.\n\nℹ️ In case these are absent, L♾️pGPT will fall back to using [DuckDuckGo Search](https://pypi.org/project/duckduckgo-search/).\n\n## 💌 Contribute \n\nWe need A LOT of Help! Please open an issue or a PR if you'd like to contribute.\n\n## 🌳 Community\n\nNeed help? Join our [Discord](https://discord.gg/rqs26cqx7v).\n\n[google-console]: https://console.developers.google.com\n[google-custom-search]: https://programmablesearchengine.google.com/controlpanel/create\n\n\n## ⭐ Star History 📈\n\u003cimg src=\"https://api.star-history.com/svg?repos=farizrahman4u/loopgpt\u0026type=Date\" alt= \"Star History Chart\" height=\"350\"\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffarizrahman4u%2Floopgpt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffarizrahman4u%2Floopgpt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffarizrahman4u%2Floopgpt/lists"}