Skip to content

abstract_agent

RL4CRN.agents.abstract_agent

Abstract agent interface.

Defines the minimal interface for RL agents used in this project. An agent is responsible for:

  • producing actions to be applied to the environment (act)
  • updating internal parameters from observed rewards (update)
  • translating environment states into agent-specific representations (translate_state)

Concrete agents should override these methods to implement their behavior.

AbstractAgent

Base class for agents that act in and learn from a CRN environment.

__init__()

Initialize the agent.

act()

Produce an action to be applied to the environment.

The returned object should be compatible with the agent-to-environment interface used by the environment/actuator. Concrete agents must override this method.

RETURNS DESCRIPTION

A policy action representing a reaction to add or select. The exact structure depends on the concrete agent and the actuator in use.

update(rewards, hof=None)

Update the agent from rewards (e.g., perform a backward pass).

This method is intended to update the agent's internal state and does not return anything.

If the agent exposes a policy attribute and that policy defines reset_template(), this method calls it after each update. This is used to distinguish template reactions from reactions added during interaction.

This method automatically resets the initial CRN template after each update.

PARAMETER DESCRIPTION
rewards

Reward signal(s) returned by the environment. The expected type/shape is agent-specific.

hof

Optional hall-of-fame (or similar) object carrying elite samples or trajectories. Concrete agents may use or ignore it.

DEFAULT: None

RETURNS DESCRIPTION

None.

translate_state(state)

Translate an environment state into an agent-specific representation.

Concrete agents should override this method to implement state encoding / feature extraction suitable for their policy and value function(s).

PARAMETER DESCRIPTION
state

Environment state object.

RETURNS DESCRIPTION

An agent-specific representation of state (e.g., tensors, feature vectors, graphs). The exact type depends on the implementation.