How to Integrate Robocorp with Langchain: A Step-by-Step Guide

Gary Svenson
7 min readSep 26, 2024

--

how to integrate robocorp with langchain

Let’s talk about something that we all face during development: API Testing with Postman for your Development Team.

Yeah, I’ve heard of it as well, Postman is getting worse year by year, but, you are working as a team and you need some collaboration tools for your development process, right? So you paid Postman Enterprise for…. $49/month.

Now I am telling you: You Don’t Have to:

That’s right, APIDog gives you all the features that comes with Postman paid version, at a fraction of the cost. Migration has been so easily that you only need to click a few buttons, and APIDog will do everything for you.

APIDog has a comprehensive, easy to use GUI that makes you spend no time to get started working (If you have migrated from Postman). It’s elegant, collaborate, easy to use, with Dark Mode too!

Want a Good Alternative to Postman? APIDog is definitely worth a shot. But if you are the Tech Lead of a Dev Team that really want to dump Postman for something Better, and Cheaper, Check out APIDog!

How to Integrate Robocorp with LangChain

Integrating Robocorp with LangChain allows developers to leverage the capabilities of both platforms for intelligent, automated solutions. Robocorp provides an RPA (Robotic Process Automation) framework while LangChain focuses on developing frameworks for language models. This essay presents a comprehensive guide detailing the integration process step-by-step.

Understanding Robocorp and LangChain

Robocorp Overview

Robocorp is an open-source automation framework that simplifies the development of bots to automate repetitive tasks. Developers can create these bots using Python, which makes it accessible for a wide range of programmers. Robocorp offers a robust set of tools, including:

  • RPA Framework: A library of reusable components specifically designed for RPA tasks.
  • Robocorp Lab: An IDE (Integrated Development Environment) for building, testing, and debugging bots.
  • Cloud Automation: Tools to run automation in the cloud, facilitating scalability and accessibility.

LangChain Overview

LangChain is a powerful framework designed for developing applications powered by language models. It allows developers to create language model-driven workflows, utilities, and applications. Key components of the LangChain framework include:

  • Chains: Sequences of calls to various tools or APIs.
  • Agents: Dynamic systems that can execute various calls based on the changing inputs.
  • Memory: The capability to maintain context over multiple interactions.

Prerequisites for Integration

Before diving into the integration steps, ensure you have the following prerequisites:

  1. Development Environment: Both Robocorp and LangChain require Python. You should have Python 3.8 or higher installed.
  2. Robocorp Account: Create an account on the Robocorp platform to utilize their RPA capabilities.
  3. LangChain Library: Install the LangChain library via pip. Execute:
  • pip install langchain
  1. Robocorp RPA Framework: Clone or install the Robocorp RPA framework. Follow the installation guide found in the Robocorp documentation.
  2. Familiarity with APIs: Understanding how to interact with APIs is crucial for effectively integrating the two platforms.

Step 1: Setting Up Your Project Directory

To get started, create a new directory for your project. This organization allows you to manage your files systematically.

mkdir robocorp-langchain-integration
cd robocorp-langchain-integration

Within this directory, create a separate folder for the Robocorp bot and the LangChain application.

mkdir robocorp_bot
mkdir langchain_app

Step 2: Building a Basic Robocorp Bot

In this step, we will create a simple bot with Robocorp that can perform an automated task. For demonstration purposes, let’s build a bot that scrapes information from a website.

  1. Navigate to the Robocorp folder:
  • cd robocorp_bot
  1. Create a new Robocorp bot: Within this folder, create a new robot.py file:
  • from RPA.Browser.Selenium import Selenium def run(): browser = Selenium() browser.open_chrome('https://example.com') title = browser.get_title() print(f'Page title is: {title}') browser.close_chrome()
  1. Adjust Configuration: You’ll need a robot.yaml file to provide configuration settings for the bot. Here’s an example configuration:
  • tasks: - task: run
  1. Test the Bot: Run the bot locally using Robocorp Lab or the command line to ensure it functions correctly. This automation will scrape the title from the specified webpage.

Step 3: Creating a LangChain Application

Now, we will create a LangChain application that makes use of language models to process input and provide intelligent insights.

  1. Navigate to the LangChain folder:
  • cd ../langchain_app
  1. Create a new Python script for LangChain: Create a main.py file.
  • from langchain import LLMChain from langchain.llms import OpenAI def query_langchain(input_text): llm = OpenAI(temperature=0.7) chain = LLMChain(llm=llm) response = chain.run(input_text) return response
  1. Set Up OpenAI API Credentials: Ensure you have API keys to access OpenAI services and set them in your environment variables.
  • export OPENAI_API_KEY='your_api_key_here'
  1. Run the LangChain Application: You can test the application by calling the query_langchain function with sample inputs. This interaction provides a hands-on experience with the capabilities of language models.
  • if __name__ == "__main__": input_query = "What is the purpose of RPA?" output = query_langchain(input_query) print(output)

