Skip to main content
Integrate Skyvern with LangChain to give your AI agents the ability to interact with websites, fill forms, and extract data from the web.

Overview

The Skyvern LangChain integration provides tools that allow LangChain agents to perform browser automation. Your agents can:
  • Navigate websites and interact with web pages
  • Fill out and submit forms automatically
  • Extract structured data from websites
  • Download files from web portals
  • Complete multi-step web workflows

Installation

pip install skyvern-langchain
For the full LangChain experience, also install:
pip install langchain-openai
pip install langchain-community

Quick Start

There are two ways to use Skyvern with LangChain:
  1. Agent Mode (local): Run tasks locally using skyvern init
  2. Client Mode (API): Call Skyvern Cloud APIs

Agent Mode (Local)

Agent mode requires running skyvern init first to set up your local Skyvern environment.
import asyncio
from skyvern_langchain.agent import RunTask

run_task = RunTask()

async def main():
    result = await run_task.ainvoke(
        "Navigate to the Hacker News homepage and get the top 3 posts."
    )
    print(result)

if __name__ == "__main__":
    asyncio.run(main())

Client Mode (API)

No local setup required. Uses Skyvern Cloud.
import asyncio
from skyvern_langchain.client import RunTask

run_task = RunTask(
    api_key="<your_skyvern_api_key>"
)
# Or load from SKYVERN_API_KEY environment variable:
# run_task = RunTask()

async def main():
    result = await run_task.ainvoke(
        "Navigate to the Hacker News homepage and get the top 3 posts."
    )
    print(result)

if __name__ == "__main__":
    asyncio.run(main())

Available Tools

The integration provides three main tools for LangChain agents:

RunTask

Runs a task synchronously and waits for completion. Usage:
from skyvern_langchain.agent import RunTask  # or .client

run_task = RunTask()
result = await run_task.ainvoke("Your task description here")
Input: Natural language description of the task Output: Task results including extracted data

DispatchTask

Starts a task asynchronously and returns immediately. Usage:
from skyvern_langchain.agent import DispatchTask  # or .client

dispatch_task = DispatchTask()
result = await dispatch_task.ainvoke("Your task description here")
print(result['task_id'])  # Task is running in background
Input: Natural language description of the task Output: Task ID and initial status
When running locally, keep your script running until the task completes, or it will be terminated.

GetTask

Retrieves the status and results of a previously dispatched task. Usage:
from skyvern_langchain.agent import GetTask  # or .client

get_task = GetTask()
result = await get_task.ainvoke("<task_id>")
print(result['status'])
Input: Task ID Output: Task status, extracted data, and results

Agent Integration

For a complete AI agent experience, combine Skyvern tools with LangChain agents.

Example: Agent with Polling

This agent dispatches a task, waits for completion, and returns results.
import asyncio
from dotenv import load_dotenv
from langchain_openai import ChatOpenAI
from langchain.agents import initialize_agent, AgentType
from skyvern_langchain.agent import DispatchTask, GetTask
from langchain_community.tools.sleep.tool import SleepTool

load_dotenv()

llm = ChatOpenAI(model="gpt-4o", temperature=0)

dispatch_task = DispatchTask()
get_task = GetTask()

agent = initialize_agent(
    llm=llm,
    tools=[
        dispatch_task,
        get_task,
        SleepTool(),
    ],
    verbose=True,
    agent=AgentType.STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION,
)

async def main():
    prompt = (
        "Run a task with Skyvern. The task is about 'Navigate to the Hacker News "
        "homepage and get the top 3 posts.' Then, get this task information until "
        "it's completed. The task information re-get interval should be 60s."
    )
    result = await agent.ainvoke(prompt)
    print(result)

if __name__ == "__main__":
    asyncio.run(main())

Example: API-Based Agent

Using Skyvern Cloud API (no local setup needed):
import asyncio
from dotenv import load_dotenv
from langchain_openai import ChatOpenAI
from langchain.agents import initialize_agent, AgentType
from skyvern_langchain.client import DispatchTask, GetTask
from langchain_community.tools.sleep.tool import SleepTool

load_dotenv()

llm = ChatOpenAI(model="gpt-4o", temperature=0)

