skyvern-llamaindex 0.0.4__py3-none-any.whl → 0.0.5__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.
- skyvern_llamaindex/agent.py +28 -70
- skyvern_llamaindex/client.py +25 -94
- skyvern_llamaindex/settings.py +3 -3
- {skyvern_llamaindex-0.0.4.dist-info → skyvern_llamaindex-0.0.5.dist-info}/METADATA +6 -7
- skyvern_llamaindex-0.0.5.dist-info/RECORD +8 -0
- skyvern_llamaindex-0.0.4.dist-info/RECORD +0 -8
- {skyvern_llamaindex-0.0.4.dist-info → skyvern_llamaindex-0.0.5.dist-info}/WHEEL +0 -0
skyvern_llamaindex/agent.py
CHANGED
@@ -1,23 +1,19 @@
|
|
1
|
-
from typing import List,
|
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
|
8
|
-
from skyvern.
|
9
|
-
from skyvern.
|
10
|
-
from skyvern.
|
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.agent.types.agent_get_run_response import AgentGetRunResponse
|
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[
|
14
|
+
def __init__(self, agent: Optional[Skyvern] = None):
|
19
15
|
if agent is None:
|
20
|
-
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:
|
47
|
-
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 =
|
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
|
-
|
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
|
-
|
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
|
-
|
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) -> AgentGetRunResponse | 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)
|
skyvern_llamaindex/client.py
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
from typing import
|
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
|
10
|
-
from skyvern.
|
11
|
-
from skyvern.
|
8
|
+
from skyvern import Skyvern
|
9
|
+
from skyvern.client.agent.types.agent_get_run_response import AgentGetRunResponse
|
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:
|
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 =
|
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) ->
|
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
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
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
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
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) ->
|
96
|
+
async def get_task(self, task_id: str) -> AgentGetRunResponse | 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
|
-
|
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)
|
skyvern_llamaindex/settings.py
CHANGED
@@ -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:
|
10
|
+
engine: RunEngine = RunEngine.skyvern_v2
|
11
11
|
run_task_timeout_seconds: int = 60 * 60
|
12
12
|
|
13
13
|
class Config:
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: skyvern-llamaindex
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.5
|
4
4
|
Summary: Skyvern integration for LlamaIndex
|
5
5
|
Author: lawyzheng
|
6
6
|
Author-email: lawy@skyvern.com
|
@@ -8,12 +8,11 @@ Requires-Python: >=3.11,<3.12
|
|
8
8
|
Classifier: Programming Language :: Python :: 3
|
9
9
|
Classifier: Programming Language :: Python :: 3.11
|
10
10
|
Requires-Dist: llama-index (>=0.12.19,<0.13.0)
|
11
|
-
Requires-Dist: skyvern (>=0.1.
|
11
|
+
Requires-Dist: skyvern (>=0.1.84)
|
12
12
|
Description-Content-Type: text/markdown
|
13
13
|
|
14
14
|
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
15
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
16
|
|
18
17
|
- [Skyvern LlamaIndex](#skyvern-llamaindex)
|
19
18
|
- [Installation](#installation)
|
@@ -45,7 +44,7 @@ pip install skyvern-llamaindex
|
|
45
44
|
### Run a task(sync) locally in your local environment
|
46
45
|
> sync task won't return until the task is finished.
|
47
46
|
|
48
|
-
:warning: :warning: if you want to run this code block, you need to run `skyvern init
|
47
|
+
: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
48
|
|
50
49
|
|
51
50
|
```python
|
@@ -74,7 +73,7 @@ print(response)
|
|
74
73
|
|
75
74
|
: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
75
|
|
77
|
-
:warning: :warning: if you want to run this code block, you need to run `skyvern init
|
76
|
+
: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
77
|
|
79
78
|
```python
|
80
79
|
import asyncio
|
@@ -112,7 +111,7 @@ print(response)
|
|
112
111
|
|
113
112
|
### Get a task locally in your local environment
|
114
113
|
|
115
|
-
:warning: :warning: if you want to run this code block, you need to run `skyvern init
|
114
|
+
: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
115
|
|
117
116
|
```python
|
118
117
|
from dotenv import load_dotenv
|
@@ -228,7 +227,7 @@ To provide some examples of how to integrate Skyvern with other llama-index tool
|
|
228
227
|
### Dispatch a task(async) locally in your local environment and wait until the task is finished
|
229
228
|
> 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
229
|
|
231
|
-
:warning: :warning: if you want to run this code block, you need to run `skyvern init
|
230
|
+
: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
231
|
|
233
232
|
```python
|
234
233
|
import asyncio
|
@@ -0,0 +1,8 @@
|
|
1
|
+
skyvern_llamaindex/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
+
skyvern_llamaindex/agent.py,sha256=0Qz1HOCcajL-uAzh6TT5pwS2AI8_IldBhzEIz3lm7SE,3213
|
3
|
+
skyvern_llamaindex/client.py,sha256=0OCEUEmOP4UD6pR7Vt34lICFjU2NAS5ZI7ce0oIT4cA,3357
|
4
|
+
skyvern_llamaindex/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
5
|
+
skyvern_llamaindex/settings.py,sha256=PG8SyXuwXvRmgWLEkF8i7bgn8pcvznin7opzTMFKEkM,396
|
6
|
+
skyvern_llamaindex-0.0.5.dist-info/METADATA,sha256=qhOISJr-RsdWZMQRP2mKDIcJN3EoR9GbrLxhVmHj6Ak,10539
|
7
|
+
skyvern_llamaindex-0.0.5.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
|
8
|
+
skyvern_llamaindex-0.0.5.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,,
|
File without changes
|