skyvern-llamaindex 0.0.4__py3-none-any.whl → 0.2.0__py3-none-any.whl

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,23 +1,19 @@
1
- from typing import List, Literal, Optional
1
+ from typing import List, Optional
2
2
 
3
3
  from llama_index.core.tools import FunctionTool
4
4
  from llama_index.core.tools.tool_spec.base import SPEC_FUNCTION_TYPE, BaseToolSpec
5
5
  from skyvern_llamaindex.settings import settings
6
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()
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
15
11
 
16
12
 
17
13
  class SkyvernTool:
18
- def __init__(self, agent: Optional[Agent] = None):
14
+ def __init__(self, agent: Optional[Skyvern] = None):
19
15
  if agent is None:
20
- agent = default_agent
16
+ agent = Skyvern(base_url=None, api_key=None)
21
17
  self.agent = agent
22
18
 
23
19
  def run_task(self) -> FunctionTool:
@@ -43,23 +39,17 @@ class SkyvernTaskToolSpec(BaseToolSpec):
43
39
  def __init__(
44
40
  self,
45
41
  *,
46
- agent: Optional[Agent] = None,
47
- engine: Literal["TaskV1", "TaskV2"] = settings.engine,
42
+ agent: Skyvern | None = None,
43
+ engine: RunEngine = settings.engine,
48
44
  run_task_timeout_seconds: int = settings.run_task_timeout_seconds,
49
45
  ) -> None:
50
46
  if agent is None:
51
- agent = Agent()
47
+ agent = Skyvern(base_url=None, api_key=None)
52
48
  self.agent = agent
53
49
  self.engine = engine
54
50
  self.run_task_timeout_seconds = run_task_timeout_seconds
55
51
 
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:
52
+ async def run_task(self, user_prompt: str, url: Optional[str] = None) -> TaskRunResponse:
63
53
  """
64
54
  Use Skyvern agent to run a task. This function won't return until the task is finished.
65
55
 
@@ -67,13 +57,15 @@ class SkyvernTaskToolSpec(BaseToolSpec):
67
57
  user_prompt[str]: The user's prompt describing the task.
68
58
  url (Optional[str]): The URL of the target website for the task.
69
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
+ )
70
67
 
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:
68
+ async def dispatch_task(self, user_prompt: str, url: Optional[str] = None) -> TaskRunResponse:
77
69
  """
78
70
  Use Skyvern agent to dispatch a task. This function will return immediately and the task will be running in the background.
79
71
 
@@ -81,53 +73,19 @@ class SkyvernTaskToolSpec(BaseToolSpec):
81
73
  user_prompt[str]: The user's prompt describing the task.
82
74
  url (Optional[str]): The URL of the target website for the task.
83
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
+ )
84
83
 
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:
84
+ async def get_task(self, task_id: str) -> GetRunResponse | None:
91
85
  """
92
86
  Use Skyvern agent to get a task.
93
87
 
94
88
  Args:
95
89
  task_id[str]: The id of the task.
96
90
  """
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)
91
+ return await self.agent.get_run(run_id=task_id)
@@ -1,14 +1,14 @@
1
- from typing import Any, Dict, List, Literal, Optional
1
+ from typing import List, Optional
2
2
 
3
- from httpx import AsyncClient
4
3
  from llama_index.core.tools import FunctionTool
5
4
  from llama_index.core.tools.tool_spec.base import SPEC_FUNCTION_TYPE, BaseToolSpec
6
5
  from pydantic import BaseModel
7
6
  from skyvern_llamaindex.settings import settings
8
7
 
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
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
12
 
13
13
 
14
14
  class SkyvernTool(BaseModel):
@@ -52,20 +52,14 @@ class SkyvernTaskToolSpec(BaseToolSpec):
52
52
  *,
53
53
  api_key: str = settings.api_key,
54
54
  base_url: str = settings.base_url,
55
- engine: Literal["TaskV1", "TaskV2"] = settings.engine,
55
+ engine: RunEngine = settings.engine,
56
56
  run_task_timeout_seconds: int = settings.run_task_timeout_seconds,