# Initialize with API key
dispatch_task = DispatchTask(
    api_key="<your_skyvern_api_key>"
)
get_task = GetTask(
    api_key="<your_skyvern_api_key>"
)
# Or load from environment: DispatchTask() and GetTask()

agent = initialize_agent(
    llm=llm,
    tools=[
        dispatch_task,
        get_task,
        SleepTool(),
    ],
    verbose=True,
    agent=AgentType.STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION,
)

async def main():
    prompt = (
        "Run a task with Skyvern. The task is about 'Navigate to the Hacker News "
        "homepage and get the top 3 posts.' Then, get this task information until "
        "it's completed. The task information re-get interval should be 60s."
    )
    result = await agent.ainvoke(prompt)
    print(result)

if __name__ == "__main__":
    asyncio.run(main())

Local vs. API Mode

Agent Mode (Local)

Import from: skyvern_langchain.agent Setup required:
skyvern init
Pros:
  • Full control over Skyvern instance
  • No API usage limits
  • Can use custom LLM providers
Cons:
  • Requires local setup and maintenance
  • Must keep process running for async tasks

Client Mode (API)

Import from: skyvern_langchain.client Setup required: Just an API key from app.skyvern.com Pros:
  • No local setup needed
  • Tasks run in the cloud
  • Managed infrastructure
Cons:
  • Requires API key
  • Subject to API rate limits
  • Usage-based pricing

Use Cases

Research Assistant

An agent that gathers competitive intelligence:
from langchain_openai import ChatOpenAI
from langchain.agents import initialize_agent, AgentType
from skyvern_langchain.client import RunTask

llm = ChatOpenAI(model="gpt-4o")
run_task = RunTask(api_key="your_api_key")

agent = initialize_agent(
    llm=llm,
    tools=[run_task],
    agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
    verbose=True
)

result = agent.run(
    "Research the top 3 competitors in the project management space. "
    "For each, find their pricing and main features."
)

Form Automation Assistant

Automate form submissions based on user input:
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain
from skyvern_langchain.client import RunTask

run_task = RunTask()

async def submit_application(user_data):
    task_description = f"""
    Navigate to the job application form and fill it out with:
    - Name: {user_data['name']}
    - Email: {user_data['email']}
    - Phone: {user_data['phone']}
    - Resume: Upload from {user_data['resume_path']}
    Then submit the form.
    """
    
    result = await run_task.ainvoke(task_description)
    return result

Data Collection Pipeline

Extract data from multiple sources:
from langchain.agents import initialize_agent
from skyvern_langchain.client import DispatchTask, GetTask

dispatch = DispatchTask(api_key="your_key")
get = GetTask(api_key="your_key")

agent = initialize_agent(
    llm=ChatOpenAI(model="gpt-4o"),
    tools=[dispatch, get, SleepTool()],
    agent=AgentType.STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION,
)

result = agent.run(
    "Extract product data from these 3 e-commerce sites: [urls]. "
    "Wait for all tasks to complete and compile the results."
)

Tips and Best Practices

Be specific in task descriptions: The more detailed your instructions, the better the results.
Use structured prompts: When building agents, guide them with clear instructions about when to use Skyvern tools.
  • Handle async properly: Always use await with async tool invocations
  • Set appropriate timeouts: For long-running tasks, increase polling intervals
  • Check task status: Always verify task completion before using results
  • Store task IDs: Keep track of task IDs for debugging and monitoring
  • Use environment variables: Store API keys in .env files, not in code

Common Issues

ImportError: No module named ‘skyvern_langchain’

Install the package:
pip install skyvern-langchain

Local mode fails: “Skyvern not initialized”

Run the initialization command:
skyvern init

API mode: Authentication failed

Verify your API key:
  • Check it’s from app.skyvern.com/settings
  • Ensure no extra whitespace
  • Try setting SKYVERN_API_KEY environment variable

Task never completes

  • Increase wait time between status checks
  • Check the task manually in the Skyvern dashboard
  • Verify the navigation goal is achievable

Advanced Usage

For more advanced patterns and examples, see:

Support

For LangChain integration help:

Next Steps

Creating Tasks

Learn how to write effective task instructions

Data Extraction

Extract structured data from websites

LlamaIndex Integration

Integrate with LlamaIndex instead

API Reference

Full Skyvern API documentation

Build docs developers (and LLMs) love