Overview

Humanlayer integrates seamlessly with LangChain to add human oversight to your AI applications. This guide shows you how to use Humanlayer with LangChain.

Installation

Install the required packages:

pip install humanlayer langchain langchain-openai python-dotenv

Basic Example

Let’s create a customer onboarding assistant that sends emails with human oversight.

How it Works

  1. We create a HumanLayer instance with a Slack contact channel for approvals
  2. Define two functions:
    • get_info_about_customer: Gets customer onboarding status
    • send_email: Sends an email (requires approval)
  3. Create LangChain tools from these functions
  4. Initialize a LangChain agent with the tools
  5. The agent will request approval before sending any emails

Running the Example

  1. Set up your environment variables in .env
  2. Configure your Slack channel ID in the contact_channel
  3. Run the example:
python main.py

When the agent attempts to send an email, it will pause and request approval through Slack.

Next Steps

For more framework examples, see https://github.com/humanlayer/humanlayer/tree/main/examples