57
57
  ):
58
- httpx_client = AsyncClient(
59
- headers={
60
- "Content-Type": "application/json",
61
- "x-api-key": api_key,
62
- },
63
- )
64
58
  self.engine = engine
65
59
  self.run_task_timeout_seconds = run_task_timeout_seconds
66
- self.client = AsyncSkyvern(base_url=base_url, httpx_client=httpx_client)
60
+ self.client = Skyvern(base_url=base_url, api_key=api_key)
67
61
 
68
- async def run_task(self, user_prompt: str, url: Optional[str] = None) -> TaskResponse | Dict[str, Any | None]:
62
+ async def run_task(self, user_prompt: str, url: Optional[str] = None) -> TaskRunResponse:
69
63
  """
70
64
  Use Skyvern client to run a task. This function won't return until the task is finished.
71
65
 
@@ -74,14 +68,15 @@ class SkyvernTaskToolSpec(BaseToolSpec):
74
68
  url (Optional[str]): The URL of the target website for the task.
75
69
  """
76
70
 
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)
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
+ )
81
78
 
82
- async def dispatch_task(
83
- self, user_prompt: str, url: Optional[str] = None
84
- ) -> CreateTaskResponse | Dict[str, Any | None]:
79
+ async def dispatch_task(self, user_prompt: str, url: Optional[str] = None) -> TaskRunResponse:
85
80
  """
86
81
  Use Skyvern client to dispatch a task. This function will return immediately and the task will be running in the background.
87
82
 
@@ -90,12 +85,15 @@ class SkyvernTaskToolSpec(BaseToolSpec):
90
85
  url (Optional[str]): The URL of the target website for the task.
91
86
  """
92
87
 
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)
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
+ )
97
95
 
98
- async def get_task(self, task_id: str) -> TaskResponse | Dict[str, Any | None]:
96
+ async def get_task(self, task_id: str) -> GetRunResponse | None:
99
97
  """
100
98
  Use Skyvern client to get a task.
101
99
 
@@ -103,71 +101,4 @@ class SkyvernTaskToolSpec(BaseToolSpec):
103
101
  task_id[str]: The id of the task.
104
102
  """
105
103
 
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)
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,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
@@ -0,0 +1,8 @@
1
+ skyvern_llamaindex/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ skyvern_llamaindex/agent.py,sha256=wEpTUJpP0_VL0l0v9VckrG0pX96AI4T6M74Z6mUgdvI,3191
3
+ skyvern_llamaindex/client.py,sha256=KRFlJgzsYJUAutvqMSNH0QfzEkRHJT_lkr_fSrfFsxk,3335
4
+ skyvern_llamaindex/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ skyvern_llamaindex/settings.py,sha256=PG8SyXuwXvRmgWLEkF8i7bgn8pcvznin7opzTMFKEkM,396
6
+ skyvern_llamaindex-0.2.0.dist-info/METADATA,sha256=RZUCTR-zR9JEwVPSa4KfX3ct0n53Klulh1gpZIZy2UA,10640
7
+ skyvern_llamaindex-0.2.0.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
8
+ skyvern_llamaindex-0.2.0.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- skyvern_llamaindex/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- skyvern_llamaindex/agent.py,sha256=BrA9JxqyETTnJcVv_Hj18oFeDesOINpPpXpszh0F-pc,5622
3
- skyvern_llamaindex/client.py,sha256=JZZXghqLctZ_yV2XwNNOHhHcPYN7Q38jevOAuzUh4JU,6834
4
- skyvern_llamaindex/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
- skyvern_llamaindex/settings.py,sha256=DsW7xaol9azsJ89b9qvJfoB2BWqSR3C5BkiL1aYx8Ws,386
6
- skyvern_llamaindex-0.0.4.dist-info/METADATA,sha256=xdaJbvcWjUyqbAslNuFAyDixt1JAKTqem67fWMDjYxI,10787
7
- skyvern_llamaindex-0.0.4.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
8
- skyvern_llamaindex-0.0.4.dist-info/RECORD,,