Step 4: Establishing Communication between Robocorp and LangChain

Now, we will establish a communication channel so that the outputs from Robocorp can be sent to LangChain for further processing and insights.

Using Files for Communication

The simplest method to facilitate communication is to use files. The Robocorp bot will write its output to a text file, and the LangChain app will read from this file.

  1. Modify the Robocorp Bot: Update the run() function in the robot.py file to save output to a text file.
  • def run(): browser = Selenium() browser.open_chrome('https://example.com') title = browser.get_title() print(f'Page title is: {title}') # Write to file with open('output.txt', 'w') as f: f.write(title) browser.close_chrome()
  1. Read File in LangChain Application: Update the main.py file to read from the output.txt and utilize LangChain to generate insights based on the information from the file.
  • def read_output_file(): with open('output.txt', 'r') as file: return file.read().strip() if __name__ == "__main__": title_from_robot = read_output_file() output = query_langchain(title_from_robot) print(output)

Step 5: Running the Integrated Solution

Now that we have modified both the Robocorp bot and the LangChain application to communicate through a text file, we can run both components.

  1. Execute the Robocorp Bot: Run the bot using Robocorp Lab or the command line. This will collect the desired output and write it to output.txt.
  • robocorp run
  1. Run the LangChain Application: After the bot has successfully finished, switch to the LangChain directory and execute the main.py script.
  • python main.py

You should see the title from the webpage printed out along with any intelligent response from the LangChain model.

Step 6: Optimizing the Integration

While the integration outlined above functions as expected, optimization can significantly improve performance and efficiency.

Using REST API for Communication

Instead of relying on file I/O, you could establish a more sophisticated integration using a RESTful API. This method involves hosting the LangChain application on a web server, allowing the Robocorp bot to make HTTP requests directly.

  1. Create a Simple Flask App for LangChain: Instead of running LangChain as a local script, package it as a RESTful API using Flask or FastAPI.
  • from flask import Flask, request, jsonify from langchain import LLMChain from langchain.llms import OpenAI app = Flask(__name__) @app.route('/query', methods=['POST']) def query(): input_data = request.json.get('input') llm = OpenAI(temperature=0.7) chain = LLMChain(llm=llm) response = chain.run(input_data) return jsonify({'response': response}) if __name__ == "__main__": app.run(port=5000)
  1. Modify Robocorp to Make HTTP Requests: Update the Robocorp bot to send HTTP POST requests instead of writing to a file.
  • import requests def send_to_langchain(title): response = requests.post("http://localhost:5000/query", json={"input": title}) return response.json()
  1. Integrate the Communication: Now, in the run() function, immediately after fetching the title, send the response to the Flask app.
  • def run(): browser = Selenium() browser.open_chrome('https://example.com') title = browser.get_title() print(f'Page title is: {title}') # Send to LangChain langchain_response = send_to_langchain(title) print(langchain_response) browser.close_chrome()

By implementing these steps, you facilitate a more real-time interaction between Robocorp and LangChain.

Conclusion

In conclusion, integrating Robocorp with LangChain involves building a bot for RPA tasks, setting up a LangChain application for language processing, and establishing communication channels between them. Developers can refine their solutions further by utilizing advanced techniques such as RESTful APIs to optimize performance. The integration opens new avenues for creating intelligent, automated workflows, effectively merging the potential of RPA with the power of language models.

Let’s talk about something that we all face during development: API Testing with Postman for your Development Team.

Yeah, I’ve heard of it as well, Postman is getting worse year by year, but, you are working as a team and you need some collaboration tools for your development process, right? So you paid Postman Enterprise for…. $49/month.

Now I am telling you: You Don’t Have to:

That’s right, APIDog gives you all the features that comes with Postman paid version, at a fraction of the cost. Migration has been so easily that you only need to click a few buttons, and APIDog will do everything for you.

APIDog has a comprehensive, easy to use GUI that makes you spend no time to get started working (If you have migrated from Postman). It’s elegant, collaborate, easy to use, with Dark Mode too!

Want a Good Alternative to Postman? APIDog is definitely worth a shot. But if you are the Tech Lead of a Dev Team that really want to dump Postman for something Better, and Cheaper, Check out APIDog!

--

--