Skip to content

AgentComponent

Requires the rl package to be installed for the project.

AgentComponent

action property

action: Any

The most recent action, in whatever type matches the configured action_space (int for Discrete, list for Box/MultiDiscrete/MultiBinary).

Example
move_idx, jump, shoot = self.agent.action  # MultiDiscrete([3, 2, 2])

action_space property

action_space: Any

The gymnasium.spaces.Space configured via set_action_space()

agent_id property

agent_id: int

Unique id of this agent, used to key per-agent training state

enable property writable

enable: bool

Whether this component is active

observation_space property

observation_space: Any

The gymnasium.spaces.Space configured via set_observation_space(), or None if unset

owner property

owner: Object

The Object that owns this component

add_child

add_child(obj: Object) -> Object

Add obj as a child of this component's owning Object

add_component

add_component(component_class: Any) -> typing.Any

Attach a new component of the given type to this component's owning Object.

Example
render = self.add_component(RenderComponent)

add_object

add_object(obj: Object, parent: Object = None) -> Object

Add a newly created Object to the scene, optionally parented to another Object

add_reward

add_reward(delta: SupportsFloat | SupportsIndex) -> None

Add delta to this episode's accumulated reward

clear_observation

clear_observation() -> None

Clear the observation vector accumulated so far this frame

end_episode

end_episode() -> None

Mark the current episode as done, ending the RL rollout on the next step

get_component

get_component(component_class: Any) -> typing.Any

Look up a component on this Object

get_owner

get_owner() -> Object

The Object that owns this component

has_component

has_component(component_class: Any) -> bool

Check whether this component's owning Object has a component of the given type

remove_component

remove_component(component_class: Any) -> None

Remove a component of the given type from this component's owning Object

remove_object

remove_object(obj: Object) -> None

Remove an object from the scene

set_action_space

set_action_space(space: Any) -> None

Set this agent's action space to any gymnasium.spaces.Space instance (Discrete, Box, MultiDiscrete, MultiBinary).

Example
from gymnasium import spaces
self.agent.set_action_space(spaces.MultiDiscrete([3, 2, 2]))

Must be called (e.g. from OnStart) before training or inference.

set_observation

set_observation(values: Sequence[SupportsFloat | SupportsIndex]) -> None

Replace this frame's entire observation vector

set_observation_space

set_observation_space(space: Any) -> None

Optional. Override the observation space with any gymnasium.spaces.Space. If not set, a Box inferred from the length of accumulated add_observation() values is used automatically (previous default behavior).

set_reward

set_reward(value: SupportsFloat | SupportsIndex) -> None

Overwrite this step's reward with value