skyvern-llamaindex 0.0.1__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,197 @@
1
+ Metadata-Version: 2.1
2
+ Name: skyvern-llamaindex
3
+ Version: 0.0.1
4
+ Summary: Skyvern integration for LlamaIndex
5
+ Author: lawyzheng
6
+ Author-email: lawy@skyvern.com
7
+ Requires-Python: >=3.11,<3.12
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.11
10
+ Requires-Dist: llama-index (>=0.12.19,<0.13.0)
11
+ Requires-Dist: skyvern (>=0.1.56,<0.2.0)
12
+ Description-Content-Type: text/markdown
13
+
14
+ <!-- START doctoc generated TOC please keep comment here to allow auto update -->
15
+ <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
16
+ **Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*
17
+
18
+ - [Skyvern LlamaIndex](#skyvern-llamaindex)
19
+ - [Installation](#installation)
20
+ - [Usage](#usage)
21
+ - [Run a task(sync) with skyvern agent (calling skyvern agent function directly in the tool)](#run-a-tasksync-with-skyvern-agent-calling-skyvern-agent-function-directly-in-the-tool)
22
+ - [Run a task(async) with skyvern agent (calling skyvern agent function directly in the tool)](#run-a-taskasync-with-skyvern-agent-calling-skyvern-agent-function-directly-in-the-tool)
23
+ - [Run a task(sync) with skyvern client (calling skyvern OpenAPI in the tool)](#run-a-tasksync-with-skyvern-client-calling-skyvern-openapi-in-the-tool)
24
+ - [Run a task(async) with skyvern client (calling skyvern OpenAPI in the tool)](#run-a-taskasync-with-skyvern-client-calling-skyvern-openapi-in-the-tool)
25
+
26
+ <!-- END doctoc generated TOC please keep comment here to allow auto update -->
27
+
28
+ # Skyvern LlamaIndex
29
+
30
+ This is a LlamaIndex integration for Skyvern.
31
+
32
+ ## Installation
33
+
34
+ ```bash
35
+ pip install skyvern-llamaindex
36
+ ```
37
+
38
+ ## Usage
39
+
40
+ ### Run a task(sync) with skyvern agent (calling skyvern agent function directly in the tool)
41
+ > sync task won't return until the task is finished.
42
+
43
+ :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.
44
+
45
+
46
+ ```python
47
+ import asyncio
48
+ from dotenv import load_dotenv
49
+ from llama_index.agent.openai import OpenAIAgent
50
+ from llama_index.llms.openai import OpenAI
51
+ from skyvern_llamaindex.agent import SkyvernAgentToolSpec
52
+
53
+ # load OpenAI API key from .env
54
+ load_dotenv()
55
+
56
+ skyvern_tool = SkyvernAgentToolSpec()
57
+
58
+ tools = skyvern_tool.to_tool_list(["run_task_v2"])
59
+
60
+ agent = OpenAIAgent.from_tools(
61
+ tools=tools,
62
+ llm=OpenAI(model="gpt-4o"),
63
+ verbose=True,
64
+ max_function_calls=10,
65
+ )
66
+
67
+ # to run skyvern agent locally, must run `skyvern init` first
68
+ response = agent.chat("Run the task with skyvern. The task is about 'Navigate to the Hacker News homepage and get the top 3 posts.'")
69
+ print(response)
70
+ ```
71
+
72
+ ### Run a task(async) with skyvern agent (calling skyvern agent function directly in the tool)
73
+ > async task will return immediately and the task will be running in the background. You can use `get_task_v2` tool to poll the task information until the task is finished.
74
+
75
+ :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.
76
+
77
+ ```python
78
+ import asyncio
79
+ from dotenv import load_dotenv
80
+ from llama_index.agent.openai import OpenAIAgent
81
+ from llama_index.llms.openai import OpenAI
82
+ from llama_index.core.tools import FunctionTool
83
+ from skyvern_llamaindex.agent import SkyvernAgentToolSpec
84
+
85
+ async def sleep(seconds: int) -> str:
86
+ await asyncio.sleep(seconds)
87
+ return f"Slept for {seconds} seconds"
88
+
89
+ # load OpenAI API key from .env
90
+ load_dotenv()
91
+
92
+ skyvern_tool = SkyvernAgentToolSpec()
93
+
94
+ sleep_tool = FunctionTool.from_defaults(
95
+ async_fn=sleep,
96
+ description="Sleep for a given number of seconds",
97
+ name="sleep",
98
+ )
99
+
100
+ tools = skyvern_tool.to_tool_list(["queue_task_v2", "get_task_v2"])
101
+ tools.append(sleep_tool)
102
+
103
+ agent = OpenAIAgent.from_tools(
104
+ tools=tools,
105
+ llm=OpenAI(model="gpt-4o"),
106
+ verbose=True,
107
+ max_function_calls=10,
108
+ )
109
+
110
+ response = agent.chat("Queue 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.")
111
+ print(response)
112
+
113
+ ```
114
+
115
+ ### Run a task(sync) with skyvern client (calling skyvern OpenAPI in the tool)
116
+ > sync task won't return until the task is finished.
117
+
118
+ no need to run `skyvern init` command in your terminal to set up skyvern before using this integration.
119
+
120
+ ```python
121
+ import asyncio
122
+ from dotenv import load_dotenv
123
+ from llama_index.agent.openai import OpenAIAgent
124
+ from llama_index.llms.openai import OpenAI
125
+ from skyvern_llamaindex.client import SkyvernClientToolSpec
126
+
127
+
128
+ async def sleep(seconds: int) -> str:
129
+ await asyncio.sleep(seconds)
130
+ return f"Slept for {seconds} seconds"
131
+
132
+ # load OpenAI API key from .env
133
+ load_dotenv()
134
+
135
+ skyvern_client_tool = SkyvernClientToolSpec(
136
+ credential="<your_organization_api_key>",
137
+ )
138
+
139
+ tools = skyvern_client_tool.to_tool_list(["run_task_v2"])
140
+
141
+ agent = OpenAIAgent.from_tools(
142
+ tools=tools,
143
+ llm=OpenAI(model="gpt-4o"),
144
+ verbose=True,
145
+ max_function_calls=10,
146
+ )
147
+
148
+ response = agent.chat("Run the task with skyvern. The task is about 'Navigate to the Hacker News homepage and get the top 3 posts.'")
149
+ print(response)
150
+
151
+ ```
152
+
153
+ ### Run a task(async) with skyvern client (calling skyvern OpenAPI in the tool)
154
+ > async task will return immediately and the task will be running in the background. You can use `GetSkyvernClientTaskV2Tool` tool to poll the task information until the task is finished.
155
+
156
+ no need to run `skyvern init` command in your terminal to set up skyvern before using this integration.
157
+
158
+ ```python
159
+ import asyncio
160
+ from dotenv import load_dotenv
161
+ from llama_index.agent.openai import OpenAIAgent
162
+ from llama_index.llms.openai import OpenAI
163
+ from llama_index.core.tools import FunctionTool
164
+ from skyvern_llamaindex.client import SkyvernClientToolSpec
165
+
166
+
167
+ async def sleep(seconds: int) -> str:
168
+ await asyncio.sleep(seconds)
169
+ return f"Slept for {seconds} seconds"
170
+
171
+ # load OpenAI API key from .env
172
+ load_dotenv()
173
+
174
+ skyvern_client_tool = SkyvernClientToolSpec(
175
+ credential="<your_organization_api_key>",
176
+ )
177
+
178
+ sleep_tool = FunctionTool.from_defaults(
179
+ async_fn=sleep,
180
+ description="Sleep for a given number of seconds",
181
+ name="sleep",
182
+ )
183
+
184
+ tools = skyvern_client_tool.to_tool_list(["queue_task_v2", "get_task_v2"])
185
+ tools.append(sleep_tool)
186
+
187
+ agent = OpenAIAgent.from_tools(
188
+ tools=tools,
189
+ llm=OpenAI(model="gpt-4o"),
190
+ verbose=True,
191
+ max_function_calls=10,
192
+ )
193
+
194
+ response = agent.chat("Queue 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.")
195
+ print(response)
196
+
197
+ ```
@@ -0,0 +1,184 @@
1
+ <!-- START doctoc generated TOC please keep comment here to allow auto update -->
2
+ <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
3
+ **Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*
4
+
5
+ - [Skyvern LlamaIndex](#skyvern-llamaindex)
6
+ - [Installation](#installation)
7
+ - [Usage](#usage)
8
+ - [Run a task(sync) with skyvern agent (calling skyvern agent function directly in the tool)](#run-a-tasksync-with-skyvern-agent-calling-skyvern-agent-function-directly-in-the-tool)
9
+ - [Run a task(async) with skyvern agent (calling skyvern agent function directly in the tool)](#run-a-taskasync-with-skyvern-agent-calling-skyvern-agent-function-directly-in-the-tool)
10
+ - [Run a task(sync) with skyvern client (calling skyvern OpenAPI in the tool)](#run-a-tasksync-with-skyvern-client-calling-skyvern-openapi-in-the-tool)
11
+ - [Run a task(async) with skyvern client (calling skyvern OpenAPI in the tool)](#run-a-taskasync-with-skyvern-client-calling-skyvern-openapi-in-the-tool)
12
+
13
+ <!-- END doctoc generated TOC please keep comment here to allow auto update -->
14
+
15
+ # Skyvern LlamaIndex
16
+
17
+ This is a LlamaIndex integration for Skyvern.
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ pip install skyvern-llamaindex
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ ### Run a task(sync) with skyvern agent (calling skyvern agent function directly in the tool)
28
+ > sync task won't return until the task is finished.
29
+
30
+ :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.
31
+
32
+
33
+ ```python
34
+ import asyncio
35
+ from dotenv import load_dotenv
36
+ from llama_index.agent.openai import OpenAIAgent
37
+ from llama_index.llms.openai import OpenAI
38
+ from skyvern_llamaindex.agent import SkyvernAgentToolSpec
39
+
40
+ # load OpenAI API key from .env
41
+ load_dotenv()
42
+
43
+ skyvern_tool = SkyvernAgentToolSpec()
44
+
45
+ tools = skyvern_tool.to_tool_list(["run_task_v2"])
46
+
47
+ agent = OpenAIAgent.from_tools(
48
+ tools=tools,
49
+ llm=OpenAI(model="gpt-4o"),
50
+ verbose=True,
51
+ max_function_calls=10,
52
+ )
53
+
54
+ # to run skyvern agent locally, must run `skyvern init` first
55
+ response = agent.chat("Run the task with skyvern. The task is about 'Navigate to the Hacker News homepage and get the top 3 posts.'")
56
+ print(response)
57
+ ```
58
+
59
+ ### Run a task(async) with skyvern agent (calling skyvern agent function directly in the tool)
60
+ > async task will return immediately and the task will be running in the background. You can use `get_task_v2` tool to poll the task information until the task is finished.
61
+
62
+ :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.
63
+
64
+ ```python
65
+ import asyncio
66
+ from dotenv import load_dotenv
67
+ from llama_index.agent.openai import OpenAIAgent
68
+ from llama_index.llms.openai import OpenAI
69
+ from llama_index.core.tools import FunctionTool
70
+ from skyvern_llamaindex.agent import SkyvernAgentToolSpec
71
+
72
+ async def sleep(seconds: int) -> str:
73
+ await asyncio.sleep(seconds)
74
+ return f"Slept for {seconds} seconds"
75
+
76
+ # load OpenAI API key from .env
77
+ load_dotenv()
78
+
79
+ skyvern_tool = SkyvernAgentToolSpec()
80
+
81
+ sleep_tool = FunctionTool.from_defaults(
82
+ async_fn=sleep,
83
+ description="Sleep for a given number of seconds",
84
+ name="sleep",
85
+ )
86
+
87
+ tools = skyvern_tool.to_tool_list(["queue_task_v2", "get_task_v2"])
88
+ tools.append(sleep_tool)
89
+
90
+ agent = OpenAIAgent.from_tools(
91
+ tools=tools,
92
+ llm=OpenAI(model="gpt-4o"),
93
+ verbose=True,
94
+ max_function_calls=10,
95
+ )
96
+
97
+ response = agent.chat("Queue 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.")
98
+ print(response)
99
+
100
+ ```
101
+
102
+ ### Run a task(sync) with skyvern client (calling skyvern OpenAPI in the tool)
103
+ > sync task won't return until the task is finished.
104
+
105
+ no need to run `skyvern init` command in your terminal to set up skyvern before using this integration.
106
+
107
+ ```python
108
+ import asyncio
109
+ from dotenv import load_dotenv
110
+ from llama_index.agent.openai import OpenAIAgent
111
+ from llama_index.llms.openai import OpenAI
112
+ from skyvern_llamaindex.client import SkyvernClientToolSpec
113
+
114
+
115
+ async def sleep(seconds: int) -> str:
116
+ await asyncio.sleep(seconds)
117
+ return f"Slept for {seconds} seconds"
118
+
119
+ # load OpenAI API key from .env
120
+ load_dotenv()
121
+
122
+ skyvern_client_tool = SkyvernClientToolSpec(
123
+ credential="<your_organization_api_key>",
124
+ )
125
+
126
+ tools = skyvern_client_tool.to_tool_list(["run_task_v2"])
127
+
128
+ agent = OpenAIAgent.from_tools(
129
+ tools=tools,
130
+ llm=OpenAI(model="gpt-4o"),
131
+ verbose=True,
132
+ max_function_calls=10,
133
+ )
134
+
135
+ response = agent.chat("Run the task with skyvern. The task is about 'Navigate to the Hacker News homepage and get the top 3 posts.'")
136
+ print(response)
137
+
138
+ ```
139
+
140
+ ### Run a task(async) with skyvern client (calling skyvern OpenAPI in the tool)
141
+ > async task will return immediately and the task will be running in the background. You can use `GetSkyvernClientTaskV2Tool` tool to poll the task information until the task is finished.
142
+
143
+ no need to run `skyvern init` command in your terminal to set up skyvern before using this integration.
144
+
145
+ ```python
146
+ import asyncio
147
+ from dotenv import load_dotenv
148
+ from llama_index.agent.openai import OpenAIAgent
149
+ from llama_index.llms.openai import OpenAI
150
+ from llama_index.core.tools import FunctionTool
151
+ from skyvern_llamaindex.client import SkyvernClientToolSpec
152
+
153
+
154
+ async def sleep(seconds: int) -> str:
155
+ await asyncio.sleep(seconds)
156
+ return f"Slept for {seconds} seconds"
157
+
158
+ # load OpenAI API key from .env
159
+ load_dotenv()
160
+
161
+ skyvern_client_tool = SkyvernClientToolSpec(
162
+ credential="<your_organization_api_key>",
163
+ )
164
+
165
+ sleep_tool = FunctionTool.from_defaults(
166
+ async_fn=sleep,
167
+ description="Sleep for a given number of seconds",
168
+ name="sleep",
169
+ )
170
+
171
+ tools = skyvern_client_tool.to_tool_list(["queue_task_v2", "get_task_v2"])
172
+ tools.append(sleep_tool)
173
+
174
+ agent = OpenAIAgent.from_tools(
175
+ tools=tools,
176
+ llm=OpenAI(model="gpt-4o"),
177
+ verbose=True,
178
+ max_function_calls=10,
179
+ )
180
+
181
+ response = agent.chat("Queue 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.")
182
+ print(response)
183
+
184
+ ```
@@ -0,0 +1,20 @@
1
+ [tool.poetry]
2
+ name = "skyvern-llamaindex"
3
+ version = "0.0.1"
4
+ description = "Skyvern integration for LlamaIndex"
5
+ authors = ["lawyzheng <lawy@skyvern.com>"]
6
+ packages = [{ include = "skyvern_llamaindex" }]
7
+ readme = "README.md"
8
+
9
+ [tool.poetry.dependencies]
10
+ python = "^3.11,<3.12"
11
+ skyvern = "^0.1.56"
12
+ llama-index = "^0.12.19"
13
+
14
+
15
+ [tool.poetry.group.dev.dependencies]
16
+ twine = "^6.1.0"
17
+
18
+ [build-system]
19
+ requires = ["poetry-core"]
20
+ build-backend = "poetry.core.masonry.api"
@@ -0,0 +1,95 @@
1
+ from typing import Any, Dict, List, Tuple
2
+
3
+ from llama_index.core.tools.tool_spec.base import SPEC_FUNCTION_TYPE, BaseToolSpec
4
+ from llama_index.core.tools.types import ToolMetadata
5
+ from skyvern_llamaindex.schema import GetTaskInput, TaskV1Request, TaskV2Request
6
+
7
+ from skyvern.agent import Agent
8
+ from skyvern.forge.sdk.schemas.observers import ObserverTask
9
+ from skyvern.forge.sdk.schemas.tasks import CreateTaskResponse, TaskResponse
10
+
11
+
12
+ class SkyvernAgentToolSpec(BaseToolSpec):
13
+ spec_functions: List[SPEC_FUNCTION_TYPE] = [
14
+ "run_task_v1",
15
+ "queue_task_v1",
16
+ "get_task_v1",
17
+ "run_task_v2",
18
+ "queue_task_v2",
19
+ "get_task_v2",
20
+ ]
21
+ spec_metadata: Dict[str, ToolMetadata] = {
22
+ "run_task_v1": ToolMetadata(
23
+ name="run-skyvern-agent-task-v1",
24
+ description="Use Skyvern agent to run a v1 task. It is usually used for the simple tasks. This function won't return until the task is finished.",
25
+ fn_schema=TaskV1Request,
26
+ ),
27
+ "queue_task_v1": ToolMetadata(
28
+ name="queue-skyvern-agent-task-v1",
29
+ description="Use Skyvern agent to queue a v1 task. It is usually used for the simple tasks. This function will return immediately and the task will be running in the background.",
30
+ fn_schema=TaskV1Request,
31
+ ),
32
+ "get_task_v1": ToolMetadata(
33
+ name="get-skyvern-agent-task-v1",
34
+ description="Use Skyvern agent to get a v1 task. v1 tasks are usually simple tasks.",
35
+ fn_schema=GetTaskInput,
36
+ ),
37
+ "run_task_v2": ToolMetadata(
38
+ name="run-skyvern-agent-task-v2",
39
+ description="Use Skyvern agent to run a v2 task. It is usually used for the complicated tasks. This function won't return until the task is finished.",
40
+ fn_schema=TaskV2Request,
41
+ ),
42
+ "queue_task_v2": ToolMetadata(
43
+ name="queue-skyvern-agent-task-v2",
44
+ description="Use Skyvern agent to queue a v2 task. It is usually used for the complicated tasks. This function will return immediately and the task will be running in the background.",
45
+ fn_schema=TaskV2Request,
46
+ ),
47
+ "get_task_v2": ToolMetadata(
48
+ name="get-skyvern-agent-task-v2",
49
+ description="Use Skyvern agent to get a v2 task. v2 tasks are usually complicated tasks.",
50
+ fn_schema=GetTaskInput,
51
+ ),
52
+ }
53
+
54
+ def __init__(self) -> None:
55
+ self.agent = Agent()
56
+
57
+ def get_metadata_from_fn_name(
58
+ self, fn_name: str, spec_functions: List[str | Tuple[str, str]] | None = None
59
+ ) -> ToolMetadata | None:
60
+ try:
61
+ getattr(self, fn_name)
62
+ except AttributeError:
63
+ return None
64
+
65
+ return self.spec_metadata.get(fn_name)
66
+
67
+ async def run_task_v1(self, **kwargs: Dict[str, Any]) -> TaskResponse:
68
+ """Use Skyvern agent to run a v1 task. It is usually used for the simple tasks. This function won't return until the task is finished."""
69
+ task_request = TaskV1Request(**kwargs)
70
+ return await self.agent.run_task(task_request=task_request, timeout_seconds=task_request.timeout_seconds)
71
+
72
+ async def queue_task_v1(self, **kwargs: Dict[str, Any]) -> CreateTaskResponse:
73
+ """Use Skyvern agent to queue a v1 task. It is usually used for the simple tasks. This function will return immediately and the task will be running in the background."""
74
+ task_request = TaskV1Request(**kwargs)
75
+ return await self.agent.create_task(task_request=task_request)
76
+
77
+ async def get_task_v1(self, task_id: str) -> TaskResponse | None:
78
+ """Use Skyvern agent to get a v1 task. v1 tasks are usually simple tasks."""
79
+ return await self.agent.get_task(task_id=task_id)
80
+
81
+ async def run_task_v2(self, **kwargs: Dict[str, Any]) -> ObserverTask:
82
+ """Use Skyvern agent to run a v2 task. It is usually used for the complicated tasks. This function won't return until the task is finished."""
83
+ task_request = TaskV2Request(**kwargs)
84
+ return await self.agent.run_observer_task_v_2(
85
+ task_request=task_request, timeout_seconds=task_request.timeout_seconds
86
+ )
87
+
88
+ async def queue_task_v2(self, **kwargs: Dict[str, Any]) -> ObserverTask:
89
+ """Use Skyvern agent to queue a v2 task. It is usually used for the complicated tasks. This function will return immediately and the task will be running in the background."""
90
+ task_request = TaskV2Request(**kwargs)
91
+ return await self.agent.observer_task_v_2(task_request=task_request)
92
+
93
+ async def get_task_v2(self, task_id: str) -> ObserverTask | None:
94
+ """Use Skyvern agent to get a v2 task. v2 tasks are usually complicated tasks."""
95
+ return await self.agent.get_observer_task_v_2(task_id=task_id)
@@ -0,0 +1,146 @@
1
+ from typing import Any, Dict, List, Tuple
2
+
3
+ from httpx import AsyncClient
4
+ from llama_index.core.tools.tool_spec.base import SPEC_FUNCTION_TYPE, BaseToolSpec
5
+ from llama_index.core.tools.types import ToolMetadata
6
+ from skyvern_llamaindex.schema import GetTaskInput, TaskV1Request, TaskV2Request
7
+
8
+ from skyvern.client import AsyncSkyvern
9
+ from skyvern.forge.sdk.schemas.tasks import CreateTaskResponse, TaskResponse
10
+
11
+
12
+ class SkyvernClientToolSpec(BaseToolSpec):
13
+ spec_functions: List[SPEC_FUNCTION_TYPE] = [
14
+ "run_task_v1",
15
+ "queue_task_v1",
16
+ "get_task_v1",
17
+ "run_task_v2",
18
+ "queue_task_v2",
19
+ "get_task_v2",
20
+ ]
21
+
22
+ spec_metadata: Dict[str, ToolMetadata] = {
23
+ "run_task_v1": ToolMetadata(
24
+ name="run-skyvern-client-task-v1",
25
+ description="Use Skyvern client to run a v1 task. It is usually used for the simple tasks. This function won't return until the task is finished.",
26
+ fn_schema=TaskV1Request,
27
+ ),
28
+ "queue_task_v1": ToolMetadata(
29
+ name="queue-skyvern-client-task-v1",
30
+ description="Use Skyvern client to queue a v1 task. It is usually used for the simple tasks. This function will return immediately and the task will be running in the background.",
31
+ fn_schema=TaskV1Request,
32
+ ),
33
+ "get_task_v1": ToolMetadata(
34
+ name="get-skyvern-client-task-v1",
35
+ description="Use Skyvern client to get a v1 task. v1 tasks are usually simple tasks.",
36
+ fn_schema=GetTaskInput,
37
+ ),
38
+ "run_task_v2": ToolMetadata(
39
+ name="run-skyvern-client-task-v2",
40
+ description="Use Skyvern client to run a v2 task. It is usually used for the complicated tasks. This function won't return until the task is finished.",
41
+ fn_schema=TaskV2Request,
42
+ ),
43
+ "queue_task_v2": ToolMetadata(
44
+ name="queue-skyvern-client-task-v2",
45
+ description="Use Skyvern client to queue a v2 task. It is usually used for the complicated tasks. This function will return immediately and the task will be running in the background.",
46
+ fn_schema=TaskV2Request,
47
+ ),
48
+ "get_task_v2": ToolMetadata(
49
+ name="get-skyvern-client-task-v2",
50
+ description="Use Skyvern client to get a v2 task. It is usually used for the complicated tasks.",
51
+ fn_schema=GetTaskInput,
52
+ ),
53
+ }
54
+
55
+ def __init__(self, credential: str, base_url: str = "https://api.skyvern.com"):
56
+ httpx_client = AsyncClient(
57
+ headers={
58
+ "Content-Type": "application/json",
59
+ "x-api-key": credential,
60
+ },
61
+ )
62
+ self.client = AsyncSkyvern(base_url=base_url, httpx_client=httpx_client)
63
+
64
+ def get_metadata_from_fn_name(
65
+ self, fn_name: str, spec_functions: List[str | Tuple[str, str]] | None = None
66
+ ) -> ToolMetadata | None:
67
+ try:
68
+ getattr(self, fn_name)
69
+ except AttributeError:
70
+ return None
71
+
72
+ return self.spec_metadata.get(fn_name)
73
+
74
+ async def run_task_v1(self, **kwargs: Dict[str, Any]) -> TaskResponse:
75
+ task_request = TaskV1Request(**kwargs)
76
+ return await self.client.agent.run_task(
77
+ max_steps_override=task_request.max_steps,
78
+ timeout_seconds=task_request.timeout_seconds,
79
+ url=task_request.url,
80
+ title=task_request.title,
81
+ webhook_callback_url=task_request.webhook_callback_url,
82
+ totp_verification_url=task_request.totp_verification_url,
83
+ totp_identifier=task_request.totp_identifier,
84
+ navigation_goal=task_request.navigation_goal,
85
+ data_extraction_goal=task_request.data_extraction_goal,
86
+ navigation_payload=task_request.navigation_goal,
87
+ error_code_mapping=task_request.error_code_mapping,
88
+ proxy_location=task_request.proxy_location,
89
+ extracted_information_schema=task_request.extracted_information_schema,
90
+ complete_criterion=task_request.complete_criterion,
91
+ terminate_criterion=task_request.terminate_criterion,
92
+ browser_session_id=task_request.browser_session_id,
93
+ )
94
+
95
+ async def queue_task_v1(self, **kwargs: Dict[str, Any]) -> CreateTaskResponse:
96
+ task_request = TaskV1Request(**kwargs)
97
+ return await self.client.agent.create_task(
98
+ max_steps_override=task_request.max_steps,
99
+ url=task_request.url,
100
+ title=task_request.title,
101
+ webhook_callback_url=task_request.webhook_callback_url,
102
+ totp_verification_url=task_request.totp_verification_url,
103
+ totp_identifier=task_request.totp_identifier,
104
+ navigation_goal=task_request.navigation_goal,
105
+ data_extraction_goal=task_request.data_extraction_goal,
106
+ navigation_payload=task_request.navigation_goal,
107
+ error_code_mapping=task_request.error_code_mapping,
108
+ proxy_location=task_request.proxy_location,
109
+ extracted_information_schema=task_request.extracted_information_schema,
110
+ complete_criterion=task_request.complete_criterion,
111
+ terminate_criterion=task_request.terminate_criterion,
112
+ browser_session_id=task_request.browser_session_id,
113
+ )
114
+
115
+ async def get_task_v1(self, task_id: str) -> TaskResponse:
116
+ return await self.client.agent.get_task(task_id=task_id)
117
+
118
+ async def run_task_v2(self, **kwargs: Dict[str, Any]) -> Dict[str, Any | None]:
119
+ task_request = TaskV2Request(**kwargs)
120
+ return await self.client.agent.run_observer_task_v_2(
121
+ max_iterations_override=task_request.max_iterations,
122
+ timeout_seconds=task_request.timeout_seconds,
123
+ user_prompt=task_request.user_prompt,
124
+ url=task_request.url,
125
+ browser_session_id=task_request.browser_session_id,
126
+ webhook_callback_url=task_request.webhook_callback_url,
127
+ totp_verification_url=task_request.totp_verification_url,
128
+ totp_identifier=task_request.totp_identifier,
129
+ proxy_location=task_request.proxy_location,
130
+ )
131
+
132
+ async def queue_task_v2(self, **kwargs: Dict[str, Any]) -> Dict[str, Any | None]:
133
+ task_request = TaskV2Request(**kwargs)
134
+ return await self.client.agent.observer_task_v_2(
135
+ max_iterations_override=task_request.max_iterations,
136
+ user_prompt=task_request.user_prompt,
137
+ url=task_request.url,
138
+ browser_session_id=task_request.browser_session_id,
139
+ webhook_callback_url=task_request.webhook_callback_url,
140
+ totp_verification_url=task_request.totp_verification_url,
141
+ totp_identifier=task_request.totp_identifier,
142
+ proxy_location=task_request.proxy_location,
143
+ )
144
+
145
+ async def get_task_v2(self, task_id: str) -> Dict[str, Any | None]:
146
+ return await self.client.agent.get_observer_task_v_2(task_id=task_id)
File without changes
@@ -0,0 +1,18 @@
1
+ from pydantic import BaseModel
2
+
3
+ from skyvern.forge.sdk.schemas.observers import ObserverTaskRequest
4
+ from skyvern.forge.sdk.schemas.tasks import TaskRequest
5
+
6
+
7
+ class TaskV1Request(TaskRequest):
8
+ max_steps: int = 10
9
+ timeout_seconds: int = 60 * 60
10
+
11
+
12
+ class TaskV2Request(ObserverTaskRequest):
13
+ max_iterations: int = 10
14
+ timeout_seconds: int = 60 * 60
15
+
16
+
17
+ class GetTaskInput(BaseModel):
18
+ task_id: str