!function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){var t=null;try{t=new URLSearchParams(window.location.search).get("docusaurus-theme")}catch(t){}return t}()||function(){var t=null;try{t=localStorage.getItem("theme")}catch(t){}return t}();t(null!==e?e:"light")}(),document.documentElement.setAttribute("data-announcement-bar-initially-dismissed",function(){try{return"true"===localStorage.getItem("docusaurus.announcement.dismiss")}catch(t){}return!1}())

[Skip to main content](#__docusaurus_skipToContent_fallback)

LangChain v0.2 is coming soon! Preview the new docs [here](/v0.2/docs/introduction/).

[

![🦜️🔗 Langchain](/v0.1/img/brand/wordmark.png)![🦜️🔗 Langchain](/v0.1/img/brand/wordmark-dark.png)

](/v0.1/)[Docs](/v0.1/docs/get_started/introduction/)[Use cases](/v0.1/docs/use_cases/)[Integrations](/v0.1/docs/integrations/platforms/)[API Reference](https://api.js.langchain.com)

[More](#)

*   [People](/v0.1/docs/people/)
*   [Community](/v0.1/docs/community/)
*   [Tutorials](/v0.1/docs/additional_resources/tutorials/)
*   [Contributing](/v0.1/docs/contributing/)

[v0.1](#)

*   [v0.2](https://js.langchain.com/v0.2/docs/introduction)
*   [v0.1](/v0.1/docs/get_started/introduction/)

[🦜🔗](#)

*   [LangSmith](https://smith.langchain.com)
*   [LangSmith Docs](https://docs.smith.langchain.com)
*   [LangChain Hub](https://smith.langchain.com/hub)
*   [LangServe](https://github.com/langchain-ai/langserve)
*   [Python Docs](https://python.langchain.com/)

[Chat](https://chatjs.langchain.com)[](https://github.com/langchain-ai/langchainjs)

Search

*   [Use cases](/v0.1/docs/use_cases/)
    
    *   [SQL](/v0.1/docs/use_cases/sql/)
        
    *   [Chatbots](/v0.1/docs/use_cases/chatbots/)
        
    *   [Extraction](/v0.1/docs/use_cases/extraction/)
        
    *   [Query Analysis](/v0.1/docs/use_cases/query_analysis/)
        
    *   [Q&A with RAG](/v0.1/docs/use_cases/question_answering/)
        
    *   [Tool use](/v0.1/docs/use_cases/tool_use/)
        
    *   [Interacting with APIs](/v0.1/docs/use_cases/api/)
    *   [Tabular Question Answering](/v0.1/docs/use_cases/tabular/)
    *   [Graphs](/v0.1/docs/use_cases/graph/)
        
    *   [Summarization](/v0.1/docs/use_cases/summarization/)
    *   [Agent Simulations](/v0.1/docs/use_cases/agent_simulations/)
        
    *   [Autonomous Agents](/v0.1/docs/use_cases/autonomous_agents/)
        
        *   [SalesGPT](/v0.1/docs/use_cases/autonomous_agents/sales_gpt/)
        *   [AutoGPT](/v0.1/docs/use_cases/autonomous_agents/auto_gpt/)
        *   [BabyAGI](/v0.1/docs/use_cases/autonomous_agents/baby_agi/)
    *   [Code Understanding](/v0.1/docs/use_cases/code_understanding/)
    *   [Audio/Video Structured Extraction](/v0.1/docs/use_cases/media/)

*   [](/v0.1/)
*   [Use cases](/v0.1/docs/use_cases/)
*   [Autonomous Agents](/v0.1/docs/use_cases/autonomous_agents/)
*   AutoGPT

On this page

AutoGPT
=======

info

Original Repo: [https://github.com/Significant-Gravitas/Auto-GPT](https://github.com/Significant-Gravitas/Auto-GPT)

AutoGPT is a custom agent that uses long-term memory along with a prompt designed for independent work (ie. without asking user input) to perform tasks.

Isomorphic Example[​](#isomorphic-example "Direct link to Isomorphic Example")
------------------------------------------------------------------------------

In this example we use AutoGPT to predict the weather for a given location. This example is designed to run in all JS environments, including the browser.

tip

See [this section for general instructions on installing integration packages](/v0.1/docs/get_started/installation/#installing-integration-packages).

*   npm
*   Yarn
*   pnpm

    npm install @langchain/openai @langchain/community

    yarn add @langchain/openai @langchain/community

    pnpm add @langchain/openai @langchain/community

    import { AutoGPT } from "langchain/experimental/autogpt";import { ReadFileTool, WriteFileTool } from "langchain/tools";import { InMemoryFileStore } from "langchain/stores/file/in_memory";import { MemoryVectorStore } from "langchain/vectorstores/memory";import { OpenAIEmbeddings, ChatOpenAI } from "@langchain/openai";import { SerpAPI } from "@langchain/community/tools/serpapi";const store = new InMemoryFileStore();const tools = [  new ReadFileTool({ store }),  new WriteFileTool({ store }),  new SerpAPI(process.env.SERPAPI_API_KEY, {    location: "San Francisco,California,United States",    hl: "en",    gl: "us",  }),];const vectorStore = new MemoryVectorStore(new OpenAIEmbeddings());const autogpt = AutoGPT.fromLLMAndTools(  new ChatOpenAI({ temperature: 0 }),  tools,  {    memory: vectorStore.asRetriever(),    aiName: "Tom",    aiRole: "Assistant",  });await autogpt.run(["write a weather report for SF today"]);/*{    "thoughts": {        "text": "I need to write a weather report for SF today. I should use a search engine to find the current weather conditions.",        "reasoning": "I don't have the current weather information for SF in my short term memory, so I need to use a search engine to find it.",        "plan": "- Use the search command to find the current weather conditions for SF\n- Write a weather report based on the information found",        "criticism": "I need to make sure that the information I find is accurate and up-to-date.",        "speak": "I will use the search command to find the current weather conditions for SF."    },    "command": {        "name": "search",        "args": {            "input": "current weather conditions San Francisco"        }    }}{    "thoughts": {        "text": "I have found the current weather conditions for SF. I need to write a weather report based on this information.",        "reasoning": "I have the information I need to write a weather report, so I should use the write_file command to save it to a file.",        "plan": "- Use the write_file command to save the weather report to a file",        "criticism": "I need to make sure that the weather report is clear and concise.",        "speak": "I will use the write_file command to save the weather report to a file."    },    "command": {        "name": "write_file",        "args": {            "file_path": "weather_report.txt",            "text": "San Francisco Weather Report:\n\nMorning: 53°, Chance of Rain 1%\nAfternoon: 59°, Chance of Rain 0%\nEvening: 52°, Chance of Rain 3%\nOvernight: 48°, Chance of Rain 2%"        }    }}{    "thoughts": {        "text": "I have completed all my objectives. I will use the finish command to signal that I am done.",        "reasoning": "I have completed the task of writing a weather report for SF today, so I don't need to do anything else.",        "plan": "- Use the finish command to signal that I am done",        "criticism": "I need to make sure that I have completed all my objectives before using the finish command.",        "speak": "I will use the finish command to signal that I am done."    },    "command": {        "name": "finish",        "args": {            "response": "I have completed all my objectives."        }    }}*/

#### API Reference:

*   [AutoGPT](https://api.js.langchain.com/classes/langchain_experimental_autogpt.AutoGPT.html) from `langchain/experimental/autogpt`
*   [ReadFileTool](https://api.js.langchain.com/classes/langchain_tools.ReadFileTool.html) from `langchain/tools`
*   [WriteFileTool](https://api.js.langchain.com/classes/langchain_tools.WriteFileTool.html) from `langchain/tools`
*   [InMemoryFileStore](https://api.js.langchain.com/classes/langchain_stores_file_in_memory.InMemoryFileStore.html) from `langchain/stores/file/in_memory`
*   [MemoryVectorStore](https://api.js.langchain.com/classes/langchain_vectorstores_memory.MemoryVectorStore.html) from `langchain/vectorstores/memory`
*   [OpenAIEmbeddings](https://api.js.langchain.com/classes/langchain_openai.OpenAIEmbeddings.html) from `@langchain/openai`
*   [ChatOpenAI](https://api.js.langchain.com/classes/langchain_openai.ChatOpenAI.html) from `@langchain/openai`
*   [SerpAPI](https://api.js.langchain.com/classes/langchain_community_tools_serpapi.SerpAPI.html) from `@langchain/community/tools/serpapi`

Node.js Example[​](#nodejs-example "Direct link to Node.js Example")
--------------------------------------------------------------------

In this example we use AutoGPT to predict the weather for a given location. This example is designed to run in Node.js, so it uses the local filesystem, and a Node-only vector store.

    import { AutoGPT } from "langchain/experimental/autogpt";import { ReadFileTool, WriteFileTool } from "langchain/tools";import { NodeFileStore } from "langchain/stores/file/node";import { HNSWLib } from "@langchain/community/vectorstores/hnswlib";import { OpenAIEmbeddings, ChatOpenAI } from "@langchain/openai";import { SerpAPI } from "@langchain/community/tools/serpapi";const store = new NodeFileStore();const tools = [  new ReadFileTool({ store }),  new WriteFileTool({ store }),  new SerpAPI(process.env.SERPAPI_API_KEY, {    location: "San Francisco,California,United States",    hl: "en",    gl: "us",  }),];const vectorStore = new HNSWLib(new OpenAIEmbeddings(), {  space: "cosine",  numDimensions: 1536,});const autogpt = AutoGPT.fromLLMAndTools(  new ChatOpenAI({ temperature: 0 }),  tools,  {    memory: vectorStore.asRetriever(),    aiName: "Tom",    aiRole: "Assistant",  });await autogpt.run(["write a weather report for SF today"]);/*{    "thoughts": {        "text": "I need to write a weather report for SF today. I should use a search engine to find the current weather conditions.",        "reasoning": "I don't have the current weather information for SF in my short term memory, so I need to use a search engine to find it.",        "plan": "- Use the search command to find the current weather conditions for SF\n- Write a weather report based on the information found",        "criticism": "I need to make sure that the information I find is accurate and up-to-date.",        "speak": "I will use the search command to find the current weather conditions for SF."    },    "command": {        "name": "search",        "args": {            "input": "current weather conditions San Francisco"        }    }}{    "thoughts": {        "text": "I have found the current weather conditions for SF. I need to write a weather report based on this information.",        "reasoning": "I have the information I need to write a weather report, so I should use the write_file command to save it to a file.",        "plan": "- Use the write_file command to save the weather report to a file",        "criticism": "I need to make sure that the weather report is clear and concise.",        "speak": "I will use the write_file command to save the weather report to a file."    },    "command": {        "name": "write_file",        "args": {            "file_path": "weather_report.txt",            "text": "San Francisco Weather Report:\n\nMorning: 53°, Chance of Rain 1%\nAfternoon: 59°, Chance of Rain 0%\nEvening: 52°, Chance of Rain 3%\nOvernight: 48°, Chance of Rain 2%"        }    }}{    "thoughts": {        "text": "I have completed all my objectives. I will use the finish command to signal that I am done.",        "reasoning": "I have completed the task of writing a weather report for SF today, so I don't need to do anything else.",        "plan": "- Use the finish command to signal that I am done",        "criticism": "I need to make sure that I have completed all my objectives before using the finish command.",        "speak": "I will use the finish command to signal that I am done."    },    "command": {        "name": "finish",        "args": {            "response": "I have completed all my objectives."        }    }}*/

#### API Reference:

*   [AutoGPT](https://api.js.langchain.com/classes/langchain_experimental_autogpt.AutoGPT.html) from `langchain/experimental/autogpt`
*   [ReadFileTool](https://api.js.langchain.com/classes/langchain_tools.ReadFileTool.html) from `langchain/tools`
*   [WriteFileTool](https://api.js.langchain.com/classes/langchain_tools.WriteFileTool.html) from `langchain/tools`
*   [NodeFileStore](https://api.js.langchain.com/classes/langchain_stores_file_node.NodeFileStore.html) from `langchain/stores/file/node`
*   [HNSWLib](https://api.js.langchain.com/classes/langchain_community_vectorstores_hnswlib.HNSWLib.html) from `@langchain/community/vectorstores/hnswlib`
*   [OpenAIEmbeddings](https://api.js.langchain.com/classes/langchain_openai.OpenAIEmbeddings.html) from `@langchain/openai`
*   [ChatOpenAI](https://api.js.langchain.com/classes/langchain_openai.ChatOpenAI.html) from `@langchain/openai`
*   [SerpAPI](https://api.js.langchain.com/classes/langchain_community_tools_serpapi.SerpAPI.html) from `@langchain/community/tools/serpapi`

* * *

#### Help us out by providing feedback on this documentation page:

[

Previous

SalesGPT

](/v0.1/docs/use_cases/autonomous_agents/sales_gpt/)[

Next

BabyAGI

](/v0.1/docs/use_cases/autonomous_agents/baby_agi/)

*   [Isomorphic Example](#isomorphic-example)
*   [Node.js Example](#nodejs-example)

Community

*   [Discord](https://discord.gg/cU2adEyC7w)
*   [Twitter](https://twitter.com/LangChainAI)

GitHub

*   [Python](https://github.com/langchain-ai/langchain)
*   [JS/TS](https://github.com/langchain-ai/langchainjs)

More

*   [Homepage](https://langchain.com)
*   [Blog](https://blog.langchain.dev)

Copyright © 2024 LangChain, Inc.