Skip to main content

Skyvern Langchain

This is a langchain integration for Skyvern.

Installation

pip install skyvern-langchain

To run the example scenarios, you might need to install other langchain dependencies.

pip install langchain-openai
pip install langchain-community

Basic Usage

This is the only basic usage of skyvern langchain tool. If you want a full langchain integration experience, please refer to the Agent Usage section to play with langchain agent.

Go to Langchain Tools to see more advanced langchain tool usage.

Run a task(sync) locally in your local environment

sync task won't return until the task is finished.

:warning: :warning: if you want to run this code block, you need to run skyvern init command in your terminal to set up skyvern first.

import asyncio
from skyvern_langchain.agent import RunTask

run_task = RunTask()

async def main():
    # to run skyvern agent locally, must run `skyvern init` first
    print(await run_task.ainvoke("Navigate to the Hacker News homepage and get the top 3 posts."))


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

Run a task(async) locally in your local environment

async task will return immediately and the task will be running in the background.

:warning: :warning: if you want to run the task in the background, you need to keep the script running until the task is finished, otherwise the task will be killed when the script is finished.

:warning: :warning: if you want to run this code block, you need to run skyvern init command in your terminal to set up skyvern first.

import asyncio
from skyvern_langchain.agent import DispatchTask

dispatch_task = DispatchTask()

async def main():
    # to run skyvern agent locally, must run `skyvern init` first
    print(await dispatch_task.ainvoke("Navigate to the Hacker News homepage and get the top 3 posts."))

    # keep the script running until the task is finished
    await asyncio.sleep(600)


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

Get a task locally in your local environment

:warning: :warning: if you want to run this code block, you need to run skyvern init command in your terminal to set up skyvern first.

import asyncio
from skyvern_langchain.agent import GetTask

get_task = GetTask()

async def main():
    # to run skyvern agent locally, must run `skyvern init` first
    print(await get_task.ainvoke("<task_id>"))


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

Run a task(sync) by calling skyvern APIs

sync task won't return until the task is finished.

no need to run skyvern init command in your terminal to set up skyvern before using this integration.

import asyncio
from skyvern_langchain.client import RunTask

run_task = RunTask(
    api_key="<your_organization_api_key>",
)
# or you can load the api_key from SKYVERN_API_KEY in .env
# run_task = RunTask()

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


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

Run a task(async) by calling skyvern APIs

async task will return immediately and the task will be running in the background.

no need to run skyvern init command in your terminal to set up skyvern before using this integration.

the task is actually running in the skyvern cloud service, so you don't need to keep your script running until the task is finished.

import asyncio
from skyvern_langchain.client import DispatchTask

dispatch_task = DispatchTask(
    api_key="<your_organization_api_key>",
)
# or you can load the api_key from SKYVERN_API_KEY in .env
# dispatch_task = DispatchTask()

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


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

Get a task by calling skyvern APIs

async task will return immediately and the task will be running in the background.

no need to run skyvern init command in your terminal to set up skyvern before using this integration.

the task is actually running in the skyvern cloud service, so you don't need to keep your script running until the task is finished.

import asyncio
from skyvern_langchain.client import GetTask

get_task = GetTask(
    api_key="<your_organization_api_key>",
)
# or you can load the api_key from SKYVERN_API_KEY in .env
# get_task = GetTask()

async def main():
    print(await get_task.ainvoke("<task_id>"))


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

Agent Usage

Langchain is more powerful when used with Langchain Agents.

The following two examples show how to build an agent that executes a specified task, waits for its completion, and then returns the results. For example, the agent is tasked with navigating to the Hacker News homepage and retrieving the top three posts.

Run a task(async) locally in your local environment and wait until the task is finished

async task will return immediately and the task will be running in the background. You can use GetTask tool to poll the task information until the task is finished.

:warning: :warning: if you want to run this code block, you need to run skyvern init command in your terminal to set up skyvern first.

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 OpenAI API key from .env
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():
    # use sleep tool to set up the polling logic until the task is completed, if you only want to dispatch a task, you can remove the sleep tool
    print(await agent.ainvoke("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."))


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

Run a task(async) by calling skyvern APIs and wait until the task is finished

async task will return immediately and the task will be running in the background. You can use GetTask tool to poll the task information until the task is finished.

no need to run skyvern init command in your terminal to set up skyvern before using this integration.

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 OpenAI API key from .env
load_dotenv()

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

dispatch_task = DispatchTask(
    api_key="<your_organization_api_key>",
)
# or you can load the api_key from SKYVERN_API_KEY in .env
# dispatch_task = DispatchTask()

get_task = GetTask(
    api_key="<your_organization_api_key>",
)
# or you can load the api_key from SKYVERN_API_KEY in .env
# 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():
    # use sleep tool to set up the polling logic until the task is completed, if you only want to dispatch a task, you can remove the sleep tool
    print(await agent.ainvoke("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."))


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

Metadata

Release files for skyvern-langchain 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for skyvern-langchain 0.2.1
File Size Uploaded
skyvern_langchain-0.2.1.tar.gz 4.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for skyvern-langchain 0.2.1
File Interpreter ABI Platform
skyvern_langchain-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 10.3 kB

Release files / skyvern_langchain-0.2.1.tar.gz

Download URL skyvern_langchain-0.2.1.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
9b34ad254b307c15f8df607174ca32585d2bfb8f76f2be4c9d6f7dc6a2e19f3f
BLAKE2b-256 checksum
How to use checksums
4cdb283909f4890a4d27caa4012f8d5d985dced78b71b961a3bf7822a9cc1f5c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.11

Release files / skyvern_langchain-0.2.1-py3-none-any.whl

Download URL skyvern_langchain-0.2.1-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4b3abb394329551680eb1d8483cf98f5eb9e3b03a2f35323247bde92f30b2b9b
BLAKE2b-256 checksum
How to use checksums
6969f1aabb7a6097a0394ca287981867436b8c5a1539027125a0b2bf7d54b0d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.11

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page