!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/)
*   BabyAGI

On this page

BabyAGI
=======

info

Original Repo: [https://github.com/yoheinakajima/babyagi](https://github.com/yoheinakajima/babyagi)

BabyAGI is made up of 3 components:

*   A chain responsible for creating tasks
*   A chain responsible for prioritising tasks
*   A chain responsible for executing tasks

These chains are executed in sequence until the task list is empty or the maximum number of iterations is reached.

Simple Example[​](#simple-example "Direct link to Simple Example")
------------------------------------------------------------------

In this example we use BabyAGI directly without any tools. You'll see this results in successfully creating a list of tasks but when it comes to executing the tasks we do not get concrete results. This is because we have not provided any tools to the BabyAGI. We'll see how to do that in the next example.

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

    yarn add @langchain/openai

    pnpm add @langchain/openai

    import { BabyAGI } from "langchain/experimental/babyagi";import { MemoryVectorStore } from "langchain/vectorstores/memory";import { OpenAIEmbeddings, OpenAI } from "@langchain/openai";const vectorStore = new MemoryVectorStore(new OpenAIEmbeddings());const babyAGI = BabyAGI.fromLLM({  llm: new OpenAI({ temperature: 0 }),  vectorstore: vectorStore,  maxIterations: 3,});await babyAGI.invoke({ objective: "Write a weather report for SF today" });/******TASK LIST*****1: Make a todo list*****NEXT TASK*****1: Make a todo list*****TASK RESULT*****1. Check the weather forecast for San Francisco today2. Make note of the temperature, humidity, wind speed, and other relevant weather conditions3. Write a weather report summarizing the forecast4. Check for any weather alerts or warnings5. Share the report with the relevant stakeholders*****TASK LIST*****2: Check the current temperature in San Francisco3: Check the current humidity in San Francisco4: Check the current wind speed in San Francisco5: Check for any weather alerts or warnings in San Francisco6: Check the forecast for the next 24 hours in San Francisco7: Check the forecast for the next 48 hours in San Francisco8: Check the forecast for the next 72 hours in San Francisco9: Check the forecast for the next week in San Francisco10: Check the forecast for the next month in San Francisco11: Check the forecast for the next 3 months in San Francisco1: Write a weather report for SF today*****NEXT TASK*****2: Check the current temperature in San Francisco*****TASK RESULT*****I will check the current temperature in San Francisco. I will use an online weather service to get the most up-to-date information.*****TASK LIST*****3: Check the current UV index in San Francisco4: Check the current air quality in San Francisco5: Check the current precipitation levels in San Francisco6: Check the current cloud cover in San Francisco7: Check the current barometric pressure in San Francisco8: Check the current dew point in San Francisco9: Check the current wind direction in San Francisco10: Check the current humidity levels in San Francisco1: Check the current temperature in San Francisco to the average temperature for this time of year2: Check the current visibility in San Francisco11: Write a weather report for SF today*****NEXT TASK*****3: Check the current UV index in San Francisco*****TASK RESULT*****The current UV index in San Francisco is moderate, with a value of 5. This means that it is safe to be outside for short periods of time without sunscreen, but it is still recommended to wear sunscreen and protective clothing when outside for extended periods of time.*/

#### API Reference:

*   [BabyAGI](https://api.js.langchain.com/classes/langchain_experimental_babyagi.BabyAGI.html) from `langchain/experimental/babyagi`
*   [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`
*   [OpenAI](https://api.js.langchain.com/classes/langchain_openai.OpenAI.html) from `@langchain/openai`

Example with Tools[​](#example-with-tools "Direct link to Example with Tools")
------------------------------------------------------------------------------

In this next example we replace the execution chain with a custom agent with a Search tool. This gives BabyAGI the ability to use real-world data when executing tasks, which makes it much more powerful. You can add additional tools to give it more capabilities.

    import { BabyAGI } from "langchain/experimental/babyagi";import { MemoryVectorStore } from "langchain/vectorstores/memory";import { OpenAIEmbeddings, OpenAI } from "@langchain/openai";import { LLMChain } from "langchain/chains";import { ChainTool } from "langchain/tools";import { initializeAgentExecutorWithOptions } from "langchain/agents";import { PromptTemplate } from "@langchain/core/prompts";import { Tool } from "@langchain/core/tools";import { SerpAPI } from "@langchain/community/tools/serpapi";// First, we create a custom agent which will serve as execution chain.const todoPrompt = PromptTemplate.fromTemplate(  "You are a planner who is an expert at coming up with a todo list for a given objective. Come up with a todo list for this objective: {objective}");const tools: Tool[] = [  new SerpAPI(process.env.SERPAPI_API_KEY, {    location: "San Francisco,California,United States",    hl: "en",    gl: "us",  }),  new ChainTool({    name: "TODO",    chain: new LLMChain({      llm: new OpenAI({ temperature: 0 }),      prompt: todoPrompt,    }),    description:      "useful for when you need to come up with todo lists. Input: an objective to create a todo list for. Output: a todo list for that objective. Please be very clear what the objective is!",  }),];const agentExecutor = await initializeAgentExecutorWithOptions(  tools,  new OpenAI({ temperature: 0 }),  {    agentType: "zero-shot-react-description",    agentArgs: {      prefix: `You are an AI who performs one task based on the following objective: {objective}. Take into account these previously completed tasks: {context}.`,      suffix: `Question: {task}{agent_scratchpad}`,      inputVariables: ["objective", "task", "context", "agent_scratchpad"],    },  });const vectorStore = new MemoryVectorStore(new OpenAIEmbeddings());// Then, we create a BabyAGI instance.const babyAGI = BabyAGI.fromLLM({  llm: new OpenAI({ temperature: 0 }),  executionChain: agentExecutor, // an agent executor is a chain  vectorstore: vectorStore,  maxIterations: 10,});await babyAGI.invoke({  objective: "Write a short weather report for SF today",});/******TASK LIST*****1: Make a todo list*****NEXT TASK*****1: Make a todo list*****TASK RESULT*****Today in San Francisco, the weather is sunny with a temperature of 70 degrees Fahrenheit, light winds, and low humidity. The forecast for the next few days is expected to be similar.*****TASK LIST*****2: Find the forecasted temperature for the next few days in San Francisco3: Find the forecasted wind speed for the next few days in San Francisco4: Find the forecasted humidity for the next few days in San Francisco5: Create a graph showing the forecasted temperature, wind speed, and humidity for San Francisco over the next few days6: Research the average temperature for San Francisco in the past week7: Research the average wind speed for San Francisco in the past week8: Research the average humidity for San Francisco in the past week9: Create a graph showing the temperature, wind speed, and humidity for San Francisco over the past week*****NEXT TASK*****2: Find the forecasted temperature for the next few days in San Francisco*****TASK RESULT*****The forecasted temperature for the next few days in San Francisco is 63°, 65°, 71°, 73°, and 66°.*****TASK LIST*****3: Find the forecasted wind speed for the next few days in San Francisco4: Find the forecasted humidity for the next few days in San Francisco5: Create a graph showing the forecasted temperature, wind speed, and humidity for San Francisco over the next few days6: Research the average temperature for San Francisco in the past week7: Research the average wind speed for San Francisco in the past week8: Research the average humidity for San Francisco in the past week9: Create a graph showing the temperature, wind speed, and humidity for San Francisco over the past week10: Compare the forecasted temperature, wind speed, and humidity for San Francisco over the next few days to the average temperature, wind speed, and humidity for San Francisco over the past week11: Find the forecasted precipitation for the next few days in San Francisco12: Research the average wind direction for San Francisco in the past week13: Create a graph showing the forecasted temperature, wind speed, and humidity for San Francisco over the past week14: Compare the forecasted temperature, wind speed, and humidity for San Francisco over the next few days to*****NEXT TASK*****3: Find the forecasted wind speed for the next few days in San Francisco*****TASK RESULT*****West winds 10 to 20 mph. Gusts up to 35 mph in the evening. Tuesday. Sunny. Highs in the 60s to upper 70s. West winds 5 to 15 mph.*****TASK LIST*****4: Research the average precipitation for San Francisco in the past week5: Research the average temperature for San Francisco in the past week6: Research the average wind speed for San Francisco in the past week7: Research the average humidity for San Francisco in the past week8: Research the average wind direction for San Francisco in the past week9: Find the forecasted temperature, wind speed, and humidity for San Francisco over the next few days10: Find the forecasted precipitation for the next few days in San Francisco11: Create a graph showing the forecasted temperature, wind speed, and humidity for San Francisco over the next few days12: Create a graph showing the temperature, wind speed, and humidity for San Francisco over the past week13: Create a graph showing the forecasted temperature, wind speed, and humidity for San Francisco over the past month14: Compare the forecasted temperature, wind speed, and humidity for San Francisco over the next few days to the average temperature, wind speed, and humidity for San Francisco over the past week15: Compare the forecasted temperature, wind speed, and humidity for San Francisco over the next few days to the*****NEXT TASK*****4: Research the average precipitation for San Francisco in the past week*****TASK RESULT*****According to Weather Underground, the forecasted precipitation for San Francisco in the next few days is 7-hour rain and snow with 24-hour rain accumulation.*****TASK LIST*****5: Research the average wind speed for San Francisco over the past month6: Create a graph showing the forecasted temperature, wind speed, and humidity for San Francisco over the past month7: Compare the forecasted temperature, wind speed, and humidity for San Francisco over the next few days to the average temperature, wind speed, and humidity for San Francisco over the past month8: Research the average temperature for San Francisco over the past month9: Research the average wind direction for San Francisco over the past month10: Create a graph showing the forecasted precipitation for San Francisco over the next few days11: Compare the forecasted precipitation for San Francisco over the next few days to the average precipitation for San Francisco over the past week12: Find the forecasted temperature, wind speed, and humidity for San Francisco over the next few days13: Find the forecasted precipitation for the next few days in San Francisco14: Create a graph showing the temperature, wind speed, and humidity for San Francisco over the past week15: Create a graph showing the forecasted temperature, wind speed, and humidity for San Francisco over the next few days16: Compare the forecast*****NEXT TASK*****5: Research the average wind speed for San Francisco over the past month*****TASK RESULT*****The average wind speed for San Francisco over the past month is 3.2 meters per second.*****TASK LIST*****6: Find the forecasted temperature, wind speed, and humidity for San Francisco over the next few days,7: Find the forecasted precipitation for the next few days in San Francisco,8: Create a graph showing the temperature, wind speed, and humidity for San Francisco over the past week,9: Create a graph showing the forecasted temperature, wind speed, and humidity for San Francisco over the next few days,10: Compare the forecasted temperature, wind speed, and humidity for San Francisco over the next few days to the average wind speed for San Francisco over the past month,11: Research the average wind speed for San Francisco over the past week,12: Create a graph showing the forecasted precipitation for San Francisco over the next few days,13: Compare the forecasted precipitation for San Francisco over the next few days to the average precipitation for San Francisco over the past month,14: Research the average temperature for San Francisco over the past month,15: Research the average humidity for San Francisco over the past month,16: Compare the forecasted temperature, wind speed, and humidity for San Francisco over the next few days to the average temperature,*****NEXT TASK*****6: Find the forecasted temperature, wind speed, and humidity for San Francisco over the next few days,*****TASK RESULT*****The forecast for San Francisco over the next few days is mostly sunny, with a high near 64. West wind 7 to 12 mph increasing to 13 to 18 mph in the afternoon. Winds could gust as high as 22 mph. Humidity will be around 50%.*****TASK LIST*****7: Find the forecasted precipitation for the next few days in San Francisco,8: Create a graph showing the temperature, wind speed, and humidity for San Francisco over the past week,9: Create a graph showing the forecasted temperature, wind speed, and humidity for San Francisco over the next few days,10: Compare the forecasted temperature, wind speed, and humidity for San Francisco over the next few days to the average wind speed for San Francisco over the past month,11: Research the average wind speed for San Francisco over the past week,12: Create a graph showing the forecasted precipitation for San Francisco over the next few days,13: Compare the forecasted precipitation for San Francisco over the next few days to the average precipitation for San Francisco over the past month,14: Research the average temperature for San Francisco over the past month,15: Research the average humidity for San Francisco over the past month,16: Compare the forecasted temperature, wind speed, and humidity for San Francisco over the next few days to the average temperature*****NEXT TASK*****7: Find the forecasted precipitation for the next few days in San Francisco,*****TASK RESULT*****According to Weather Underground, the forecasted precipitation for the next few days in San Francisco is 7-hour rain and snow with 24-hour rain accumulation, radar and satellite maps of precipitation.*****TASK LIST*****8: Create a graph showing the temperature, wind speed, and humidity for San Francisco over the past week,9: Create a graph showing the forecasted temperature, wind speed, and humidity for San Francisco over the next few days,10: Compare the forecasted temperature, wind speed, and humidity for San Francisco over the next few days to the average wind speed for San Francisco over the past month,11: Research the average wind speed for San Francisco over the past week,12: Create a graph showing the forecasted precipitation for San Francisco over the next few days,13: Compare the forecasted precipitation for San Francisco over the next few days to the average precipitation for San Francisco over the past month,14: Research the average temperature for San Francisco over the past month,15: Research the average humidity for San Francisco over the past month,16: Compare the forecasted temperature, wind speed, and humidity for San Francisco over the next few days to the average temperature*****NEXT TASK*****8: Create a graph showing the temperature, wind speed, and humidity for San Francisco over the past week,*****TASK RESULT*****A graph showing the temperature, wind speed, and humidity for San Francisco over the past week.*****TASK LIST*****9: Create a graph showing the forecasted temperature, wind speed, and humidity for San Francisco over the next few days10: Compare the forecasted temperature, wind speed, and humidity for San Francisco over the next few days to the average wind speed for San Francisco over the past month11: Research the average wind speed for San Francisco over the past week12: Create a graph showing the forecasted precipitation for San Francisco over the next few days13: Compare the forecasted precipitation for San Francisco over the next few days to the average precipitation for San Francisco over the past month14: Research the average temperature for San Francisco over the past month15: Research the average humidity for San Francisco over the past month16: Compare the forecasted temperature, wind speed, and humidity for San Francisco over the next few days to the average temperature*****NEXT TASK*****9: Create a graph showing the forecasted temperature, wind speed, and humidity for San Francisco over the next few days*****TASK RESULT*****The forecasted temperature, wind speed, and humidity for San Francisco over the next few days can be seen in the graph created.*****TASK LIST*****10: Research the average wind speed for San Francisco over the past month11: Compare the forecasted temperature, wind speed, and humidity for San Francisco over the next few days to the average humidity for San Francisco over the past month12: Create a graph showing the forecasted precipitation for San Francisco over the next few days13: Compare the forecasted precipitation for San Francisco over the next few days to the average precipitation for San Francisco over the past month14: Research the average temperature for San Francisco over the past week15: Compare the forecasted temperature, wind speed, and humidity for San Francisco over the next few days to the average wind speed for San Francisco over the past week*****NEXT TASK*****10: Research the average wind speed for San Francisco over the past month*****TASK RESULT*****The average wind speed for San Francisco over the past month is 2.7 meters per second.[...]*/

#### API Reference:

*   [BabyAGI](https://api.js.langchain.com/classes/langchain_experimental_babyagi.BabyAGI.html) from `langchain/experimental/babyagi`
*   [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`
*   [OpenAI](https://api.js.langchain.com/classes/langchain_openai.OpenAI.html) from `@langchain/openai`
*   [LLMChain](https://api.js.langchain.com/classes/langchain_chains.LLMChain.html) from `langchain/chains`
*   ChainTool from `langchain/tools`
*   [initializeAgentExecutorWithOptions](https://api.js.langchain.com/functions/langchain_agents.initializeAgentExecutorWithOptions.html) from `langchain/agents`
*   [PromptTemplate](https://api.js.langchain.com/classes/langchain_core_prompts.PromptTemplate.html) from `@langchain/core/prompts`
*   [Tool](https://api.js.langchain.com/classes/langchain_core_tools.Tool.html) from `@langchain/core/tools`
*   [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

AutoGPT

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

Next

Code Understanding

](/v0.1/docs/use_cases/code_understanding/)

*   [Simple Example](#simple-example)
*   [Example with Tools](#example-with-tools)

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.