HumanLayer integration for LangGraph
Project description
HumanLayer for LangGraph
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
-
Clone the repository:
git clone https://github.com/humanlayer/humanlayer-langgraph-alpha.git cd humanlayer-langgraph-alpha
-
Create a virtual environment and install development dependencies:
make setup-dev -
Run the tests:
make test
Development Commands
make format: Format code with blackmake lint: Run linters (ruff, mypy)make test: Run testsmake run-examples: Run example scriptsmake clean: Clean build artifactsmake build: Build package
Publishing
Local Publishing
To release a new version:
-
Bump the version (patch, minor, or major):
make bump-patch # or bump-minor, bump-major
-
Build and publish:
make publish # or publish-test for TestPyPI
GitHub Actions
This package uses GitHub Actions to automate the release process:
- Go to the "Actions" tab in the GitHub repository
- Select the "Publish Package" workflow
- Click "Run workflow"
- Select the release type (patch, minor, or major)
- 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file humanlayer_langgraph_alpha-0.1.0.tar.gz.
File metadata
- Download URL: humanlayer_langgraph_alpha-0.1.0.tar.gz
- Upload date:
- Size: 13.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1ea685f5d4255728056e0b93517f77dc18b5b8a4fbf9cbc7a1cbea11070d3767
|
|
| MD5 |
0f5c02bbd1c6d439a52adf7bffb00c22
|
|
| BLAKE2b-256 |
809a08317c3ca7695c76f630844a4ea48470cc2babd941851216ad90571d924b
|
File details
Details for the file humanlayer_langgraph_alpha-0.1.0-py3-none-any.whl.
File metadata
- Download URL: humanlayer_langgraph_alpha-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
20108f75334826ca9daa675b31e8ab7d270dad92989a264100f97de5b7845e69
|
|
| MD5 |
f991899a7b3916fa1211217a19111e6a
|
|
| BLAKE2b-256 |
1b75cac3350e4a9642f9805d0b32e6cdd83f03a89f0a22efb01752f6849bf01a
|