Skip to main content

No project description provided

Project description

Table of Contents generated with DocToc

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

Usage

Run a task(sync) with skyvern agent (calling skyvern agent function directly in the tool)

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 --openai-api-key <your_openai_api_key> 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 RunTask

# load OpenAI API key from .env
load_dotenv()

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

run_task = RunTask()

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


async def main():
    # to run skyvern agent locally, must run `skyvern init` first
    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.'"))


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

Run a task(async) with skyvern agent (calling skyvern agent function directly in the tool)

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 --openai-api-key <your_openai_api_key> 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(sync) with skyvern client (calling skyvern OpenAPI in the tool)

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 dotenv import load_dotenv
from langchain_openai import ChatOpenAI
from langchain.agents import initialize_agent, AgentType
from skyvern_langchain.client import RunTask

# load OpenAI API key from .env
load_dotenv()

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

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

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

async def main():
    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.'"))


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

Run a task(async) with skyvern client (calling skyvern OpenAPI in the tool)

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(
    credential="<your_organization_api_key>",
)
# or you can load the credential from SKYVERN_CREDENTIAL in .env
# dispatch_task = DispatchTask()

get_task = GetTask(
    credential="<your_organization_api_key>",
)
# or you can load the credential from SKYVERN_CREDENTIAL 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())

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

skyvern_langchain-0.1.3.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

skyvern_langchain-0.1.3-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file skyvern_langchain-0.1.3.tar.gz.

File metadata

  • Download URL: skyvern_langchain-0.1.3.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for skyvern_langchain-0.1.3.tar.gz
Algorithm Hash digest
SHA256 5c3c5e51e012f395fa7eeb063ebff0bc3b188d08dc6b2dbc9f2a7ad01e1a40a6
MD5 af8b27505298f9cec7e3ba299b69568e
BLAKE2b-256 6de7f7ee59cd7833bc9b5b7f005712c028f6efb397b388308083716c3ba2f13b

See more details on using hashes here.

File details

Details for the file skyvern_langchain-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for skyvern_langchain-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 353bc53e1d4ce7cd99b25aa064b105e584786b285577bfa60dc0dfedf163ec63
MD5 a7b5f8356bd1884105cfa8f8f33ded27
BLAKE2b-256 d18dcb8a6ae76729ba1eb6c73d734bca61b27285967537fdf81e24830d57da03

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page