skyvern-llamaindex 0.0.3__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 +78 -96
- skyvern_llamaindex/client.py +84 -152
- skyvern_llamaindex/settings.py +18 -0
- skyvern_llamaindex-0.0.5.dist-info/METADATA +307 -0
- skyvern_llamaindex-0.0.5.dist-info/RECORD +8 -0
- {skyvern_llamaindex-0.0.3.dist-info → skyvern_llamaindex-0.0.5.dist-info}/WHEEL +1 -1
- skyvern_llamaindex/schema.py +0 -18
- skyvern_llamaindex-0.0.3.dist-info/METADATA +0 -197
- skyvern_llamaindex-0.0.3.dist-info/RECORD +0 -8
skyvern_llamaindex/agent.py
CHANGED
@@ -1,109 +1,91 @@
|
|
1
|
-
from typing import
|
1
|
+
from typing import List, Optional
|
2
2
|
|
3
|
+
from llama_index.core.tools import FunctionTool
|
3
4
|
from llama_index.core.tools.tool_spec.base import SPEC_FUNCTION_TYPE, BaseToolSpec
|
4
|
-
from
|
5
|
-
from skyvern_llamaindex.schema import GetTaskInput, TaskV1Request, TaskV2Request
|
5
|
+
from skyvern_llamaindex.settings import settings
|
6
6
|
|
7
|
-
from skyvern
|
8
|
-
from skyvern.
|
9
|
-
from skyvern.
|
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
|
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]
|
10
30
|
|
11
31
|
|
12
32
|
class SkyvernTaskToolSpec(BaseToolSpec):
|
13
33
|
spec_functions: List[SPEC_FUNCTION_TYPE] = [
|
14
|
-
"
|
15
|
-
"
|
16
|
-
"
|
34
|
+
"run_task",
|
35
|
+
"dispatch_task",
|
36
|
+
"get_task",
|
17
37
|
]
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
),
|
30
|
-
"get": ToolMetadata(
|
31
|
-
name="get-skyvern-agent-task",
|
32
|
-
description="Use Skyvern agent to get a task.",
|
33
|
-
fn_schema=GetTaskInput,
|
34
|
-
),
|
35
|
-
},
|
36
|
-
"TaskV2": {
|
37
|
-
"run": ToolMetadata(
|
38
|
-
name="run-skyvern-agent-task",
|
39
|
-
description="Use Skyvern agent to run a task. This function won't return until the task is finished.",
|
40
|
-
fn_schema=TaskV2Request,
|
41
|
-
),
|
42
|
-
"dispatch": ToolMetadata(
|
43
|
-
name="dispatch-skyvern-agent-task",
|
44
|
-
description="Use Skyvern agent to dispatch a task. This function will return immediately and the task will be running in the background.",
|
45
|
-
fn_schema=TaskV2Request,
|
46
|
-
),
|
47
|
-
"get": ToolMetadata(
|
48
|
-
name="get-skyvern-agent-task",
|
49
|
-
description="Use Skyvern agent to get a task.",
|
50
|
-
fn_schema=GetTaskInput,
|
51
|
-
),
|
52
|
-
},
|
53
|
-
}
|
54
|
-
|
55
|
-
def __init__(self, *, engine: Literal["TaskV1", "TaskV2"] = "TaskV2") -> None:
|
56
|
-
self.agent = Agent()
|
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
|
57
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
|
+
)
|
58
67
|
|
59
|
-
def
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
return self.
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
return await self.run_task_v2(**kwargs)
|
74
|
-
|
75
|
-
async def dispatch(self, **kwargs: Dict[str, Any]) -> CreateTaskResponse | ObserverTask:
|
76
|
-
if self.engine == "TaskV1":
|
77
|
-
return await self.dispatch_task_v1(**kwargs)
|
78
|
-
else:
|
79
|
-
return await self.dispatch_task_v2(**kwargs)
|
80
|
-
|
81
|
-
async def get(self, task_id: str) -> TaskResponse | ObserverTask | None:
|
82
|
-
if self.engine == "TaskV1":
|
83
|
-
return await self.get_task_v1(task_id)
|
84
|
-
else:
|
85
|
-
return await self.get_task_v2(task_id)
|
86
|
-
|
87
|
-
async def run_task_v1(self, **kwargs: Dict[str, Any]) -> TaskResponse:
|
88
|
-
task_request = TaskV1Request(**kwargs)
|
89
|
-
return await self.agent.run_task(task_request=task_request, timeout_seconds=task_request.timeout_seconds)
|
90
|
-
|
91
|
-
async def dispatch_task_v1(self, **kwargs: Dict[str, Any]) -> CreateTaskResponse:
|
92
|
-
task_request = TaskV1Request(**kwargs)
|
93
|
-
return await self.agent.create_task(task_request=task_request)
|
94
|
-
|
95
|
-
async def get_task_v1(self, task_id: str) -> TaskResponse | None:
|
96
|
-
return await self.agent.get_task(task_id=task_id)
|
97
|
-
|
98
|
-
async def run_task_v2(self, **kwargs: Dict[str, Any]) -> ObserverTask:
|
99
|
-
task_request = TaskV2Request(**kwargs)
|
100
|
-
return await self.agent.run_observer_task_v_2(
|
101
|
-
task_request=task_request, timeout_seconds=task_request.timeout_seconds
|
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,
|
102
82
|
)
|
103
83
|
|
104
|
-
async def
|
105
|
-
|
106
|
-
|
84
|
+
async def get_task(self, task_id: str) -> AgentGetRunResponse | None:
|
85
|
+
"""
|
86
|
+
Use Skyvern agent to get a task.
|
107
87
|
|
108
|
-
|
109
|
-
|
88
|
+
Args:
|
89
|
+
task_id[str]: The id of the task.
|
90
|
+
"""
|
91
|
+
return await self.agent.get_run(run_id=task_id)
|
skyvern_llamaindex/client.py
CHANGED
@@ -1,172 +1,104 @@
|
|
1
|
-
from typing import
|
1
|
+
from typing import List, Optional
|
2
2
|
|
3
|
-
from
|
3
|
+
from llama_index.core.tools import FunctionTool
|
4
4
|
from llama_index.core.tools.tool_spec.base import SPEC_FUNCTION_TYPE, BaseToolSpec
|
5
|
-
from
|
6
|
-
from skyvern_llamaindex.
|
5
|
+
from pydantic import BaseModel
|
6
|
+
from skyvern_llamaindex.settings import settings
|
7
7
|
|
8
|
-
from skyvern
|
9
|
-
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
|
+
|
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]
|
10
41
|
|
11
42
|
|
12
43
|
class SkyvernTaskToolSpec(BaseToolSpec):
|
13
44
|
spec_functions: List[SPEC_FUNCTION_TYPE] = [
|
14
|
-
"
|
15
|
-
"
|
16
|
-
"
|
45
|
+
"run_task",
|
46
|
+
"dispatch_task",
|
47
|
+
"get_task",
|
17
48
|
]
|
18
49
|
|
19
|
-
spec_metadata: Dict[str, Dict[str, ToolMetadata]] = {
|
20
|
-
"TaskV1": {
|
21
|
-
"run": ToolMetadata(
|
22
|
-
name="run-skyvern-client-task",
|
23
|
-
description="Use Skyvern client to run a task. This function won't return until the task is finished.",
|
24
|
-
fn_schema=TaskV1Request,
|
25
|
-
),
|
26
|
-
"dispatch": ToolMetadata(
|
27
|
-
name="dispatch-skyvern-client-task",
|
28
|
-
description="Use Skyvern client to dispatch a task. This function will return immediately and the task will be running in the background.",
|
29
|
-
fn_schema=TaskV1Request,
|
30
|
-
),
|
31
|
-
"get": ToolMetadata(
|
32
|
-
name="get-skyvern-client-task",
|
33
|
-
description="Use Skyvern client to get a task.",
|
34
|
-
fn_schema=GetTaskInput,
|
35
|
-
),
|
36
|
-
},
|
37
|
-
"TaskV2": {
|
38
|
-
"run": ToolMetadata(
|
39
|
-
name="run-skyvern-client-task",
|
40
|
-
description="Use Skyvern client to run a task. This function won't return until the task is finished.",
|
41
|
-
fn_schema=TaskV2Request,
|
42
|
-
),
|
43
|
-
"dispatch": ToolMetadata(
|
44
|
-
name="dispatch-skyvern-client-task",
|
45
|
-
description="Use Skyvern client to dispatch a task. This function will return immediately and the task will be running in the background.",
|
46
|
-
fn_schema=TaskV2Request,
|
47
|
-
),
|
48
|
-
"get": ToolMetadata(
|
49
|
-
name="get-skyvern-client-task",
|
50
|
-
description="Use Skyvern client to get a task.",
|
51
|
-
fn_schema=GetTaskInput,
|
52
|
-
),
|
53
|
-
},
|
54
|
-
}
|
55
|
-
|
56
50
|
def __init__(
|
57
51
|
self,
|
58
|
-
credential: str,
|
59
52
|
*,
|
60
|
-
|
61
|
-
|
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,
|
62
57
|
):
|
63
|
-
httpx_client = AsyncClient(
|
64
|
-
headers={
|
65
|
-
"Content-Type": "application/json",
|
66
|
-
"x-api-key": credential,
|
67
|
-
},
|
68
|
-
)
|
69
58
|
self.engine = engine
|
70
|
-
self.
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
async def dispatch(self, **kwargs: Dict[str, Any]) -> CreateTaskResponse | Dict[str, Any | None]:
|
89
|
-
if self.engine == "TaskV1":
|
90
|
-
return await self.dispatch_task_v1(**kwargs)
|
91
|
-
else:
|
92
|
-
return await self.dispatch_task_v2(**kwargs)
|
93
|
-
|
94
|
-
async def get(self, task_id: str) -> TaskResponse | Dict[str, Any | None]:
|
95
|
-
if self.engine == "TaskV1":
|
96
|
-
return await self.get_task_v1(task_id)
|
97
|
-
else:
|
98
|
-
return await self.get_task_v2(task_id)
|
99
|
-
|
100
|
-
async def run_task_v1(self, **kwargs: Dict[str, Any]) -> TaskResponse:
|
101
|
-
task_request = TaskV1Request(**kwargs)
|
102
|
-
return await self.client.agent.run_task(
|
103
|
-
max_steps_override=task_request.max_steps,
|
104
|
-
timeout_seconds=task_request.timeout_seconds,
|
105
|
-
url=task_request.url,
|
106
|
-
title=task_request.title,
|
107
|
-
webhook_callback_url=task_request.webhook_callback_url,
|
108
|
-
totp_verification_url=task_request.totp_verification_url,
|
109
|
-
totp_identifier=task_request.totp_identifier,
|
110
|
-
navigation_goal=task_request.navigation_goal,
|
111
|
-
data_extraction_goal=task_request.data_extraction_goal,
|
112
|
-
navigation_payload=task_request.navigation_goal,
|
113
|
-
error_code_mapping=task_request.error_code_mapping,
|
114
|
-
proxy_location=task_request.proxy_location,
|
115
|
-
extracted_information_schema=task_request.extracted_information_schema,
|
116
|
-
complete_criterion=task_request.complete_criterion,
|
117
|
-
terminate_criterion=task_request.terminate_criterion,
|
118
|
-
browser_session_id=task_request.browser_session_id,
|
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,
|
119
77
|
)
|
120
78
|
|
121
|
-
async def
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
complete_criterion=task_request.complete_criterion,
|
137
|
-
terminate_criterion=task_request.terminate_criterion,
|
138
|
-
browser_session_id=task_request.browser_session_id,
|
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,
|
139
94
|
)
|
140
95
|
|
141
|
-
async def
|
142
|
-
|
143
|
-
|
144
|
-
async def run_task_v2(self, **kwargs: Dict[str, Any]) -> Dict[str, Any | None]:
|
145
|
-
task_request = TaskV2Request(**kwargs)
|
146
|
-
return await self.client.agent.run_observer_task_v_2(
|
147
|
-
max_iterations_override=task_request.max_iterations,
|
148
|
-
timeout_seconds=task_request.timeout_seconds,
|
149
|
-
user_prompt=task_request.user_prompt,
|
150
|
-
url=task_request.url,
|
151
|
-
browser_session_id=task_request.browser_session_id,
|
152
|
-
webhook_callback_url=task_request.webhook_callback_url,
|
153
|
-
totp_verification_url=task_request.totp_verification_url,
|
154
|
-
totp_identifier=task_request.totp_identifier,
|
155
|
-
proxy_location=task_request.proxy_location,
|
156
|
-
)
|
96
|
+
async def get_task(self, task_id: str) -> AgentGetRunResponse | None:
|
97
|
+
"""
|
98
|
+
Use Skyvern client to get a task.
|
157
99
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
max_iterations_override=task_request.max_iterations,
|
162
|
-
user_prompt=task_request.user_prompt,
|
163
|
-
url=task_request.url,
|
164
|
-
browser_session_id=task_request.browser_session_id,
|
165
|
-
webhook_callback_url=task_request.webhook_callback_url,
|
166
|
-
totp_verification_url=task_request.totp_verification_url,
|
167
|
-
totp_identifier=task_request.totp_identifier,
|
168
|
-
proxy_location=task_request.proxy_location,
|
169
|
-
)
|
100
|
+
Args:
|
101
|
+
task_id[str]: The id of the task.
|
102
|
+
"""
|
170
103
|
|
171
|
-
|
172
|
-
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)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
from dotenv import load_dotenv
|
2
|
+
from pydantic_settings import BaseSettings
|
3
|
+
|
4
|
+
from skyvern.schemas.runs import RunEngine
|
5
|
+
|
6
|
+
|
7
|
+
class Settings(BaseSettings):
|
8
|
+
api_key: str = ""
|
9
|
+
base_url: str = "https://api.skyvern.com"
|
10
|
+
engine: RunEngine = RunEngine.skyvern_v2
|
11
|
+
run_task_timeout_seconds: int = 60 * 60
|
12
|
+
|
13
|
+
class Config:
|
14
|
+
env_prefix = "SKYVERN_"
|
15
|
+
|
16
|
+
|
17
|
+
load_dotenv()
|
18
|
+
settings = Settings()
|
@@ -0,0 +1,307 @@
|
|
1
|
+
Metadata-Version: 2.3
|
2
|
+
Name: skyvern-llamaindex
|
3
|
+
Version: 0.0.5
|
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.84)
|
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
|
+
|
17
|
+
- [Skyvern LlamaIndex](#skyvern-llamaindex)
|
18
|
+
- [Installation](#installation)
|
19
|
+
- [Basic Usage](#basic-usage)
|
20
|
+
- [Run a task(sync) locally in your local environment](#run-a-tasksync-locally-in-your-local-environment)
|
21
|
+
- [Run a task(async) locally in your local environment](#run-a-taskasync-locally-in-your-local-environment)
|
22
|
+
- [Get a task locally in your local environment](#get-a-task-locally-in-your-local-environment)
|
23
|
+
- [Run a task(sync) by calling skyvern APIs](#run-a-tasksync-by-calling-skyvern-apis)
|
24
|
+
- [Run a task(async) by calling skyvern APIs](#run-a-taskasync-by-calling-skyvern-apis)
|
25
|
+
- [Get a task by calling skyvern APIs](#get-a-task-by-calling-skyvern-apis)
|
26
|
+
- [Advanced Usage](#advanced-usage)
|
27
|
+
- [Dispatch a task(async) locally in your local environment and wait until the task is finished](#dispatch-a-taskasync-locally-in-your-local-environment-and-wait-until-the-task-is-finished)
|
28
|
+
- [Dispatch a task(async) by calling skyvern APIs and wait until the task is finished](#dispatch-a-taskasync-by-calling-skyvern-apis-and-wait-until-the-task-is-finished)
|
29
|
+
|
30
|
+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
31
|
+
|
32
|
+
# Skyvern LlamaIndex
|
33
|
+
|
34
|
+
This is a LlamaIndex integration for Skyvern.
|
35
|
+
|
36
|
+
## Installation
|
37
|
+
|
38
|
+
```bash
|
39
|
+
pip install skyvern-llamaindex
|
40
|
+
```
|
41
|
+
|
42
|
+
## Basic Usage
|
43
|
+
|
44
|
+
### Run a task(sync) locally in your local environment
|
45
|
+
> sync task won't return until the task is finished.
|
46
|
+
|
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.
|
48
|
+
|
49
|
+
|
50
|
+
```python
|
51
|
+
from dotenv import load_dotenv
|
52
|
+
from llama_index.agent.openai import OpenAIAgent
|
53
|
+
from llama_index.llms.openai import OpenAI
|
54
|
+
from skyvern_llamaindex.agent import SkyvernTool
|
55
|
+
|
56
|
+
# load OpenAI API key from .env
|
57
|
+
load_dotenv()
|
58
|
+
|
59
|
+
skyvern_tool = SkyvernTool()
|
60
|
+
|
61
|
+
agent = OpenAIAgent.from_tools(
|
62
|
+
tools=[skyvern_tool.run_task()],
|
63
|
+
llm=OpenAI(model="gpt-4o"),
|
64
|
+
verbose=True,
|
65
|
+
)
|
66
|
+
|
67
|
+
response = agent.chat("Run a task with Skyvern. The task is about 'Navigate to the Hacker News homepage and get the top 3 posts.'")
|
68
|
+
print(response)
|
69
|
+
```
|
70
|
+
|
71
|
+
### Run a task(async) locally in your local environment
|
72
|
+
> async task will return immediately and the task will be running in the background.
|
73
|
+
|
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.
|
75
|
+
|
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.
|
77
|
+
|
78
|
+
```python
|
79
|
+
import asyncio
|
80
|
+
from dotenv import load_dotenv
|
81
|
+
from llama_index.agent.openai import OpenAIAgent
|
82
|
+
from llama_index.llms.openai import OpenAI
|
83
|
+
from skyvern_llamaindex.agent import SkyvernTool
|
84
|
+
from llama_index.core.tools import FunctionTool
|
85
|
+
|
86
|
+
# load OpenAI API key from .env
|
87
|
+
load_dotenv()
|
88
|
+
|
89
|
+
async def sleep(seconds: int) -> str:
|
90
|
+
await asyncio.sleep(seconds)
|
91
|
+
return f"Slept for {seconds} seconds"
|
92
|
+
|
93
|
+
# define a sleep tool to keep the agent running until the task is finished
|
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
|
+
skyvern_tool = SkyvernTool()
|
101
|
+
|
102
|
+
agent = OpenAIAgent.from_tools(
|
103
|
+
tools=[skyvern_tool.dispatch_task(), sleep_tool],
|
104
|
+
llm=OpenAI(model="gpt-4o"),
|
105
|
+
verbose=True,
|
106
|
+
)
|
107
|
+
|
108
|
+
response = agent.chat("Run a task with Skyvern. The task is about 'Navigate to the Hacker News homepage and get the top 3 posts.' Then, sleep for 10 minutes.")
|
109
|
+
print(response)
|
110
|
+
```
|
111
|
+
|
112
|
+
### Get a task locally in your local environment
|
113
|
+
|
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.
|
115
|
+
|
116
|
+
```python
|
117
|
+
from dotenv import load_dotenv
|
118
|
+
from llama_index.agent.openai import OpenAIAgent
|
119
|
+
from llama_index.llms.openai import OpenAI
|
120
|
+
from skyvern_llamaindex.agent import SkyvernTool
|
121
|
+
|
122
|
+
# load OpenAI API key from .env
|
123
|
+
load_dotenv()
|
124
|
+
|
125
|
+
skyvern_tool = SkyvernTool()
|
126
|
+
|
127
|
+
agent = OpenAIAgent.from_tools(
|
128
|
+
tools=[skyvern_tool.get_task()],
|
129
|
+
llm=OpenAI(model="gpt-4o"),
|
130
|
+
verbose=True,
|
131
|
+
)
|
132
|
+
|
133
|
+
response = agent.chat("Get the task information with Skyvern. The task id is '<task_id>'.")
|
134
|
+
print(response)
|
135
|
+
```
|
136
|
+
|
137
|
+
### Run a task(sync) by calling skyvern APIs
|
138
|
+
> sync task won't return until the task is finished.
|
139
|
+
|
140
|
+
no need to run `skyvern init` command in your terminal to set up skyvern before using this integration.
|
141
|
+
|
142
|
+
```python
|
143
|
+
from dotenv import load_dotenv
|
144
|
+
from llama_index.agent.openai import OpenAIAgent
|
145
|
+
from llama_index.llms.openai import OpenAI
|
146
|
+
from skyvern_llamaindex.client import SkyvernTool
|
147
|
+
|
148
|
+
# load OpenAI API key from .env
|
149
|
+
load_dotenv()
|
150
|
+
|
151
|
+
skyvern_tool = SkyvernTool(api_key="<your_organization_api_key>")
|
152
|
+
# or you can load the api_key from SKYVERN_API_KEY in .env
|
153
|
+
# skyvern_tool = SkyvernTool()
|
154
|
+
|
155
|
+
agent = OpenAIAgent.from_tools(
|
156
|
+
tools=[skyvern_tool.run_task()],
|
157
|
+
llm=OpenAI(model="gpt-4o"),
|
158
|
+
verbose=True,
|
159
|
+
)
|
160
|
+
|
161
|
+
response = agent.chat("Run a task with Skyvern. The task is about 'Navigate to the Hacker News homepage and get the top 3 posts.'")
|
162
|
+
print(response)
|
163
|
+
```
|
164
|
+
|
165
|
+
### Run a task(async) by calling skyvern APIs
|
166
|
+
> async task will return immediately and the task will be running in the background.
|
167
|
+
|
168
|
+
no need to run `skyvern init` command in your terminal to set up skyvern before using this integration.
|
169
|
+
|
170
|
+
the task is actually running in the skyvern cloud service, so you don't need to keep your agent running until the task is finished.
|
171
|
+
|
172
|
+
```python
|
173
|
+
from dotenv import load_dotenv
|
174
|
+
from llama_index.agent.openai import OpenAIAgent
|
175
|
+
from llama_index.llms.openai import OpenAI
|
176
|
+
from skyvern_llamaindex.client import SkyvernTool
|
177
|
+
|
178
|
+
# load OpenAI API key from .env
|
179
|
+
load_dotenv()
|
180
|
+
|
181
|
+
skyvern_tool = SkyvernTool(api_key="<your_organization_api_key>")
|
182
|
+
# or you can load the api_key from SKYVERN_API_KEY in .env
|
183
|
+
# skyvern_tool = SkyvernTool()
|
184
|
+
|
185
|
+
agent = OpenAIAgent.from_tools(
|
186
|
+
tools=[skyvern_tool.dispatch_task()],
|
187
|
+
llm=OpenAI(model="gpt-4o"),
|
188
|
+
verbose=True,
|
189
|
+
)
|
190
|
+
|
191
|
+
response = agent.chat("Run a task with Skyvern. The task is about 'Navigate to the Hacker News homepage and get the top 3 posts.'")
|
192
|
+
print(response)
|
193
|
+
```
|
194
|
+
|
195
|
+
|
196
|
+
### Get a task by calling skyvern APIs
|
197
|
+
|
198
|
+
no need to run `skyvern init` command in your terminal to set up skyvern before using this integration.
|
199
|
+
|
200
|
+
```python
|
201
|
+
from dotenv import load_dotenv
|
202
|
+
from llama_index.agent.openai import OpenAIAgent
|
203
|
+
from llama_index.llms.openai import OpenAI
|
204
|
+
from skyvern_llamaindex.client import SkyvernTool
|
205
|
+
|
206
|
+
# load OpenAI API key from .env
|
207
|
+
load_dotenv()
|
208
|
+
|
209
|
+
skyvern_tool = SkyvernTool(api_key="<your_organization_api_key>")
|
210
|
+
# or you can load the api_key from SKYVERN_API_KEY in .env
|
211
|
+
# skyvern_tool = SkyvernTool()
|
212
|
+
|
213
|
+
agent = OpenAIAgent.from_tools(
|
214
|
+
tools=[skyvern_tool.get_task()],
|
215
|
+
llm=OpenAI(model="gpt-4o"),
|
216
|
+
verbose=True,
|
217
|
+
)
|
218
|
+
|
219
|
+
response = agent.chat("Get the task information with Skyvern. The task id is '<task_id>'.")
|
220
|
+
print(response)
|
221
|
+
```
|
222
|
+
|
223
|
+
## Advanced Usage
|
224
|
+
|
225
|
+
To provide some examples of how to integrate Skyvern with other llama-index tools in the agent.
|
226
|
+
|
227
|
+
### Dispatch a task(async) locally in your local environment and wait until the task is finished
|
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.
|
229
|
+
|
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.
|
231
|
+
|
232
|
+
```python
|
233
|
+
import asyncio
|
234
|
+
from dotenv import load_dotenv
|
235
|
+
from llama_index.agent.openai import OpenAIAgent
|
236
|
+
from llama_index.llms.openai import OpenAI
|
237
|
+
from llama_index.core.tools import FunctionTool
|
238
|
+
from skyvern_llamaindex.agent import SkyvernTool
|
239
|
+
|
240
|
+
# load OpenAI API key from .env
|
241
|
+
load_dotenv()
|
242
|
+
|
243
|
+
async def sleep(seconds: int) -> str:
|
244
|
+
await asyncio.sleep(seconds)
|
245
|
+
return f"Slept for {seconds} seconds"
|
246
|
+
|
247
|
+
sleep_tool = FunctionTool.from_defaults(
|
248
|
+
async_fn=sleep,
|
249
|
+
description="Sleep for a given number of seconds",
|
250
|
+
name="sleep",
|
251
|
+
)
|
252
|
+
|
253
|
+
skyvern_tool = SkyvernTool()
|
254
|
+
|
255
|
+
agent = OpenAIAgent.from_tools(
|
256
|
+
tools=[skyvern_tool.dispatch_task(), skyvern_tool.get_task(), sleep_tool],
|
257
|
+
llm=OpenAI(model="gpt-4o"),
|
258
|
+
verbose=True,
|
259
|
+
max_function_calls=10,
|
260
|
+
)
|
261
|
+
|
262
|
+
response = agent.chat("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.")
|
263
|
+
print(response)
|
264
|
+
|
265
|
+
```
|
266
|
+
|
267
|
+
### Dispatch a task(async) by calling skyvern APIs and wait until the task is finished
|
268
|
+
> 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.
|
269
|
+
|
270
|
+
no need to run `skyvern init` command in your terminal to set up skyvern before using this integration.
|
271
|
+
|
272
|
+
```python
|
273
|
+
import asyncio
|
274
|
+
from dotenv import load_dotenv
|
275
|
+
from llama_index.agent.openai import OpenAIAgent
|
276
|
+
from llama_index.llms.openai import OpenAI
|
277
|
+
from llama_index.core.tools import FunctionTool
|
278
|
+
from skyvern_llamaindex.client import SkyvernTool
|
279
|
+
|
280
|
+
# load OpenAI API key from .env
|
281
|
+
load_dotenv()
|
282
|
+
|
283
|
+
async def sleep(seconds: int) -> str:
|
284
|
+
await asyncio.sleep(seconds)
|
285
|
+
return f"Slept for {seconds} seconds"
|
286
|
+
|
287
|
+
sleep_tool = FunctionTool.from_defaults(
|
288
|
+
async_fn=sleep,
|
289
|
+
description="Sleep for a given number of seconds",
|
290
|
+
name="sleep",
|
291
|
+
)
|
292
|
+
|
293
|
+
skyvern_tool = SkyvernTool(api_key="<your_organization_api_key>")
|
294
|
+
# or you can load the api_key from SKYVERN_API_KEY in .env
|
295
|
+
# skyvern_tool = SkyvernTool()
|
296
|
+
|
297
|
+
agent = OpenAIAgent.from_tools(
|
298
|
+
tools=[skyvern_tool.dispatch_task(), skyvern_tool.get_task(), sleep_tool],
|
299
|
+
llm=OpenAI(model="gpt-4o"),
|
300
|
+
verbose=True,
|
301
|
+
max_function_calls=10,
|
302
|
+
)
|
303
|
+
|
304
|
+
response = agent.chat("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.")
|
305
|
+
print(response)
|
306
|
+
|
307
|
+
```
|
@@ -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,,
|
skyvern_llamaindex/schema.py
DELETED
@@ -1,18 +0,0 @@
|
|
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
|
@@ -1,197 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.1
|
2
|
-
Name: skyvern-llamaindex
|
3
|
-
Version: 0.0.3
|
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
|
-
- [Dispatch a task(async) with skyvern agent (calling skyvern agent function directly in the tool)](#dispatch-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
|
-
- [Dispatch a task(async) with skyvern client (calling skyvern OpenAPI in the tool)](#dispatch-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 SkyvernTaskToolSpec
|
52
|
-
|
53
|
-
# load OpenAI API key from .env
|
54
|
-
load_dotenv()
|
55
|
-
|
56
|
-
skyvern_tool = SkyvernTaskToolSpec()
|
57
|
-
|
58
|
-
tools = skyvern_tool.to_tool_list(["run"])
|
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
|
-
### Dispatch a task(async) with skyvern agent (calling skyvern agent function directly in the tool)
|
73
|
-
> dispatch task will return immediately and the task will be running in the background. You can use `get` 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 SkyvernTaskToolSpec
|
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 = SkyvernTaskToolSpec()
|
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(["dispatch", "get"])
|
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("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.")
|
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 SkyvernTaskToolSpec
|
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 = SkyvernTaskToolSpec(
|
136
|
-
credential="<your_organization_api_key>",
|
137
|
-
)
|
138
|
-
|
139
|
-
tools = skyvern_client_tool.to_tool_list(["run"])
|
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
|
-
### Dispatch a task(async) with skyvern client (calling skyvern OpenAPI in the tool)
|
154
|
-
> dispatch task will return immediately and the task will be running in the background. You can use `get` 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 SkyvernTaskToolSpec
|
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 = SkyvernTaskToolSpec(
|
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(["dispatch", "get"])
|
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("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.")
|
195
|
-
print(response)
|
196
|
-
|
197
|
-
```
|
@@ -1,8 +0,0 @@
|
|
1
|
-
skyvern_llamaindex/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
-
skyvern_llamaindex/agent.py,sha256=LAW5IAXkMZL0PR8E2A0bl8KvdGIEnkZCyT3lWZoWVGY,4606
|
3
|
-
skyvern_llamaindex/client.py,sha256=o_5fmTFGHpLx-viTegJGiYdDIf11NOP5uXYlc9XXd-w,7682
|
4
|
-
skyvern_llamaindex/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
5
|
-
skyvern_llamaindex/schema.py,sha256=tTvnSC-ms_tW8bnzIn6FXPOCngom7l62B-IyhIwvRxQ,409
|
6
|
-
skyvern_llamaindex-0.0.3.dist-info/METADATA,sha256=mewOXnIZlYnvG9c1q-ETn5h5Oqi9gQixeWlHvkdWihc,6704
|
7
|
-
skyvern_llamaindex-0.0.3.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
8
|
-
skyvern_llamaindex-0.0.3.dist-info/RECORD,,
|