Skip to content

Commit 1ba33f3

Browse files
committed
agent-studio api
1 parent ac9bdff commit 1ba33f3

File tree

6 files changed

+68
-5
lines changed

6 files changed

+68
-5
lines changed

lavague-integrations/drivers/lavague-drivers-selenium/lavague/drivers/selenium/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
NoPageException,
2626
)
2727

28+
from lavague.sdk.action.navigation import WebNavigationAction, NavigationCommand
29+
from lavague.sdk.action import ActionStatus
2830
from selenium.common.exceptions import (
2931
NoSuchElementException,
3032
TimeoutException,
@@ -39,7 +41,6 @@
3941
from selenium.webdriver.support.ui import WebDriverWait
4042
from selenium.webdriver.chrome.service import Service
4143

42-
4344
class SeleniumDriver(BaseDriver[SeleniumNode]):
4445
driver: WebDriver
4546

lavague-sdk/lavague/sdk/action/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from lavague.sdk.action.base import (
22
Action,
3+
Instruction,
4+
EngineType,
35
ActionType,
46
ActionStatus,
57
ActionParser,

lavague-sdk/lavague/sdk/action/base.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ class ActionType(str, Enum):
1414
EXTRACTION = "web_extraction"
1515

1616

17+
class EngineType(str, Enum):
18+
NAVIGATION = "Navigation Engine"
19+
EXTRACTION = "Element Extraction Engine"
20+
CONTROLS = "Navigation Controls"
21+
COMPLETE = "COMPLETE"
22+
23+
1724
T = TypeVar("T")
1825

1926

@@ -55,6 +62,12 @@ def parse(self, action_dict: Dict) -> Action:
5562
return Action.parse(action_dict)
5663

5764

65+
class Instruction(BaseModel):
66+
chain_of_toughts: str
67+
engine: EngineType
68+
engine_instruction: str
69+
70+
5871
class UnhandledTypeException(Exception):
5972
pass
6073

lavague-sdk/lavague/sdk/base_driver/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def execute(self, action: NavigationOutput) -> None:
6767
raise NotImplementedError(
6868
f"Action {action.navigation_command} not implemented"
6969
)
70+
self.wait_for_idle()
7071

7172
@abstractmethod
7273
def destroy(self) -> None:

lavague-sdk/lavague/sdk/client.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from typing import Any, Optional, Tuple
33

44
import requests
5-
from lavague.sdk.action import DEFAULT_PARSER, ActionParser
5+
from lavague.sdk.action import DEFAULT_PARSER, ActionParser, Instruction, Action
66
from lavague.sdk.trajectory import Trajectory
77
from lavague.sdk.trajectory.controller import TrajectoryController
88
from lavague.sdk.trajectory.model import StepCompletion
@@ -86,7 +86,30 @@ def next_step(self, run_id: str) -> StepCompletion:
8686
f"/runs/{run_id}/step",
8787
"POST",
8888
)
89-
return StepCompletion.model_validate_json(content)
89+
return StepCompletion.from_data(content)
90+
91+
def generate_instruction(self, run_id: str) -> Instruction:
92+
content = self.request_api(
93+
f"/runs/{run_id}/step/instruction",
94+
"POST",
95+
)
96+
return Instruction.model_validate_json(content)
97+
98+
def generate_action(self, run_id: str, instruction: Instruction) -> StepCompletion:
99+
content = self.request_api(
100+
f"/runs/{run_id}/step/action",
101+
"POST",
102+
instruction.model_dump(),
103+
)
104+
return StepCompletion.from_data(content)
105+
106+
def execute_action(self, run_id: str, action: StepCompletion) -> StepCompletion:
107+
content = self.request_api(
108+
f"/runs/{run_id}/step/execution",
109+
"POST",
110+
action.model_dump(),
111+
)
112+
return StepCompletion.from_data(content)
90113

91114
def stop(self, run_id: str) -> None:
92115
self.request_api(

lavague-sdk/lavague/sdk/trajectory/model.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from enum import Enum
22
from typing import Any, Dict, List, Tuple, Optional
33
from pydantic import BaseModel, SerializeAsAny
4-
from lavague.sdk.action import Action
4+
from lavague.sdk.action import Action, ActionParser
55
from lavague.sdk.action.base import DEFAULT_PARSER
66
from pydantic import model_validator
7+
from pydantic_core import from_json
78

89
class RunStatus(str, Enum):
910
STARTING = "starting"
@@ -59,4 +60,26 @@ def write_to_file(self, file_path: str):
5960
class StepCompletion(BaseModel):
6061
run_status: RunStatus
6162
action: Optional[Action]
62-
run_mode: RunMode
63+
run_mode: RunMode
64+
65+
@classmethod
66+
def from_data(
67+
cls,
68+
data: str | bytes | bytearray,
69+
parser: ActionParser = DEFAULT_PARSER,
70+
):
71+
obj = from_json(data)
72+
return cls.from_dict(obj, parser)
73+
74+
@classmethod
75+
def from_dict(
76+
cls,
77+
data: Dict,
78+
parser: ActionParser = DEFAULT_PARSER,
79+
):
80+
action = data.get("action")
81+
action = parser.parse(action) if action else None
82+
return cls.model_validate({
83+
**data,
84+
"action": action
85+
})

0 commit comments

Comments
 (0)