Skip to content

Commit 11071e9

Browse files
committed
initial commit
1 parent 57bf273 commit 11071e9

File tree

2 files changed

+141
-0
lines changed

2 files changed

+141
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import gym
2+
from abc import ABC, abstractmethod
3+
4+
5+
class AbstractEnvArgs(ABC):
6+
"""Easily serialiazable class to store the arguments of an environment"""
7+
8+
@abstractmethod
9+
def make_env(self, action_mapping, exp_dir, exp_task_kwargs) -> "AbstractEnv":
10+
"""Create an instance of the environment with the arguments stored in this object.
11+
12+
Args:
13+
action_mapping (dict[str,str]): mapping from the agent's action space to the environment's action space
14+
see AbstractActionSet.to_python_code from BrowserGym for an example
15+
exp_dir (str): directory where the experiment is stored
16+
exp_task_kwargs (dict[str,Any]): additional arguments for the environment
17+
18+
Returns:
19+
env (AbstractEnv): instance of the environment.
20+
"""
21+
22+
23+
class AbstractEnv(gym.Env, ABC):
24+
25+
@abstractmethod
26+
def reset(self, seed: int = None) -> tuple[dict[str, any], dict[str, any]]:
27+
"""Reset the environment to the initial state, ready for an agent to start a new episode.
28+
29+
Args:
30+
seed (int): seed to be used for the environment's random number generator. Some task may
31+
be deterministic and not require a seed.
32+
33+
Returns:
34+
obs (dict[str,Any]): dictionary containing the observations
35+
env_info (dict[str,Any]): additional information about the environment (see step's docstring)
36+
"""
37+
38+
@abstractmethod
39+
def step(self, action: str):
40+
"""Exection action in the environment and return the next observations
41+
42+
Args:
43+
action (str): action to be executed in the environment, as a string
44+
45+
Returns:
46+
obs (dict[str,Any]): dictionary containing the observations
47+
reward (float): reward obtained after executing the action
48+
terminated (bool): whether the episode is terminated. The MDP reached a terminal state
49+
truncated (bool): whether the episode is truncated. The episode was truncated due to external reasons
50+
env_info (dict[str,Any]): additional information about the environment
51+
task_info (str): Some potential debugging information about the task, not intended for the agent
52+
action_exec_start (float): time when the action execution started
53+
action_exec_stop (float): time when the action execution ended
54+
action_exec_timeout (float): TODO I don't remember exactly what this is
55+
"""
56+
57+
@abstractmethod
58+
def close(self):
59+
"""Close any resources used by the environment"""
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
from dataclasses import dataclass
2+
from agentlab.benchmarks.abstract_env import AbstractEnv, AbstractEnvArgs
3+
import bgym
4+
5+
6+
@dataclass
7+
class TauBenchEnvArgs(AbstractEnvArgs):
8+
"""All arguments parameterizing a task in tau-bench"""
9+
10+
task_name: str
11+
task_seed: int # is there any seeds or tasks are deterministic?
12+
13+
def __init__(self):
14+
super().__init__()
15+
16+
def make_env(self, action_mapping, exp_dir, exp_task_kwargs) -> "AbstractEnv":
17+
# TODO look at how bgym does it. You need to register tasks and do gym.make(task_name)
18+
pass
19+
20+
21+
class TauBenchEnv(AbstractEnv):
22+
def __init__(self):
23+
super().__init__()
24+
25+
def reset(self, seed=None):
26+
pass
27+
28+
def step(self, action: str):
29+
pass
30+
31+
def close(self):
32+
pass
33+
34+
35+
@dataclass
36+
class TauBenchActionSetArgs:
37+
"""Holds hyperparameters for the TauBenchActionSet"""
38+
39+
def make_action_set(self):
40+
return TauBenchActionSet()
41+
42+
43+
class TauBenchActionSet(bgym.AbstractActionSet):
44+
# TODO: Get inspiration from bgym's HighLevelActionSet, perhaps reusing code there, TBD
45+
46+
def describe(self, with_long_description: bool = True, with_examples: bool = True) -> str:
47+
# TODO: Implement this method
48+
pass
49+
50+
def example_action(self, abstract: bool) -> str:
51+
# TODO: Implement this method
52+
53+
pass
54+
55+
def to_python_code(self, action) -> str:
56+
# TODO: Implement this method
57+
58+
pass
59+
60+
61+
def _make_env_args_list():
62+
# TODO generate all evn_args for the benchmark, get inspiration from bgym's task_list_from_metadata and make_env_args_list_from_repeat_tasks
63+
return [TauBenchEnvArgs()]
64+
65+
66+
def _task_metadata():
67+
# load a dataframe containing configuration for all tasks
68+
pass
69+
70+
71+
def make_tau_benchmark():
72+
return bgym.Benchmark(
73+
name="tau-bench",
74+
high_level_action_set_args=TauBenchActionSet(),
75+
is_multi_tab=False,
76+
supports_parallel_seeds=True,
77+
backends=[
78+
"taubench"
79+
], # TODO this is not an implemented backend yet and bgym's make_backed implementation with match case needs to be revised
80+
env_args_list=_make_env_args_list(), # TODO adapt
81+
task_metadata=_task_metadata(), # TODO adapt
82+
)

0 commit comments

Comments
 (0)