ray.rllib.algorithms.algorithm.Algorithm.add_module#

Algorithm.add_module(module_id: str, module_spec: SingleAgentRLModuleSpec, *, module_state: Dict | None = None, new_agent_to_module_mapping_fn: Callable[[Any, SingleAgentEpisode | MultiAgentEpisode], str] | None = None, new_should_module_be_updated: Sequence[str] | Callable[[str, MultiAgentBatch | None], bool] | None = None, evaluation_workers: bool = True) Policy | None[source]#

Adds a new (single-agent) RLModule to this Algorithm’s MARLModule.

Parameters:
  • module_id – ID of the RLModule to add to the MARLModule. IMPORTANT: Must not contain characters that are also not allowed in Unix/Win filesystems, such as: <>:"/|?*, or a dot, space or backslash at the end of the ID.

  • module_spec – The SingleAgentRLModuleSpec to use for constructing the new RLModule.

  • module_state – Optional state dict to apply to the new RLModule instance, right after its construction.

  • new_agent_to_module_mapping_fn – An optional (updated) AgentID to ModuleID mapping function to use from here on. Note that already ongoing episodes will not change their mapping but will use the old mapping till the end of the episode.

  • new_should_module_be_updated – An optional sequence of ModuleIDs or a callable taking ModuleID and SampleBatchType and returning whether the ModuleID should be updated (trained). If None, will keep the existing setup in place. RLModules, whose IDs are not in the list (or for which the callable returns False) will not be updated.

  • evaluation_workers – Whether to add the new RLModule also to the evaluation WorkerSet.

Returns:

The newly added RLModule (the copy that got added to the local worker).