class_docstr: The generic environment runner for the single agent case.
class_docstr_tok: ["The","generic","environment","runner","for","the","single","agent","case","."]
code: def get_metrics(self) -> List[RolloutMetrics]:
      # Compute per-episode metrics (only on already completed episodes).
      metrics = []
      for eps in self._done_episodes_for_metrics:
          assert eps.is_done
          episode_length = len(eps)
          episode_reward = eps.get_return()
          # Don't forget about the already returned chunks of this episode.
          if eps.id_ in self._ongoing_episodes_for_metrics:
              for eps2 in self._ongoing_episodes_for_metrics[eps.id_]:
                  episode_length += len(eps2)
                  episode_reward += eps2.get_return()
              del self._ongoing_episodes_for_metrics[eps.id_]
  
          metrics.append(
              RolloutMetrics(
                  episode_length=episode_length,
                  episode_reward=episode_reward,
              )
          )
  
      self._done_episodes_for_metrics.clear()
      self._ts_since_last_metrics = 0
  
      return metrics
  
imports: import gymnasium
  import numpy
  import tree
  from collections import defaultdict
  from functools import partial
  from typing import Dict, List, Optional
  from ray.rllib.algorithms.algorithm_config import AlgorithmConfig
  from ray.rllib.algorithms.callbacks import DefaultCallbacks
  from ray.rllib.core.rl_module.rl_module import RLModule, SingleAgentRLModuleSpec
  from ray.rllib.env.env_runner import EnvRunner
  from ray.rllib.env.single_agent_episode import SingleAgentEpisode
  from ray.rllib.env.utils import _gym_env_creator
  from ray.rllib.evaluation.metrics import RolloutMetrics
  from ray.rllib.policy.sample_batch import DEFAULT_POLICY_ID, SampleBatch
  from ray.rllib.utils.annotations import ExperimentalAPI, override
  from ray.rllib.utils.framework import try_import_tf, try_import_torch
  from ray.rllib.utils.torch_utils import convert_to_torch_tensor
  from ray.rllib.utils.typing import TensorType
  from ray.tune.registry import ENV_CREATOR, _global_registry
label_desc: Use image node_id 6 for calling the SingleAgentEnvRunner obj's underlying member method code with example usage: obj.get_metrics() and returns: metrics