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

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

Let's make an AI agent!

In this tutorial, we will cover how to use LangChain with API to create a conversational AI agent that can add items to 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 board.

Table of Contents

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

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 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 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 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

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

Make sure to replace your_monday_com_api_key with your actual API key:

url = ""

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"
        return f"Request failed: {response.text}"

6. Defining a Tool to Add Items to

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

tools = [
        name="Add Item to",
        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

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"add buy peanutbutter to")

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

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

With this, you have successfully created a conversational AI agent that can add items to a 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 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 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