LangChain
Add human-in-the-loop capabilities to your LangChain agents.
Prerequisites
- A LangChain project (Python or JavaScript)
- A RelayRail account with an API key
- MCP support in your agent framework
Integration Approach
LangChain can integrate with RelayRail in two ways:
1. MCP Tool Integration
If your LangChain setup supports MCP, add RelayRail as an MCP server:
# Start the RelayRail MCP server
npx @relayrail/server start
# Configure your LangChain agent to use MCP tools2. HTTP API Integration
For custom integrations, use the RelayRail HTTP API directly:
import requests
def request_approval(message: str) -> dict:
response = requests.post(
"https://relayrail.dev/api/mcp/request-approval",
headers={
"Authorization": f"Bearer {RELAYRAIL_API_KEY}"
},
json={
"message": message,
"type": "yes_no"
}
)
return response.json()LangChain Tool Example
Create a custom LangChain tool for approvals:
from langchain.tools import BaseTool
from typing import Optional
class HumanApprovalTool(BaseTool):
name = "human_approval"
description = "Request human approval via SMS/email"
def _run(self, message: str) -> str:
result = request_approval(message)
if result.get("approved"):
return "Approved"
return "Denied"
# Add to your agent
tools = [HumanApprovalTool(), ...]
agent = create_agent(llm, tools)Use Cases
- -ReAct agents - Add approval steps between reasoning and action
- -Autonomous agents - Gate critical actions with human oversight
- -Data pipelines - Notify on completion or errors