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
Create a Stagehand instance with your preferred configuration:
import { Stagehand } from "@browserbasehq/stagehand";// For local developmentconst stagehand = new Stagehand({ env: "LOCAL", verbose: 2, enableCaching: false,});// For production with Browserbaseconst stagehand = new Stagehand({ env: "BROWSERBASE", verbose: 1, enableCaching: true,});
Integrate with LangGraph for complex automation workflows:
import { createReactAgent } from "@langchain/langgraph/prebuilt";import { ChatOpenAI } from "@langchain/openai";// Create an LLMconst llm = new ChatOpenAI({ model: "gpt-4", temperature: 0,});// Create an agent with Stagehand toolsconst agent = createReactAgent({ llm, tools: stagehandToolkit.tools,});// Execute a complex workflowconst result = await agent.invoke({ messages: [ { role: "user", content: "Go to example.com, find the contact form, and extract all the form fields" } ]});
const formAgent = createReactAgent({ llm, tools: stagehandToolkit.tools,});const result = await formAgent.invoke({ messages: [{ role: "user", content: ` Navigate to contact-form.com and: 1. Fill out the contact form with: - Name: John Doe - Email: john@example.com - Message: Inquiry about services 2. Submit the form 3. Confirm submission success ` }]});