Skip to content

Commit

Permalink
internal repo sync
Browse files Browse the repository at this point in the history
  • Loading branch information
gasse committed May 17, 2024
1 parent 2246f3f commit 001a74e
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 115 deletions.
25 changes: 16 additions & 9 deletions demo_agent/agents/basic/agent.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import dataclasses

from browsergym.experiments import Agent, AgentArgs
from browsergym.experiments import Agent, AbstractAgentArgs
from browsergym.core.action.highlevel import HighLevelActionSet
from browsergym.core.action.python import PythonActionSet

Expand All @@ -15,10 +15,14 @@ def action_mapping(self):
def __init__(self, model_name) -> None:
super().__init__()
self.model_name = model_name
self.action_space = HighLevelActionSet(subsets=["bid"], strict=False, multiaction=True)

# uncomment this line to allow the agent to also use x,y coordinates
# action_space = HighLevelActionSet(subsets=["bid", "coord"])
action_space = HighLevelActionSet(
subsets=["bid"], # define a subset of the action space
# subsets=["bid", "coord"] # allows the agent to also use x,y coordinates
strict=False, # less strict on the parsing of the actions
multiaction=True, # enable to agent to take multiple actions at once
demo_mode="default", # adds visual effects
)

# uncomment this line to allow the agent to also use Python full python code
# action_space = PythonActionSet()
Expand Down Expand Up @@ -65,16 +69,19 @@ def get_action(self, obs: dict) -> tuple[str, dict]:


@dataclasses.dataclass
class DemoAgentArgs(AgentArgs):
class DemoAgentArgs(AbstractAgentArgs):
"""
This class is meant to store the arguments that define the agent.
By isolating them in a dataclass, this ensures serialization without storing
internal states of the agent.
"""

model_name: str = "gpt-3.5-turbo"

def make_agent(self):
return DemoAgent(model_name=self.model_name)

@property
def agent_name(self) -> str:
return DemoAgent.__name__


def main():
from browsergym.experiments import EnvArgs, ExpArgs, get_exp_result
Expand Down
5 changes: 2 additions & 3 deletions demo_agent/agents/legacy/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@

from browsergym.core.action.base import AbstractActionSet
from browsergym.utils.obs import flatten_axtree_to_str, flatten_dom_to_str, prune_html
from browsergym.experiments import Agent, AgentArgs
from browsergym.experiments import Agent, AbstractAgentArgs

from ..legacy import dynamic_prompting
from .utils.llm_utils import ParseError, retry
from .utils.chat_api import ChatModelArgs


@dataclass
class GenericAgentArgs(AgentArgs):
agent_name: str = "GenericAgent"
class GenericAgentArgs(AbstractAgentArgs):
chat_model_args: ChatModelArgs = None
flags: dynamic_prompting.Flags = field(default_factory=lambda: dynamic_prompting.Flags())
max_retry: int = 4
Expand Down
2 changes: 1 addition & 1 deletion experiments/src/browsergym/experiments/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .agent import Agent
from .loop import EnvArgs, AgentArgs, ExpArgs, get_exp_result
from .loop import EnvArgs, AbstractAgentArgs, ExpArgs, get_exp_result
Loading

0 comments on commit 001a74e

Please sign in to comment.