class_docstr: Tracks the current state of a (possibly multi-agent) episode.
class_docstr_tok: ["Tracks","the","current","state","of","a","(","possibly","multi-agent",")","episode","."]
docstr: Initializes an Episode instance.
  
  Args:
      env_id: The environment's ID in which this episode runs.
      policies: The PolicyMap object (mapping PolicyIDs to Policy
          objects) to use for determining, which policy is used for
          which agent.
      policy_mapping_fn: The mapping function mapping AgentIDs to
          PolicyIDs.
      worker: The RolloutWorker instance, in which this episode runs.
docstr_tok: ["Initializes","an","Episode","instance",".","Args",":","env_id",":","The","environment","'s","ID","in","which","this","episode","runs",".","policies",":","The","PolicyMap","object","(","mapping","PolicyIDs","to","Policy","objects",")","to","use","for","determining",",","which","policy","is","used","for","which","agent",".","policy_mapping_fn",":","The","mapping","function","mapping","AgentIDs","to","PolicyIDs",".","worker",":","The","RolloutWorker","instance",",","in","which","this","episode","runs","."]
code: def __init__(
      self,
      env_id: EnvID,
      policies: PolicyMap,
      policy_mapping_fn: Callable[
          [AgentID, "EpisodeV2", "RolloutWorker"], PolicyID
      ],
      *,
      worker: Optional["RolloutWorker"] = None,
      callbacks: Optional["DefaultCallbacks"] = None,
  ):
      """Initializes an Episode instance.
  
      Args:
          env_id: The environment's ID in which this episode runs.
          policies: The PolicyMap object (mapping PolicyIDs to Policy
              objects) to use for determining, which policy is used for
              which agent.
          policy_mapping_fn: The mapping function mapping AgentIDs to
              PolicyIDs.
          worker: The RolloutWorker instance, in which this episode runs.
      """
      # Unique id identifying this trajectory.
      self.episode_id: int = random.randrange(int(1e18))
      # ID of the environment this episode is tracking.
      self.env_id = env_id
      # Summed reward across all agents in this episode.
      self.total_reward: float = 0.0
      # Active (uncollected) # of env steps taken by this episode.
      # Start from -1. After add_init_obs(), we will be at 0 step.
      self.active_env_steps: int = -1
      # Total # of env steps taken by this episode.
      # Start from -1, After add_init_obs(), we will be at 0 step.
      self.total_env_steps: int = -1
      # Active (uncollected) agent steps.
      self.active_agent_steps: int = 0
      # Total # of steps take by all agents in this env.
      self.total_agent_steps: int = 0
      # Dict for user to add custom metrics.
      # TODO (sven): We should probably unify custom_metrics, user_data,
      #  and hist_data into a single data container for user to track per-step.
      # metrics and states.
      self.custom_metrics: Dict[str, float] = {}
      # Temporary storage. E.g. storing data in between two custom
      # callbacks referring to the same episode.
      self.user_data: Dict[str, Any] = {}
      # Dict mapping str keys to List[float] for storage of
      # per-timestep float data throughout the episode.
      self.hist_data: Dict[str, List[float]] = {}
      self.media: Dict[str, Any] = {}
  
      self.worker = worker
      self.callbacks = callbacks
  
      self.policy_map: PolicyMap = policies
      self.policy_mapping_fn: Callable[
          [AgentID, "EpisodeV2", "RolloutWorker"], PolicyID
      ] = policy_mapping_fn
      # Per-agent data collectors.
      self._agent_to_policy: Dict[AgentID, PolicyID] = {}
      self._agent_collectors: Dict[AgentID, AgentCollector] = {}
  
      self._next_agent_index: int = 0
      self._agent_to_index: Dict[AgentID, int] = {}
  
      # Summed rewards broken down by agent.
      self.agent_rewards: Dict[
          Tuple[AgentID, PolicyID], float
      ] = defaultdict(float)
      self._agent_reward_history: Dict[
          AgentID, List[int]
      ] = defaultdict(list)
  
      self._has_init_obs: Dict[AgentID, bool] = {}
      self._last_terminateds: Dict[AgentID, bool] = {}
      self._last_truncateds: Dict[AgentID, bool] = {}
      # Keep last info dict around, in case an environment tries to signal
      # us something.
      self._last_infos: Dict[AgentID, Dict] = {}
  
imports: import random
  from collections import defaultdict
  import numpy
  from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Tuple
  from ray.rllib.env.base_env import _DUMMY_AGENT_ID
  from ray.rllib.evaluation.collectors.simple_list_collector import _PolicyCollector, _PolicyCollectorGroup
  from ray.rllib.evaluation.collectors.agent_collector import AgentCollector
  from ray.rllib.policy.policy_map import PolicyMap
  from ray.rllib.policy.sample_batch import SampleBatch
  from ray.rllib.utils.annotations import DeveloperAPI
  from ray.rllib.utils.typing import AgentID, EnvID, EnvInfoDict, PolicyID, TensorType
label_desc: Use image node_id 1 to create a new EpisodeV2 object  with example: obj = EpisodeV2(env_id, policies, policy_mapping_fn)