code: def before_learn_on_batch(
      multi_agent_batch, policies, train_batch_size
  ):
      samples = {}
  
      # Modify keys.
      for pid, p in policies.items():
          i = p.config["agent_id"]
          keys = multi_agent_batch.policy_batches[pid].keys()
          keys = ["_".join([k, str(i)]) for k in keys]
          samples.update(
              dict(
                  zip(
                      keys,
                      multi_agent_batch.policy_batches[pid].values(),
                  )
              )
          )
  
      # Make ops and feed_dict to get "new_obs" from target action sampler.
      new_obs_ph_n = [p.new_obs_ph for p in policies.values()]
      new_obs_n = list()
      for k, v in samples.items():
          if "new_obs" in k:
              new_obs_n.append(v)
  
      for i, p in enumerate(policies.values()):
          feed_dict = {new_obs_ph_n[i]: new_obs_n[i]}
          new_act = p.get_session().run(p.target_act_sampler, feed_dict)
          samples.update({"new_actions_%d" % i: new_act})
  
      # Share samples among agents.
      policy_batches = {
          pid: SampleBatch(samples) for pid in policies.keys()
      }
      return MultiAgentBatch(policy_batches, train_batch_size)
  
file_path: ray/rllib_contrib/maddpg/src/rllib_maddpg/maddpg/maddpg.py
imports: import logging
  from typing import List, Optional, Type
  from rllib_maddpg.maddpg.maddpg_tf_policy import MADDPGTFPolicy
  from ray.rllib.algorithms.algorithm_config import AlgorithmConfig, NotProvided
  from ray.rllib.algorithms.dqn.dqn import DQN
  from ray.rllib.policy.policy import Policy
  from ray.rllib.policy.sample_batch import MultiAgentBatch, SampleBatch
  from ray.rllib.utils.annotations import override
  from ray.rllib.utils.deprecation import DEPRECATED_VALUE
label_desc: Use image node_id 1 for calling a global function with example usage: before_learn_on_batch(multi_agent_batch, policies, train_batch_size) and returns: MultiAgentBatch