Skip to main content

Skyvern integration for LlamaIndex

Project description

Table of Contents generated with DocToc

Skyvern LlamaIndex

This is a LlamaIndex integration for Skyvern.

Installation

pip install skyvern-llamaindex

Basic 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 --openai-api-key <your_openai_api_key> command in your terminal to set up skyvern first.

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

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 agent running until the task is finished, otherwise the task will be killed when the agent finished the chat.

: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 llama_index.agent.openai import OpenAIAgent
from llama_index.llms.openai import OpenAI
from skyvern_llamaindex.agent import SkyvernTool
from llama_index.core.tools import FunctionTool

# load OpenAI API key from .env
load_dotenv()

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

# define a sleep tool to keep the agent running until the task is finished
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"),
    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.' Then, sleep for 10 minutes.")
print(response)

Get a task locally in your local environment

: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.

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

skyvern_tool = SkyvernTool()

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

response = agent.chat("Get the task information with Skyvern. The task id is '<task_id>'.")
print(response)

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.

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

skyvern_tool = SkyvernTool(api_key="<your_organization_api_key>")
# or you can load the api_key from SKYVERN_API_KEY in .env
# 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)

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 agent running until the task is finished.

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

skyvern_tool = SkyvernTool(api_key="<your_organization_api_key>")
# or you can load the api_key from SKYVERN_API_KEY in .env
# skyvern_tool = SkyvernTool()

agent = OpenAIAgent.from_tools(
    tools=[skyvern_tool.dispatch_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)

Get a task by calling skyvern APIs

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

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

skyvern_tool = SkyvernTool(api_key="<your_organization_api_key>")
# or you can load the api_key from SKYVERN_API_KEY in .env
# skyvern_tool = SkyvernTool()

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

response = agent.chat("Get the task information with Skyvern. The task id is '<task_id>'.")
print(response)

Advanced Usage

To provide some examples of how to integrate Skyvern with other llama-index tools in the agent.

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

dispatch task will return immediately and the task will be running in the background. You can use get_task 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 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 OpenAI API key from .env
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)

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

dispatch task will return immediately and the task will be running in the background. You can use get_task 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 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 OpenAI API key from .env
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_organization_api_key>")
# or you can load the api_key from SKYVERN_API_KEY in .env
# 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)

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_llamaindex-0.0.4.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

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

skyvern_llamaindex-0.0.4-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file skyvern_llamaindex-0.0.4.tar.gz.

File metadata

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

File hashes

Hashes for skyvern_llamaindex-0.0.4.tar.gz
Algorithm Hash digest
SHA256 b14adea8f1f20b280fc8c73b829784e43c1735c6b2b10e17a1629c59ee64df7a
MD5 01fca71e38cb3315f69f20ae773ad57d
BLAKE2b-256 b4a69a2256a6efb2ffcdf4e5acdb5aa479321c8d162c04bcbcfb5a8a3a5a6c00

See more details on using hashes here.

File details

Details for the file skyvern_llamaindex-0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for skyvern_llamaindex-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 8dd7b92be18d3eec56a2f69235f5f9319967c4dd3d1c4fd7c807d3659cf52052
MD5 7039c615a18808a8df57c3cf02b2e6f4
BLAKE2b-256 2e1972f81eb9520c8eb0bfbae843cd34e2e37fe341bee70b0b884e6bf952c6f5

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