No project description provided
Project description
Table of Contents generated with DocToc
- Skyvern Langchain
- Installation
- Basic Usage
- Run a task(sync) with skyvern agent (calling skyvern agent function directly in the tool)
- Run a task(async) with skyvern agent (calling skyvern agent function directly in the tool)
- Get a task with skyvern agent (calling skyvern agent function directly in the tool)
- Run a task(sync) with skyvern client (calling skyvern OpenAPI in the tool)
- Run a task(async) with skyvern client (calling skyvern OpenAPI in the tool)
- Get a task with skyvern client (calling skyvern OpenAPI in the tool)
- Agent Usage
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) 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 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) 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.
: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 --openai-api-key <your_openai_api_key> 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 with skyvern agent (calling skyvern agent function directly in the tool)
: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 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) 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 skyvern_langchain.client import RunTask
run_task = RunTask(
credential="<your_organization_api_key>",
)
# or you can load the credential from SKYVERN_CREDENTIAL 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) with skyvern client (calling skyvern OpenAPI in the tool)
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(
credential="<your_organization_api_key>",
)
# or you can load the credential from SKYVERN_CREDENTIAL 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 with skyvern client (calling skyvern OpenAPI in the tool)
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(
credential="<your_organization_api_key>",
)
# or you can load the credential from SKYVERN_CREDENTIAL 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. Here is an example of how to use skyvern langchain tool with agent.
Run a task(async) and wait until the task is finished by 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
GetTasktool 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(async) and wait until the task is finished by 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
GetTasktool 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file skyvern_langchain-0.1.4.tar.gz.
File metadata
- Download URL: skyvern_langchain-0.1.4.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bf19189afd5be039c069ae27d3a9d8af5ca21add82b7b384841d5a128e0401da
|
|
| MD5 |
79a438808ae9087d6d97ef98435b07d5
|
|
| BLAKE2b-256 |
3002b609f1cb997cd55edac2f1e64c3c5b5608649b36044c521a9ef68d63eb4e
|
File details
Details for the file skyvern_langchain-0.1.4-py3-none-any.whl.
File metadata
- Download URL: skyvern_langchain-0.1.4-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
66cecc5617aed9f628389a59b5ab6f63e86f425333951dedccc14d4f9cc0dc3e
|
|
| MD5 |
4e550fd057e94e3c5a12d9ab203d2e72
|
|
| BLAKE2b-256 |
1e75ef57e8aafe04356d0bd4094c31907e8b1db059bbff7846c5bceb06cae4a3
|