Skip to content

Commit 3378b56

Browse files
committed
better abstract class
1 parent ffebf6b commit 3378b56

File tree

1 file changed

+20
-10
lines changed
  • src/agentlab/backends/browser

1 file changed

+20
-10
lines changed

src/agentlab/backends/browser/base.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
from abc import ABC, abstractmethod
23
from typing import Any, Callable, Literal
34

45
from langchain_core.utils.function_calling import convert_to_openai_tool
@@ -73,30 +74,39 @@ def from_function(cls, function: Callable):
7374
return cls.model_validate(convert_to_openai_tool(function))
7475

7576

76-
class BrowserBackend(BaseModel):
77+
class BrowserBackend(BaseModel, ABC):
78+
@abstractmethod
7779
def initialize(self) -> None:
78-
raise NotImplementedError
80+
pass
7981

82+
@abstractmethod
8083
def run_js(self, js: str):
81-
raise NotImplementedError
84+
pass
8285

86+
@abstractmethod
8387
def goto(self, url: str) -> str:
84-
raise NotImplementedError
88+
pass
8589

90+
@abstractmethod
8691
def page_html(self) -> str:
87-
raise NotImplementedError
92+
pass
8893

94+
@abstractmethod
8995
def page_screenshot(self) -> Image:
90-
raise NotImplementedError
96+
pass
9197

98+
@abstractmethod
9299
def page_axtree(self) -> str:
93-
raise NotImplementedError
100+
pass
94101

102+
@abstractmethod
95103
def step(self, action: ToolCallAction) -> str:
96-
raise NotImplementedError
104+
pass
97105

106+
@abstractmethod
98107
def actions(self) -> tuple[ToolSpec]:
99-
raise NotImplementedError
108+
pass
100109

110+
@abstractmethod
101111
def close(self) -> None:
102-
raise NotImplementedError
112+
pass

0 commit comments

Comments
 (0)