Skip to main content
This guide walks you through integrating Stagehand with LangChain JS to build powerful web automation workflows using natural language instructions.

Step 1: Install Dependencies

Install the required packages for LangChain JS and Stagehand integration:

Step 2: Configure Environment Variables

For remote browser automation, set up your Browserbase credentials:

Step 3: Create a Stagehand Instance

Initialize Stagehand with your preferred configuration:

Step 4: Generate the StagehandToolkit

Create the toolkit that provides LangChain-compatible tools:

Step 5: Use Individual Tools

The toolkit provides four specialized tools for web automation:

Available Tools

  • 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 Tool Usage

Step 6: Build LangGraph Agents

Integrate with LangGraph for complex automation workflows:

Advanced Configuration

Custom Stagehand Configuration

Error Handling

Example Workflows

LangChain JS Documentation

Official LangChain JS documentation for the Stagehand integration