Skip to main content
Integrate Skyvern with LlamaIndex to enhance your AI agents with browser automation capabilities.

Overview

The Skyvern LlamaIndex integration provides tools that enable LlamaIndex agents to:
  • Interact with websites and web applications
  • Fill out and submit forms programmatically
  • Extract structured data from web pages
  • Automate multi-step web workflows
  • Download files from web portals

Installation

pip install skyvern-llamaindex

Quick Start

Like the LangChain integration, Skyvern LlamaIndex supports two modes:
  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.
from dotenv import load_dotenv
from llama_index.agent.openai import OpenAIAgent
from llama_index.llms.openai import OpenAI
from skyvern_llamaindex.agent import SkyvernTool

load_dotenv()

skyvern_tool = SkyvernTool()

agent = OpenAIAgent.from_tools(
    tools=[skyvern_tool.run_task()],
    llm=OpenAI(model="gpt-4o"),
    verbose=True,
)

response = agent.chat(
    "Run a task with Skyvern. The task is about 'Navigate to the Hacker News "
    "homepage and get the top 3 posts.'"
)
print(response)

Client Mode (API)

No local setup required. Uses Skyvern Cloud.
from dotenv import load_dotenv
from llama_index.agent.openai import OpenAIAgent
from llama_index.llms.openai import OpenAI
from skyvern_llamaindex.client import SkyvernTool

load_dotenv()

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

agent = OpenAIAgent.from_tools(
    tools=[skyvern_tool.run_task()],
    llm=OpenAI(model="gpt-4o"),
    verbose=True,
)

response = agent.chat(
    "Run a task with Skyvern. The task is about 'Navigate to the Hacker News "
    "homepage and get the top 3 posts.'"
)
print(response)

Available Tools

The SkyvernTool class provides three tool methods:

run_task()

Runs a task synchronously and waits for completion. Usage:
skyvern_tool = SkyvernTool()
run_task_tool = skyvern_tool.run_task()

agent = OpenAIAgent.from_tools(
    tools=[run_task_tool],
    llm=OpenAI(model="gpt-4o"),
)

response = agent.chat("Extract the top posts from Hacker News")
Input: Natural language task description Output: Task results including extracted data

dispatch_task()

Starts a task asynchronously and returns immediately. Usage:
import asyncio
from llama_index.core.tools import FunctionTool

async def sleep(seconds: int) -> str:
    await asyncio.sleep(seconds)
    return f"Slept for {seconds} seconds"

sleep_tool = FunctionTool.from_defaults(
    async_fn=sleep,
    description="Sleep for a given number of seconds",
    name="sleep",
)

skyvern_tool = SkyvernTool()

agent = OpenAIAgent.from_tools(
    tools=[skyvern_tool.dispatch_task(), sleep_tool],
    llm=OpenAI(model="gpt-4o"),
)

response = agent.chat(
    "Run a task with Skyvern. The task is about 'Navigate to the Hacker News "
    "homepage and get the top 3 posts.' Then, sleep for 10 minutes."
)
Input: Natural language task description Output: Task ID and initial status
When running locally, keep your agent running until the task completes.

get_task()

Retrieves the status and results of a previously dispatched task. Usage:
skyvern_tool = SkyvernTool()

agent = OpenAIAgent.from_tools(
    tools=[skyvern_tool.get_task()],
    llm=OpenAI(model="gpt-4o"),
)

response = agent.chat(
    "Get the task information with Skyvern. The task id is 'tsk_abc123'."
)
Input: Task ID Output: Task status, extracted data, and results

Agent Examples

Example: Complete Workflow with Polling

This agent dispatches a task, polls for completion, and returns results.
import asyncio
from dotenv import load_dotenv
from llama_index.agent.openai import OpenAIAgent
from llama_index.llms.openai import OpenAI
from llama_index.core.tools import FunctionTool
from skyvern_llamaindex.agent import SkyvernTool

load_dotenv()

async def sleep(seconds: int) -> str:
    await asyncio.sleep(seconds)
    return f"Slept for {seconds} seconds"

sleep_tool = FunctionTool.from_defaults(
    async_fn=sleep,
    description="Sleep for a given number of seconds",
    name="sleep",
)

skyvern_tool = SkyvernTool()

agent = OpenAIAgent.from_tools(
    tools=[
        skyvern_tool.dispatch_task(),
        skyvern_tool.get_task(),
        sleep_tool
    ],
    llm=OpenAI(model="gpt-4o"),
    verbose=True,
    max_function_calls=10,
)

response = agent.chat(
    "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."
)
print(response)

Example: API-Based Agent

Using Skyvern Cloud (no local setup needed):
import asyncio
from dotenv import load_dotenv
from llama_index.agent.openai import OpenAIAgent
from llama_index.llms.openai import OpenAI
from llama_index.core.tools import FunctionTool
from skyvern_llamaindex.client import SkyvernTool

load_dotenv()

async def sleep(seconds: int) -> str:
    await asyncio.sleep(seconds)
    return f"Slept for {seconds} seconds"

sleep_tool = FunctionTool.from_defaults(
    async_fn=sleep,
    description="Sleep for a given number of seconds",
    name="sleep",
)

