Skip to main content

HumanLayer integration for LangGraph

Project description

HumanLayer for LangGraph

PyPI version License: MIT

An integration package for using HumanLayer with LangGraph to build human-in-the-loop agents.

Installation

pip install humanlayer-langgraph-alpha

Features

  • Seamlessly integrate HumanLayer with LangGraph agents
  • Log tool calls and results to HumanLayer
  • Request human approval for critical actions
  • Collect human input within agent workflows
  • Build complete human-in-the-loop subgraphs

Quick Start

from humanlayer import HumanLayer
from humanlayer_langgraph import build_humanlayer_subgraph
from langchain_core.tools import tool
from langgraph.graph import StateGraph
from langgraph.graph import MessagesState

# Initialize HumanLayer
hl = HumanLayer(run_id="my-agent-run")

# Define your tools
@tool
def get_weather(location: str):
    """Get the current weather for a location."""
    return f"The weather in {location} is sunny."

# Build your graph
graph_builder = StateGraph(MessagesState)

# Create a HumanLayer-integrated tool node
tools_node = build_humanlayer_subgraph([get_weather], hl)

# Add the node to your graph
graph_builder.add_node("tools", tools_node)

Human Approval Workflows

For critical actions, you can require human approval:

from humanlayer_langgraph import create_human_approval_node

# Create a node that requires human approval
approval_node = create_human_approval_node(
    human_layer=hl,
    message_template="Please approve this action: {action}",
    timeout=300  # 5 minutes
)

# Add the node to your graph
graph_builder.add_node("human_approval", approval_node)

# Add conditional edges
graph_builder.add_conditional_edges(
    "chatbot",
    lambda state: "requires_approval" if needs_approval(state) else "direct_execution",
    {
        "requires_approval": "human_approval",
        "direct_execution": "tools"
    }
)

Human Input Collection

Collect input from humans during agent execution:

from humanlayer_langgraph import create_human_input_node

# Create a node that requests human input
input_node = create_human_input_node(
    human_layer=hl,
    prompt_template="Please provide input: {prompt}",
    timeout=300
)

# Add the node to your graph
graph_builder.add_node("human_input", input_node)

Examples

See the examples/ directory for complete examples of HumanLayer integration with LangGraph. You can run the examples with:

make run-examples

Development

Setting Up Development Environment

  1. Clone the repository:

    git clone https://github.com/humanlayer/humanlayer-langgraph-alpha.git
    cd humanlayer-langgraph-alpha
    
  2. Create a virtual environment and install development dependencies:

    make setup-dev
    
  3. Run the tests:

    make test
    

Development Commands

  • make format: Format code with black
  • make lint: Run linters (ruff, mypy)
  • make test: Run tests
  • make run-examples: Run example scripts
  • make clean: Clean build artifacts
  • make build: Build package

Publishing

Local Publishing

To release a new version:

  1. Bump the version (patch, minor, or major):

    make bump-patch  # or bump-minor, bump-major
    
  2. Build and publish:

    make publish  # or publish-test for TestPyPI
    

GitHub Actions

This package uses GitHub Actions to automate the release process:

  1. Go to the "Actions" tab in the GitHub repository
  2. Select the "Publish Package" workflow
  3. Click "Run workflow"
  4. Select the release type (patch, minor, or major)
  5. Click "Run workflow"

The action will:

  • Run tests
  • Bump the version
  • Build the package
  • Push the new tag
  • Publish to PyPI

Documentation

Full documentation is available at docs.humanlayer.com.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

humanlayer_langgraph_alpha-0.1.0.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

humanlayer_langgraph_alpha-0.1.0-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file humanlayer_langgraph_alpha-0.1.0.tar.gz.

File metadata

File hashes

Hashes for humanlayer_langgraph_alpha-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1ea685f5d4255728056e0b93517f77dc18b5b8a4fbf9cbc7a1cbea11070d3767
MD5 0f5c02bbd1c6d439a52adf7bffb00c22
BLAKE2b-256 809a08317c3ca7695c76f630844a4ea48470cc2babd941851216ad90571d924b

See more details on using hashes here.

File details

Details for the file humanlayer_langgraph_alpha-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for humanlayer_langgraph_alpha-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 20108f75334826ca9daa675b31e8ab7d270dad92989a264100f97de5b7845e69
MD5 f991899a7b3916fa1211217a19111e6a
BLAKE2b-256 1b75cac3350e4a9642f9805d0b32e6cdd83f03a89f0a22efb01752f6849bf01a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page