Monday Tutorial: Using LangChain to Add Items to Monday.com: A Comprehensive Tutorial

Monday, June 12, 2023 by ezzcodeezzlife
Monday Tutorial: Using LangChain to Add Items to Monday.com: A Comprehensive Tutorial

Let's make an AI agent!

In this tutorial, we will cover how to use LangChain with Monday.com API to create a conversational AI agent that can add items to Monday.com. We will walk through the process step-by-step, starting with installing necessary packages and ending with testing the agent's ability to add items to a Monday.com board.

Table of Contents

  • Introduction
  • Installing Packages
  • Importing Necessary Components
  • Setting up ChatOpenAI
  • Creating a Function to Add Items in Monday.com
  • Defining a Tool to Add Items to Monday.com
  • Initializing the Agent
  • Testing the Agent with Adding Items to Monday.com

1. Introduction

Automations are getting more advanced. One such implementation is to create conversational AI agents that can add tasks to project management tools like Monday.com by simply sending a message to the agent. In this tutorial, we will demonstrate the process of creating such an AI agent using LangChain and Monday.com API.

2. Installing Packages

First, we need to install the required packages langchain and openai. To do this, run the following command in your Python environment:

pip install langchain openai

3. Importing Necessary Components

Next, import the required components for this tutorial.

from langchain import LLMMathChain, SerpAPIWrapper
from langchain.agents import AgentType, initialize_agent
from langchain.chat_models import ChatOpenAI
from langchain.tools import BaseTool, StructuredTool, Tool, tool
import requests
import json

4. Setting up OpenAI

Now, set up a ChatOpenAI object to train our AI agent using the GPT-3.5 model from OpenAI.

Replace your_openai_api_key with your actual OpenAI API key:

llm = ChatOpenAI(temperature=0, openai_api_key="your_openai_api_key")

5. Creating a Function to Add Items in Monday.com

In this step, we will create a function called add_Item that uses the Monday.com API and takes a query as input. This query represents the name of the item we want to add to the board in Monday.com.

Make sure to replace your_monday_com_api_key with your actual Monday.com API key:

url = "https://api.monday.com/v2"

headers = {
  'Authorization': 'your_monday_com_api_key',
  'Content-Type': 'application/json'
}

def add_Item(query: str) -> str:

    payload = json.dumps({
        "query": f"mutation {{create_item (board_id: 123, group_id: \"topics\", item_name: \"{query}\") {{id}}}}"
    })

    response = requests.request("POST", url, headers=headers, data=payload)
    
    if response.status_code == 200:
        return "Item added successfully"
    else:
        return f"Request failed: {response.text}"

6. Defining a Tool to Add Items to Monday.com

Now, define a Tool that uses the add_Item function to add items to Monday.com. This Tool can be used by the AI agent we will create later:

tools = [
    Tool.from_function(
        func=add_Item,
        name="Add Item to Monday.com",
        description="Useful for when you need to add a new item to Monday, input is the name of the new item",
    ),
]

7. Initializing the Agent

It's time to initialize the AI agent with the tools we prepared earlier. We'll use the initialize_agent function to create an AI agent capable of performing our desired action:

agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True)

8. Testing the Agent with Adding Items to Monday.com

Finally, to test our AI agent, we'll run the following command that instructs the agent to add a new item with the name "buy peanut butter" to Monday.com:

agent.run("add buy peanutbutter to monday.com")

If everything works as expected, you should see an output similar to:

> Entering new AgentExecutor chain...
I need to use the 'Add Item to Monday.com' tool to add this task to the board.
Action: Add Item to Monday.com
Action Input: 'buy peanutbutter'
Observation: Item added successfully

With this, you have successfully created a conversational AI agent that can add items to a Monday.com board.

Remember to replace your_openai_api_key and your_monday_com_api_key with your corresponding API keys, and update the board_id and group_id in the add_Item function as necessary to match your specific Monday.com configuration.

You could now add more tools to create boards, delete items or much much more! Check out the monday API docs for fore functionalities. The API Playground is also great to test out your ideas.

Ready to flex your skills?

Join an exhilarating AI Hackathon where you'll collaborate with creative minds from across the globe to develop breathtaking apps in just days! Gear up for the upcoming Monday.com AI Hackathon, where you'll craft ingenious AI apps and access customers via the Monday App Market.

Transform the world with AI!

Thank you! If you enjoyed this tutorial you can find more and continue reading on our tutorial page - Fabian Stehle, Developer at New Native

Discover tutorials with similar technologies

Upcoming AI Hackathons and Events