Overview
The LangChain JS integration enables you to use Stagehand with LangChain to create intelligent agents that can automate web interactions. This integration provides:- StagehandToolkit with LangChain-compatible tools
- AI-driven research and data extraction workflows
- Dynamic form filling based on contextual requirements
- Multi-step web processes with decision-making capabilities
Installation
Install the required packages for LangChain JS and Stagehand integration:Quick Start
1. Configure Environment Variables
For remote browser automation, set up your Browserbase credentials:2. Initialize Stagehand
Create a Stagehand instance with your preferred configuration:3. Create the StagehandToolkit
Generate the toolkit that provides LangChain-compatible tools:4. Available Tools
The toolkit provides four specialized tools for web automation:- stagehand_navigate: Navigate to specific URLs
- stagehand_act: Perform browser actions (clicking, typing, etc.)
- stagehand_extract: Extract structured data using schemas
- stagehand_observe: Analyze page elements and possible actions
Basic Usage
Individual Tool Usage
LangGraph Integration
Integrate with LangGraph for complex automation workflows:Using Custom LLM Clients
Stagehand supports using LangChain models as LLM clients:Example Workflows
Data Extraction Workflow
Form Automation Workflow
Multi-Site Research Workflow
Error Handling
Advanced Configuration
When to Use This Integration
The LangChain JS integration is perfect for:- AI-driven research: Create agents that research information across multiple websites
- Dynamic form filling: Automatically fill complex forms based on context
- Data extraction workflows: Extract and transform data from multiple sources
- Multi-step web processes: Execute complex workflows requiring decision-making
Resources
LangChain JS Documentation
Official LangChain JS documentation for Stagehand
Agent Reference
Learn about Stagehand’s Agent API
Extract Reference
Learn about data extraction
Act Reference
Learn about browser actions