skyvern_tool = SkyvernTool(api_key="<your_skyvern_api_key>")
# Or load from environment: SkyvernTool()

agent = OpenAIAgent.from_tools(
    tools=[
        skyvern_tool.dispatch_task(),
        skyvern_tool.get_task(),
        sleep_tool
    ],
    llm=OpenAI(model="gpt-4o"),
    verbose=True,
    max_function_calls=10,
)

response = agent.chat(
    "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."
)
print(response)

Local vs. API Mode

Agent Mode (Local)

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

Client Mode (API)

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

Use Cases

Web Research Agent

Build an agent that researches topics across multiple websites:
from llama_index.agent.openai import OpenAIAgent
from llama_index.llms.openai import OpenAI
from skyvern_llamaindex.client import SkyvernTool

skyvern = SkyvernTool(api_key="your_key")

agent = OpenAIAgent.from_tools(
    tools=[skyvern.run_task()],
    llm=OpenAI(model="gpt-4o"),
    verbose=True,
)

response = agent.chat(
    "Research the pricing of the top 3 CRM tools and compare their features."
)
print(response)

Form Automation Agent

Automate form submissions with extracted data:
from llama_index.agent.openai import OpenAIAgent
from skyvern_llamaindex.client import SkyvernTool

skyvern = SkyvernTool()

agent = OpenAIAgent.from_tools(
    tools=[skyvern.run_task()],
    llm=OpenAI(model="gpt-4o"),
)

user_data = {
    "name": "John Doe",
    "email": "[email protected]",
    "message": "Interested in your product"
}

response = agent.chat(
    f"Fill out the contact form at https://example.com/contact with: "
    f"Name: {user_data['name']}, Email: {user_data['email']}, "
    f"Message: {user_data['message']}"
)

Data Pipeline Agent

Extract and process data from multiple sources:
from llama_index.agent.openai import OpenAIAgent
from skyvern_llamaindex.client import SkyvernTool

skyvern = SkyvernTool()

agent = OpenAIAgent.from_tools(
    tools=[
        skyvern.dispatch_task(),
        skyvern.get_task(),
        # Add other tools like database connectors
    ],
    llm=OpenAI(model="gpt-4o"),
    max_function_calls=20,
)

response = agent.chat(
    "Extract product data from these e-commerce sites and save to database: "
    "[list of URLs]"
)

Integration with LlamaIndex Features

With Query Engines

Combine web automation with document querying:
from llama_index import VectorStoreIndex, SimpleDirectoryReader
from llama_index.agent.openai import OpenAIAgent
from skyvern_llamaindex.client import SkyvernTool

# Load and index documents
documents = SimpleDirectoryReader('data').load_data()
index = VectorStoreIndex.from_documents(documents)
query_engine = index.as_query_engine()

# Create agent with both tools
skyvern = SkyvernTool()

agent = OpenAIAgent.from_tools(
    tools=[skyvern.run_task()],
    llm=OpenAI(model="gpt-4o"),
)

# Use both capabilities
response = agent.chat(
    "First, check our docs for the pricing page URL, then extract the current "
    "pricing from the website."
)

With Workflows

Incorporate Skyvern into LlamaIndex workflows:
from llama_index.core.workflow import Workflow, step
from skyvern_llamaindex.client import SkyvernTool

class DataCollectionWorkflow(Workflow):
    @step
    async def extract_data(self, ctx, url: str) -> dict:
        skyvern = SkyvernTool()
        tool = skyvern.run_task()
        result = await tool.acall(
            f"Extract all product information from {url}"
        )
        return result
    
    @step
    async def process_data(self, ctx, data: dict) -> dict:
        # Process extracted data
        return processed_data

workflow = DataCollectionWorkflow()
result = await workflow.run(url="https://example.com/products")

Tips and Best Practices

Be specific with instructions: LlamaIndex agents work best with clear, detailed task descriptions.
Use max_function_calls: Set appropriate limits to prevent infinite loops when using polling patterns.
  • Handle async operations: Use proper async/await syntax
  • Combine with other tools: Leverage LlamaIndex’s ecosystem of tools
  • Set appropriate wait times: For dispatch/get patterns, use reasonable sleep intervals
  • Monitor token usage: Complex workflows can consume significant tokens
  • Store API keys securely: Use environment variables, not hardcoded values

Common Issues

ImportError: No module named ‘skyvern_llamaindex’

Install the package:
pip install skyvern-llamaindex

Local mode: “Skyvern not initialized”

Run the setup command:
skyvern init

API authentication fails

Verify your API key:

Agent exceeds max_function_calls

Increase the limit:
agent = OpenAIAgent.from_tools(
    tools=[...],
    max_function_calls=20,  # Increase this
)

Task results not returned

  • Ensure you’re using run_task() for synchronous completion
  • For dispatch_task(), add proper polling with get_task()
  • Check task status in Skyvern dashboard

Advanced Usage

For more advanced patterns and examples, see:

Support

For LlamaIndex integration help:

Next Steps

Creating Tasks

Learn how to write effective task instructions

Data Extraction

Extract structured data from websites

LangChain Integration

Check out the LangChain integration

API Reference

Full Skyvern API documentation

Build docs developers (and LLMs) love