Overview

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

Installation

Install the required packages:

pip install humanlayer controlflow python-dotenv

Basic Example

Let’s create a simple math agent that performs basic arithmetic operations with human oversight.

from dotenv import load_dotenv
from humanlayer import HumanLayer
import controlflow as cf

load_dotenv()

hl = HumanLayer(
    # run_id is optional - it can be used to identify the agent in approval history
    run_id="controlflow-math",
)

def add(x: int, y: int) -> int:
    """Add two numbers together."""
    return x + y

@hl.require_approval()  # require user approval before this function can be called
def multiply(x: int, y: int) -> int:
    """multiply two numbers"""
    return x * y

@cf.task(tools=[add, multiply])
def do_math() -> int:
    """multiply 2 and 5, then add 32 to the result"""

if __name__ == "__main__":
    result = do_math()
    print("\n\n---------- RESULT ----------\n\n")
    print(result)

How it Works

  1. We create a HumanLayer instance with an optional run_id to identify this agent in the approval history
  2. Define two math functions: add and multiply
  3. Use @hl.require_approval() to require human approval before the multiply function can be called
  4. Create a ControlFlow task that uses these functions as tools
  5. The agent will request approval before executing the multiply function

Running the Example

  1. Set up your environment variables in .env
  2. Run the example:
python main.py

When the agent attempts to use the multiply function, it will pause and request human approval through your configured contact channel (Slack, Email, etc).

Next Steps

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