code: def create_policy_for_framework(
      policy_id: str,
      policy_class: Type["Policy"],
      merged_config: PartialAlgorithmConfigDict,
      observation_space: gym.Space,
      action_space: gym.Space,
      worker_index: int = 0,
      session_creator: Optional[Callable[[], "tf1.Session"]] = None,
      seed: Optional[int] = None,
  ):
      """Framework-specific policy creation logics.
  
      Args:
          policy_id: Policy ID.
          policy_class: Policy class type.
          merged_config: Complete policy config.
          observation_space: Observation space of env.
          action_space: Action space of env.
          worker_index: Index of worker holding this policy. Default is 0.
          session_creator: An optional tf1.Session creation callable.
          seed: Optional random seed.
      """
      from ray.rllib.algorithms.algorithm_config import AlgorithmConfig
  
      if isinstance(merged_config, AlgorithmConfig):
          merged_config = merged_config.to_dict()
  
      # add policy_id to merged_config
      merged_config["__policy_id"] = policy_id
  
      framework = merged_config.get("framework", "tf")
      # Tf.
      if framework in ["tf2", "tf"]:
          var_scope = policy_id + (
              f"_wk{worker_index}" if worker_index else ""
          )
          # For tf static graph, build every policy in its own graph
          # and create a new session for it.
          if framework == "tf":
              with tf1.Graph().as_default():
                  # Session creator function provided manually -> Use this one to
                  # create the tf1 session.
                  if session_creator:
                      sess = session_creator()
                  # Use a default session creator, based only on our `tf_session_args` in
                  # the config.
                  else:
                      sess = tf1.Session(
                          config=tf1.ConfigProto(
                              **merged_config["tf_session_args"]
                          )
                      )
  
                  with sess.as_default():
                      # Set graph-level seed.
                      if seed is not None:
                          tf1.set_random_seed(seed)
                      with tf1.variable_scope(var_scope):
                          return policy_class(
                              observation_space,
                              action_space,
                              merged_config,
                          )
          # For tf-eager: no graph, no session.
          else:
              with tf1.variable_scope(var_scope):
                  return policy_class(
                      observation_space, action_space, merged_config
                  )
      # Non-tf: No graph, no session.
      else:
          return policy_class(
              observation_space, action_space, merged_config
          )
  
imports: import gymnasium
  import logging
  import numpy
  import re
  from typing import Callable, Dict, List, Mapping, Optional, Tuple, Type, Union, TYPE_CHECKING
  import tree
  import ray.cloudpickle
  from ray.rllib.models.preprocessors import ATARI_OBS_SHAPE
  from ray.rllib.policy.policy import PolicySpec
  from ray.rllib.policy.sample_batch import SampleBatch
  from ray.rllib.utils.deprecation import Deprecated
  from ray.rllib.utils.framework import try_import_tf
  from ray.rllib.utils.typing import ActionConnectorDataType, AgentConnectorDataType, AgentConnectorsOutput, PartialAlgorithmConfigDict, PolicyState, TensorStructType, TensorType
  from ray.util import log_once
  from ray.util.annotations import PublicAPI
label_desc: Use image node_id 2 for calling a global function with example usage: create_policy_for_framework(policy_id, policy_class, merged_config, observation_space, action_space, worker_index, session_creator, seed) and returns: policy_class, policy_class, policy_class