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: Returns and stores the policy ID for the specified agent.
  
  If the agent is new, the policy mapping fn will be called to bind the
  agent to a policy for the duration of the entire episode (even if the
  policy_mapping_fn is changed in the meantime!).
  
  Args:
      agent_id: The agent ID to lookup the policy ID for.
  
  Returns:
      The policy ID for the specified agent.
docstr_tok: ["Returns","and","stores","the","policy","ID","for","the","specified","agent",".","If","the","agent","is","new",",","the","policy","mapping","fn","will","be","called","to","bind","the","agent","to","a","policy","for","the","duration","of","the","entire","episode","(","even","if","the","policy_mapping_fn","is","changed","in","the","meantime","!",")",".","Args",":","agent_id",":","The","agent","ID","to","lookup","the","policy","ID","for",".","Returns",":","The","policy","ID","for","the","specified","agent","."]
code: def policy_for(
      self, agent_id: AgentID = _DUMMY_AGENT_ID, refresh: bool = False
  ) -> PolicyID:
      """Returns and stores the policy ID for the specified agent.
  
      If the agent is new, the policy mapping fn will be called to bind the
      agent to a policy for the duration of the entire episode (even if the
      policy_mapping_fn is changed in the meantime!).
  
      Args:
          agent_id: The agent ID to lookup the policy ID for.
  
      Returns:
          The policy ID for the specified agent.
      """
  
      # Perform a new policy_mapping_fn lookup and bind AgentID for the
      # duration of this episode to the returned PolicyID.
      if agent_id not in self._agent_to_policy or refresh:
          policy_id = self._agent_to_policy[
              agent_id
          ] = self.policy_mapping_fn(
              agent_id,  # agent_id
              self,  # episode
              worker=self.worker,
          )
      # Use already determined PolicyID.
      else:
          policy_id = self._agent_to_policy[agent_id]
  
      # PolicyID not found in policy map -> Error.
      if policy_id not in self.policy_map:
          raise KeyError(
              "policy_mapping_fn returned invalid policy id "
              f"'{policy_id}'!"
          )
      return policy_id
  
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 2 for calling the EpisodeV2 obj's underlying member method code with example usage: obj.policy_for(agent_id, refresh) and returns: policy_id