Skip to content

action

The action module decides what action the agent should perform.

ActionData = ActionRequest | TakeAction module-attribute

ActionEvent = Event[ActionData] module-attribute

Action

Bases: Component

Component for determining which action to take.

Source code in roc/action.py
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
@register_component("action", "action", auto=True)
class Action(Component):
    """Component for determining which action to take."""

    bus = EventBus[ActionData]("action", cache_depth=10)

    def __init__(self) -> None:
        super().__init__()
        self.action_bus_conn = self.connect_bus(self.bus)
        self.action_bus_conn.listen(self.action_request)

    def event_filter(self, e: ActionEvent) -> bool:
        return isinstance(e.data, ActionRequest)

    def action_request(self, e: ActionEvent) -> None:
        action = DefaultActionExpMod.get(default="pass").get_action()
        actevt = TakeAction(action=action)
        self.action_bus_conn.send(actevt)

action_bus_conn = self.connect_bus(self.bus) instance-attribute

bus = EventBus[ActionData]('action', cache_depth=10) class-attribute instance-attribute

__init__()

Source code in roc/action.py
33
34
35
36
def __init__(self) -> None:
    super().__init__()
    self.action_bus_conn = self.connect_bus(self.bus)
    self.action_bus_conn.listen(self.action_request)

action_request(e)

Source code in roc/action.py
41
42
43
44
def action_request(self, e: ActionEvent) -> None:
    action = DefaultActionExpMod.get(default="pass").get_action()
    actevt = TakeAction(action=action)
    self.action_bus_conn.send(actevt)

event_filter(e)

Source code in roc/action.py
38
39
def event_filter(self, e: ActionEvent) -> bool:
    return isinstance(e.data, ActionRequest)

ActionRequest dataclass

Communicates that the Gym is waiting for the agent to take an action.

Source code in roc/action.py
12
13
14
@dataclass
class ActionRequest:
    """Communicates that the Gym is waiting for the agent to take an action."""

__init__()

DefaultActionPass

Bases: DefaultActionExpMod

Source code in roc/action.py
47
48
49
50
51
@DefaultActionExpMod.register("pass")
class DefaultActionPass(DefaultActionExpMod):
    def get_action(self) -> int:
        """Default action for Nethack that passes (the `.` character in the game)"""
        return 19

get_action()

Default action for Nethack that passes (the . character in the game)

Source code in roc/action.py
49
50
51
def get_action(self) -> int:
    """Default action for Nethack that passes (the `.` character in the game)"""
    return 19

TakeAction

Bases: Node

Communicates back to the Gym which cation to take.

Source code in roc/action.py
17
18
19
20
class TakeAction(Node):
    """Communicates back to the Gym which cation to take."""

    action: Any

action instance-attribute