skyvern-llamaindex 0.0.4__tar.gz → 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,19 +1,20 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: skyvern-llamaindex
3
- Version: 0.0.4
3
+ Version: 0.2.0
4
4
  Summary: Skyvern integration for LlamaIndex
5
5
  Author: lawyzheng
6
6
  Author-email: lawy@skyvern.com
7
- Requires-Python: >=3.11,<3.12
7
+ Requires-Python: >=3.11,<3.14
8
8
  Classifier: Programming Language :: Python :: 3
9
9
  Classifier: Programming Language :: Python :: 3.11
10
+ Classifier: Programming Language :: Python :: 3.12
11
+ Classifier: Programming Language :: Python :: 3.13
10
12
  Requires-Dist: llama-index (>=0.12.19,<0.13.0)
11
- Requires-Dist: skyvern (>=0.1.56,<0.2.0)
13
+ Requires-Dist: skyvern (>=0.2.0)
12
14
  Description-Content-Type: text/markdown
13
15
 
14
16
  <!-- START doctoc generated TOC please keep comment here to allow auto update -->
15
17
  <!-- 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
 
18
19
  - [Skyvern LlamaIndex](#skyvern-llamaindex)
19
20
  - [Installation](#installation)
@@ -45,7 +46,7 @@ pip install skyvern-llamaindex
45
46
  ### Run a task(sync) locally in your local environment
46
47
  > sync task won't return until the task is finished.
47
48
 
48
- :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.
49
+ :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.
49
50
 
50
51
 
51
52
  ```python
@@ -74,7 +75,7 @@ print(response)
74
75
 
75
76
  :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.
76
77
 
77
- :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.
78
+ :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.
78
79
 
79
80
  ```python
80
81
  import asyncio
@@ -112,7 +113,7 @@ print(response)
112
113
 
113
114
  ### Get a task locally in your local environment
114
115
 
115
- :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.
116
+ :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.
116
117
 
117
118
  ```python
118
119
  from dotenv import load_dotenv
@@ -228,7 +229,7 @@ To provide some examples of how to integrate Skyvern with other llama-index tool
228
229
  ### Dispatch a task(async) locally in your local environment and wait until the task is finished
229
230
  > 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.
230
231
 
231
- :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.
232
+ :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.
232
233
 
233
234
  ```python
234
235
  import asyncio
@@ -1,6 +1,5 @@
1
1
  <!-- START doctoc generated TOC please keep comment here to allow auto update -->
2
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
3
 
5
4
  - [Skyvern LlamaIndex](#skyvern-llamaindex)
6
5
  - [Installation](#installation)
@@ -32,7 +31,7 @@ pip install skyvern-llamaindex
32
31
  ### Run a task(sync) locally in your local environment
33
32
  > sync task won't return until the task is finished.
34
33
 
35
- :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.
34
+ :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.
36
35
 
37
36
 
38
37
  ```python
@@ -61,7 +60,7 @@ print(response)
61
60
 
62
61
  :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.
63
62
 
64
- :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
+ :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.
65
64
 
66
65
  ```python
67
66
  import asyncio
@@ -99,7 +98,7 @@ print(response)
99
98
 
100
99
  ### Get a task locally in your local environment
101
100
 
102
- :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.
101
+ :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.
103
102
 
104
103
  ```python
105
104
  from dotenv import load_dotenv
@@ -215,7 +214,7 @@ To provide some examples of how to integrate Skyvern with other llama-index tool
215
214
  ### Dispatch a task(async) locally in your local environment and wait until the task is finished
216
215
  > 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.
217
216
 
218
- :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.
217
+ :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.
219
218
 
220
219
  ```python
221
220
  import asyncio
@@ -1,14 +1,14 @@
1
1
  [tool.poetry]
2
2
  name = "skyvern-llamaindex"
3
- version = "0.0.4"
3
+ version = "0.2.0"
4
4
  description = "Skyvern integration for LlamaIndex"
5
5
  authors = ["lawyzheng <lawy@skyvern.com>"]
6
6
  packages = [{ include = "skyvern_llamaindex" }]
7
7
  readme = "README.md"
8
8
 
9
9
  [tool.poetry.dependencies]
10
- python = "^3.11,<3.12"
11
- skyvern = "^0.1.56"
10
+ python = "^3.11,<3.14"
11
+ skyvern = ">=0.2.0"
12
12
  llama-index = "^0.12.19"
13
13
 
14
14
 
@@ -0,0 +1,91 @@
1
+ from typing import List, Optional
2
+
3
+ from llama_index.core.tools import FunctionTool
4
+ from llama_index.core.tools.tool_spec.base import SPEC_FUNCTION_TYPE, BaseToolSpec
5
+ from skyvern_llamaindex.settings import settings
6
+
7
+ from skyvern import Skyvern
8
+ from skyvern.client.types.get_run_response import GetRunResponse
9
+ from skyvern.client.types.task_run_response import TaskRunResponse
10
+ from skyvern.schemas.runs import RunEngine
11
+
12
+
13
+ class SkyvernTool:
14
+ def __init__(self, agent: Optional[Skyvern] = None):
15
+ if agent is None:
16
+ agent = Skyvern(base_url=None, api_key=None)
17
+ self.agent = agent
18
+
19
+ def run_task(self) -> FunctionTool:
20
+ task_tool_spec = SkyvernTaskToolSpec(agent=self.agent)
21
+ return task_tool_spec.to_tool_list(["run_task"])[0]
22
+
23
+ def dispatch_task(self) -> FunctionTool:
24
+ task_tool_spec = SkyvernTaskToolSpec(agent=self.agent)
25
+ return task_tool_spec.to_tool_list(["dispatch_task"])[0]
26
+
27
+ def get_task(self) -> FunctionTool:
28
+ task_tool_spec = SkyvernTaskToolSpec(agent=self.agent)
29
+ return task_tool_spec.to_tool_list(["get_task"])[0]
30
+
31
+
32
+ class SkyvernTaskToolSpec(BaseToolSpec):
33
+ spec_functions: List[SPEC_FUNCTION_TYPE] = [
34
+ "run_task",
35
+ "dispatch_task",
36
+ "get_task",
37
+ ]
38
+
39
+ def __init__(
40
+ self,
41
+ *,
42
+ agent: Skyvern | None = None,
43
+ engine: RunEngine = settings.engine,
44
+ run_task_timeout_seconds: int = settings.run_task_timeout_seconds,
45
+ ) -> None:
46
+ if agent is None:
47
+ agent = Skyvern(base_url=None, api_key=None)
48
+ self.agent = agent
49
+ self.engine = engine
50
+ self.run_task_timeout_seconds = run_task_timeout_seconds
51
+
52
+ async def run_task(self, user_prompt: str, url: Optional[str] = None) -> TaskRunResponse:
53
+ """
54
+ Use Skyvern agent to run a task. This function won't return until the task is finished.
55
+
56
+ Args:
57
+ user_prompt[str]: The user's prompt describing the task.
58
+ url (Optional[str]): The URL of the target website for the task.
59
+ """
60
+ return await self.agent.run_task(
61
+ prompt=user_prompt,
62
+ url=url,
63
+ engine=self.engine,
64
+ timeout=self.run_task_timeout_seconds,
65
+ wait_for_completion=True,
66
+ )
67
+
68
+ async def dispatch_task(self, user_prompt: str, url: Optional[str] = None) -> TaskRunResponse:
69
+ """
70
+ Use Skyvern agent to dispatch a task. This function will return immediately and the task will be running in the background.
71
+
72
+ Args:
73
+ user_prompt[str]: The user's prompt describing the task.
74
+ url (Optional[str]): The URL of the target website for the task.
75
+ """
76
+ return await self.agent.run_task(
77
+ prompt=user_prompt,
78
+ url=url,
79
+ engine=self.engine,
80
+ timeout=self.run_task_timeout_seconds,
81
+ wait_for_completion=False,
82
+ )
83
+
84
+ async def get_task(self, task_id: str) -> GetRunResponse | None:
85
+ """
86
+ Use Skyvern agent to get a task.
87
+
88
+ Args:
89
+ task_id[str]: The id of the task.
90
+ """
91
+ return await self.agent.get_run(run_id=task_id)
@@ -0,0 +1,104 @@
1
+ from typing import List, Optional
2
+
3
+ from llama_index.core.tools import FunctionTool
4
+ from llama_index.core.tools.tool_spec.base import SPEC_FUNCTION_TYPE, BaseToolSpec
5
+ from pydantic import BaseModel
6
+ from skyvern_llamaindex.settings import settings
7
+
8
+ from skyvern import Skyvern
9
+ from skyvern.client.types.get_run_response import GetRunResponse
10
+ from skyvern.client.types.task_run_response import TaskRunResponse
11
+ from skyvern.schemas.runs import RunEngine
12
+
13
+
14
+ class SkyvernTool(BaseModel):
15
+ api_key: str = settings.api_key
16
+ base_url: str = settings.base_url
17
+
18
+ def run_task(self) -> FunctionTool:
19
+ task_tool_spec = SkyvernTaskToolSpec(
20
+ api_key=self.api_key,
21
+ base_url=self.base_url,
22
+ )
23
+
24
+ return task_tool_spec.to_tool_list(["run_task"])[0]
25
+
26
+ def dispatch_task(self) -> FunctionTool:
27
+ task_tool_spec = SkyvernTaskToolSpec(
28
+ api_key=self.api_key,
29
+ base_url=self.base_url,
30
+ )
31
+
32
+ return task_tool_spec.to_tool_list(["dispatch_task"])[0]
33
+
34
+ def get_task(self) -> FunctionTool:
35
+ task_tool_spec = SkyvernTaskToolSpec(
36
+ api_key=self.api_key,
37
+ base_url=self.base_url,
38
+ )
39
+
40
+ return task_tool_spec.to_tool_list(["get_task"])[0]
41
+
42
+
43
+ class SkyvernTaskToolSpec(BaseToolSpec):
44
+ spec_functions: List[SPEC_FUNCTION_TYPE] = [
45
+ "run_task",
46
+ "dispatch_task",
47
+ "get_task",
48
+ ]
49
+
50
+ def __init__(
51
+ self,
52
+ *,
53
+ api_key: str = settings.api_key,
54
+ base_url: str = settings.base_url,
55
+ engine: RunEngine = settings.engine,
56
+ run_task_timeout_seconds: int = settings.run_task_timeout_seconds,
57
+ ):
58
+ self.engine = engine
59
+ self.run_task_timeout_seconds = run_task_timeout_seconds
60
+ self.client = Skyvern(base_url=base_url, api_key=api_key)
61
+
62
+ async def run_task(self, user_prompt: str, url: Optional[str] = None) -> TaskRunResponse:
63
+ """
64
+ Use Skyvern client to run a task. This function won't return until the task is finished.
65
+
66
+ Args:
67
+ user_prompt[str]: The user's prompt describing the task.
68
+ url (Optional[str]): The URL of the target website for the task.
69
+ """
70
+
71
+ return await self.client.run_task(
72
+ prompt=user_prompt,
73
+ url=url,
74
+ engine=self.engine,
75
+ timeout=self.run_task_timeout_seconds,
76
+ wait_for_completion=True,
77
+ )
78
+
79
+ async def dispatch_task(self, user_prompt: str, url: Optional[str] = None) -> TaskRunResponse:
80
+ """
81
+ Use Skyvern client to dispatch a task. This function will return immediately and the task will be running in the background.
82
+
83
+ Args:
84
+ user_prompt[str]: The user's prompt describing the task.
85
+ url (Optional[str]): The URL of the target website for the task.
86
+ """
87
+
88
+ return await self.client.run_task(
89
+ prompt=user_prompt,
90
+ url=url,
91
+ engine=self.engine,
92
+ timeout=self.run_task_timeout_seconds,
93
+ wait_for_completion=False,
94
+ )
95
+
96
+ async def get_task(self, task_id: str) -> GetRunResponse | None:
97
+ """
98
+ Use Skyvern client to get a task.
99
+
100
+ Args:
101
+ task_id[str]: The id of the task.
102
+ """
103
+
104
+ return await self.client.get_run(run_id=task_id)
@@ -1,13 +1,13 @@
1
- from typing import Literal
2
-
3
1
  from dotenv import load_dotenv
4
2
  from pydantic_settings import BaseSettings
5
3
 
4
+ from skyvern.schemas.runs import RunEngine
5
+
6
6
 
7
7
  class Settings(BaseSettings):
8
8
  api_key: str = ""
9
9
  base_url: str = "https://api.skyvern.com"
10
- engine: Literal["TaskV1", "TaskV2"] = "TaskV2"
10
+ engine: RunEngine = RunEngine.skyvern_v2
11
11
  run_task_timeout_seconds: int = 60 * 60
12
12
 
13
13
  class Config:
@@ -1,133 +0,0 @@
1
- from typing import List, Literal, Optional
2
-
3
- from llama_index.core.tools import FunctionTool
4
- from llama_index.core.tools.tool_spec.base import SPEC_FUNCTION_TYPE, BaseToolSpec
5
- from skyvern_llamaindex.settings import settings
6
-
7
- from skyvern.agent import Agent
8
- from skyvern.forge import app
9
- from skyvern.forge.prompts import prompt_engine
10
- from skyvern.forge.sdk.schemas.observers import ObserverTask, ObserverTaskRequest
11
- from skyvern.forge.sdk.schemas.task_generations import TaskGenerationBase
12
- from skyvern.forge.sdk.schemas.tasks import CreateTaskResponse, TaskRequest, TaskResponse
13
-
14
- default_agent = Agent()
15
-
16
-
17
- class SkyvernTool:
18
- def __init__(self, agent: Optional[Agent] = None):
19
- if agent is None:
20
- agent = default_agent
21
- self.agent = agent
22
-
23
- def run_task(self) -> FunctionTool:
24
- task_tool_spec = SkyvernTaskToolSpec(agent=self.agent)
25
- return task_tool_spec.to_tool_list(["run_task"])[0]
26
-
27
- def dispatch_task(self) -> FunctionTool:
28
- task_tool_spec = SkyvernTaskToolSpec(agent=self.agent)
29
- return task_tool_spec.to_tool_list(["dispatch_task"])[0]
30
-
31
- def get_task(self) -> FunctionTool:
32
- task_tool_spec = SkyvernTaskToolSpec(agent=self.agent)
33
- return task_tool_spec.to_tool_list(["get_task"])[0]
34
-
35
-
36
- class SkyvernTaskToolSpec(BaseToolSpec):
37
- spec_functions: List[SPEC_FUNCTION_TYPE] = [
38
- "run_task",
39
- "dispatch_task",
40
- "get_task",
41
- ]
42
-
43
- def __init__(
44
- self,
45
- *,
46
- agent: Optional[Agent] = None,
47
- engine: Literal["TaskV1", "TaskV2"] = settings.engine,
48
- run_task_timeout_seconds: int = settings.run_task_timeout_seconds,
49
- ) -> None:
50
- if agent is None:
51
- agent = Agent()
52
- self.agent = agent
53
- self.engine = engine
54
- self.run_task_timeout_seconds = run_task_timeout_seconds
55
-
56
- # TODO: agent haven't exposed the task v1 generate function, we can migrate to use agent interface when it's available
57
- async def _generate_v1_task_request(self, user_prompt: str) -> TaskGenerationBase:
58
- llm_prompt = prompt_engine.load_prompt("generate-task", user_prompt=user_prompt)
59
- llm_response = await app.LLM_API_HANDLER(prompt=llm_prompt, prompt_name="generate-task")
60
- return TaskGenerationBase.model_validate(llm_response)
61
-
62
- async def run_task(self, user_prompt: str, url: Optional[str] = None) -> TaskResponse | ObserverTask:
63
- """
64
- Use Skyvern agent to run a task. This function won't return until the task is finished.
65
-
66
- Args:
67
- user_prompt[str]: The user's prompt describing the task.
68
- url (Optional[str]): The URL of the target website for the task.
69
- """
70
-
71
- if self.engine == "TaskV1":
72
- return await self.run_task_v1(user_prompt=user_prompt, url=url)
73
- else:
74
- return await self.run_task_v2(user_prompt=user_prompt, url=url)
75
-
76
- async def dispatch_task(self, user_prompt: str, url: Optional[str] = None) -> CreateTaskResponse | ObserverTask:
77
- """
78
- Use Skyvern agent to dispatch a task. This function will return immediately and the task will be running in the background.
79
-
80
- Args:
81
- user_prompt[str]: The user's prompt describing the task.
82
- url (Optional[str]): The URL of the target website for the task.
83
- """
84
-
85
- if self.engine == "TaskV1":
86
- return await self.dispatch_task_v1(user_prompt=user_prompt, url=url)
87
- else:
88
- return await self.dispatch_task_v2(user_prompt=user_prompt, url=url)
89
-
90
- async def get_task(self, task_id: str) -> TaskResponse | ObserverTask | None:
91
- """
92
- Use Skyvern agent to get a task.
93
-
94
- Args:
95
- task_id[str]: The id of the task.
96
- """
97
-
98
- if self.engine == "TaskV1":
99
- return await self.get_task_v1(task_id)
100
- else:
101
- return await self.get_task_v2(task_id)
102
-
103
- async def run_task_v1(self, user_prompt: str, url: Optional[str] = None) -> TaskResponse:
104
- task_generation = await self._generate_v1_task_request(user_prompt=user_prompt)
105
- task_request = TaskRequest.model_validate(task_generation, from_attributes=True)
106
- if url is not None:
107
- task_request.url = url
108
-
109
- return await self.agent.run_task(task_request=task_request, timeout_seconds=self.run_task_timeout_seconds)
110
-
111
- async def dispatch_task_v1(self, user_prompt: str, url: Optional[str] = None) -> CreateTaskResponse:
112
- task_generation = await self._generate_v1_task_request(user_prompt=user_prompt)
113
- task_request = TaskRequest.model_validate(task_generation, from_attributes=True)
114
- if url is not None:
115
- task_request.url = url
116
-
117
- return await self.agent.create_task(task_request=task_request)
118
-
119
- async def get_task_v1(self, task_id: str) -> TaskResponse | None:
120
- return await self.agent.get_task(task_id=task_id)
121
-
122
- async def run_task_v2(self, user_prompt: str, url: Optional[str] = None) -> ObserverTask:
123
- task_request = ObserverTaskRequest(user_prompt=user_prompt, url=url)
124
- return await self.agent.run_observer_task_v_2(
125
- task_request=task_request, timeout_seconds=self.run_task_timeout_seconds
126
- )
127
-
128
- async def dispatch_task_v2(self, user_prompt: str, url: Optional[str] = None) -> ObserverTask:
129
- task_request = ObserverTaskRequest(user_prompt=user_prompt, url=url)
130
- return await self.agent.observer_task_v_2(task_request=task_request)
131
-
132
- async def get_task_v2(self, task_id: str) -> ObserverTask | None:
133
- return await self.agent.get_observer_task_v_2(task_id=task_id)
@@ -1,173 +0,0 @@
1
- from typing import Any, Dict, List, Literal, Optional
2
-
3
- from httpx import AsyncClient
4
- from llama_index.core.tools import FunctionTool
5
- from llama_index.core.tools.tool_spec.base import SPEC_FUNCTION_TYPE, BaseToolSpec
6
- from pydantic import BaseModel
7
- from skyvern_llamaindex.settings import settings
8
-
9
- from skyvern.client import AsyncSkyvern
10
- from skyvern.forge.sdk.schemas.observers import ObserverTaskRequest
11
- from skyvern.forge.sdk.schemas.tasks import CreateTaskResponse, TaskRequest, TaskResponse
12
-
13
-
14
- class SkyvernTool(BaseModel):
15
- api_key: str = settings.api_key
16
- base_url: str = settings.base_url
17
-
18
- def run_task(self) -> FunctionTool:
19
- task_tool_spec = SkyvernTaskToolSpec(
20
- api_key=self.api_key,
21
- base_url=self.base_url,
22
- )
23
-
24
- return task_tool_spec.to_tool_list(["run_task"])[0]
25
-
26
- def dispatch_task(self) -> FunctionTool:
27
- task_tool_spec = SkyvernTaskToolSpec(
28
- api_key=self.api_key,
29
- base_url=self.base_url,
30
- )
31
-
32
- return task_tool_spec.to_tool_list(["dispatch_task"])[0]
33
-
34
- def get_task(self) -> FunctionTool:
35
- task_tool_spec = SkyvernTaskToolSpec(
36
- api_key=self.api_key,
37
- base_url=self.base_url,
38
- )
39
-
40
- return task_tool_spec.to_tool_list(["get_task"])[0]
41
-
42
-
43
- class SkyvernTaskToolSpec(BaseToolSpec):
44
- spec_functions: List[SPEC_FUNCTION_TYPE] = [
45
- "run_task",
46
- "dispatch_task",
47
- "get_task",
48
- ]
49
-
50
- def __init__(
51
- self,
52
- *,
53
- api_key: str = settings.api_key,
54
- base_url: str = settings.base_url,
55
- engine: Literal["TaskV1", "TaskV2"] = settings.engine,
56
- run_task_timeout_seconds: int = settings.run_task_timeout_seconds,
57
- ):
58
- httpx_client = AsyncClient(
59
- headers={
60
- "Content-Type": "application/json",
61
- "x-api-key": api_key,
62
- },
63
- )
64
- self.engine = engine
65
- self.run_task_timeout_seconds = run_task_timeout_seconds
66
- self.client = AsyncSkyvern(base_url=base_url, httpx_client=httpx_client)
67
-
68
- async def run_task(self, user_prompt: str, url: Optional[str] = None) -> TaskResponse | Dict[str, Any | None]:
69
- """
70
- Use Skyvern client to run a task. This function won't return until the task is finished.
71
-
72
- Args:
73
- user_prompt[str]: The user's prompt describing the task.
74
- url (Optional[str]): The URL of the target website for the task.
75
- """
76
-
77
- if self.engine == "TaskV1":
78
- return await self.run_task_v1(user_prompt=user_prompt, url=url)
79
- else:
80
- return await self.run_task_v2(user_prompt=user_prompt, url=url)
81
-
82
- async def dispatch_task(
83
- self, user_prompt: str, url: Optional[str] = None
84
- ) -> CreateTaskResponse | Dict[str, Any | None]:
85
- """
86
- Use Skyvern client to dispatch a task. This function will return immediately and the task will be running in the background.
87
-
88
- Args:
89
- user_prompt[str]: The user's prompt describing the task.
90
- url (Optional[str]): The URL of the target website for the task.
91
- """
92
-
93
- if self.engine == "TaskV1":
94
- return await self.dispatch_task_v1(user_prompt=user_prompt, url=url)
95
- else:
96
- return await self.dispatch_task_v2(user_prompt=user_prompt, url=url)
97
-
98
- async def get_task(self, task_id: str) -> TaskResponse | Dict[str, Any | None]:
99
- """
100
- Use Skyvern client to get a task.
101
-
102
- Args:
103
- task_id[str]: The id of the task.
104
- """
105
-
106
- if self.engine == "TaskV1":
107
- return await self.get_task_v1(task_id)
108
- else:
109
- return await self.get_task_v2(task_id)
110
-
111
- async def run_task_v1(self, user_prompt: str, url: Optional[str] = None) -> TaskResponse:
112
- task_generation = await self.client.agent.generate_task(
113
- prompt=user_prompt,
114
- )
115
- task_request = TaskRequest.model_validate(task_generation, from_attributes=True)
116
- if url is not None:
117
- task_request.url = url
118
-
119
- return await self.client.agent.run_task(
120
- timeout_seconds=self.run_task_timeout_seconds,
121
- url=task_request.url,
122
- title=task_request.title,
123
- navigation_goal=task_request.navigation_goal,
124
- data_extraction_goal=task_request.data_extraction_goal,
125
- navigation_payload=task_request.navigation_goal,
126
- error_code_mapping=task_request.error_code_mapping,
127
- extracted_information_schema=task_request.extracted_information_schema,
128
- complete_criterion=task_request.complete_criterion,
129
- terminate_criterion=task_request.terminate_criterion,
130
- )
131
-
132
- async def dispatch_task_v1(self, user_prompt: str, url: Optional[str] = None) -> CreateTaskResponse:
133
- task_generation = await self.client.agent.generate_task(
134
- prompt=user_prompt,
135
- )
136
- task_request = TaskRequest.model_validate(task_generation, from_attributes=True)
137
- if url is not None:
138
- task_request.url = url
139
-
140
- return await self.client.agent.create_task(
141
- url=task_request.url,
142
- title=task_request.title,
143
- navigation_goal=task_request.navigation_goal,
144
- data_extraction_goal=task_request.data_extraction_goal,
145
- navigation_payload=task_request.navigation_goal,
146
- error_code_mapping=task_request.error_code_mapping,
147
- extracted_information_schema=task_request.extracted_information_schema,
148
- complete_criterion=task_request.complete_criterion,
149
- terminate_criterion=task_request.terminate_criterion,
150
- )
151
-
152
- async def get_task_v1(self, task_id: str) -> TaskResponse:
153
- return await self.client.agent.get_task(task_id=task_id)
154
-
155
- async def run_task_v2(self, user_prompt: str, url: Optional[str] = None) -> Dict[str, Any | None]:
156
- task_request = ObserverTaskRequest(url=url, user_prompt=user_prompt)
157
- return await self.client.agent.run_observer_task_v_2(
158
- timeout_seconds=self.run_task_timeout_seconds,
159
- user_prompt=task_request.user_prompt,
160
- url=task_request.url,
161
- browser_session_id=task_request.browser_session_id,
162
- )
163
-
164
- async def dispatch_task_v2(self, user_prompt: str, url: Optional[str] = None) -> Dict[str, Any | None]:
165
- task_request = ObserverTaskRequest(url=url, user_prompt=user_prompt)
166
- return await self.client.agent.observer_task_v_2(
167
- user_prompt=task_request.user_prompt,
168
- url=task_request.url,
169
- browser_session_id=task_request.browser_session_id,
170
- )
171
-
172
- async def get_task_v2(self, task_id: str) -> Dict[str, Any | None]:
173
- return await self.client.agent.get_observer_task_v_2(task_id=task_id)