Skip to content

viberl.agents.base

Base Agent class for all RL agents.

Classes:

Name Description
Agent

Abstract base class for all RL agents.

Agent

Agent(state_size: int, action_size: int)

Bases: ABC

Abstract base class for all RL agents.

Initialize the agent.

Parameters:

Name Type Description Default
state_size int

Size of the state space

required
action_size int

Size of the action space

required

Methods:

Name Description
act

Select an action given the current state.

learn

Perform one learning step.

save

Save agent state to file.

load

Load agent state from file.

Attributes:

Name Type Description
state_size
action_size
Source code in viberl/agents/base.py
18
19
20
21
22
23
24
25
26
def __init__(self, state_size: int, action_size: int) -> None:
    """Initialize the agent.

    Args:
        state_size: Size of the state space
        action_size: Size of the action space
    """
    self.state_size = state_size
    self.action_size = action_size

state_size instance-attribute

state_size = state_size

action_size instance-attribute

action_size = action_size

act abstractmethod

act(state: ndarray, training: bool = True) -> Action

Select an action given the current state.

Parameters:

Name Type Description Default
state ndarray

Current state observation

required
training bool

Whether in training mode (affects exploration)

True

Returns:

Type Description
Action

Action object containing the selected action and optional metadata

Source code in viberl/agents/base.py
28
29
30
31
32
33
34
35
36
37
38
@abstractmethod
def act(self, state: np.ndarray, training: bool = True) -> Action:
    """Select an action given the current state.

    Args:
        state: Current state observation
        training: Whether in training mode (affects exploration)

    Returns:
        Action object containing the selected action and optional metadata
    """

learn abstractmethod

learn(trajectories: list[Trajectory]) -> dict[str, float]

Perform one learning step.

Parameters:

Name Type Description Default
trajectories list[Trajectory]

List of trajectories to learn from

required

Returns:

Type Description
dict[str, float]

Dictionary of step metrics (e.g., loss values)

Source code in viberl/agents/base.py
40
41
42
43
44
45
46
47
48
49
@abstractmethod
def learn(self, trajectories: list[Trajectory]) -> dict[str, float]:
    """Perform one learning step.

    Args:
        trajectories: List of trajectories to learn from

    Returns:
        Dictionary of step metrics (e.g., loss values)
    """

save abstractmethod

save(filepath: str) -> None

Save agent state to file.

Parameters:

Name Type Description Default
filepath str

Path to save the model

required
Source code in viberl/agents/base.py
51
52
53
54
55
56
57
@abstractmethod
def save(self, filepath: str) -> None:
    """Save agent state to file.

    Args:
        filepath: Path to save the model
    """

load abstractmethod

load(filepath: str) -> None

Load agent state from file.

Parameters:

Name Type Description Default
filepath str

Path to load the model from

required
Source code in viberl/agents/base.py
59
60
61
62
63
64
65
@abstractmethod
def load(self, filepath: str) -> None:
    """Load agent state from file.

    Args:
        filepath: Path to load the model from
    """