code: def update_transition_before_adding_to_replay_buffer(
      self, transition
  ):
      graph_manager = self.parent_level_manager.parent_graph_manager
  
      # deal with goals given from a higher level agent
      if not self.ap.is_a_highest_level_agent:
          transition.state["desired_goal"] = self.current_hrl_goal
          transition.next_state["desired_goal"] = self.current_hrl_goal
          # TODO: allow setting goals which are not part of the state. e.g. state-embedding using get_prediction
          self.distance_from_goal.add_sample(
              self.spaces.goal.distance_from_goal(
                  self.current_hrl_goal, transition.next_state
              )
          )
          (
              goal_reward,
              sub_goal_reached,
          ) = self.spaces.goal.get_reward_for_goal_and_state(
              self.current_hrl_goal, transition.next_state
          )
          transition.reward = goal_reward
          transition.game_over = (
              transition.game_over or sub_goal_reached
          )
  
      # each level tests its own generated sub goals
      if (
          not self.ap.is_a_lowest_level_agent
          and graph_manager.should_test_current_sub_goal
      ):
          # TODO-fixme
          # _, sub_goal_reached = self.parent_level_manager.environment.agents['agent_1'].spaces.goal.\
          # get_reward_for_goal_and_state(transition.action, transition.next_state)
  
          (
              _,
              sub_goal_reached,
          ) = self.spaces.goal.get_reward_for_goal_and_state(
              transition.action, transition.next_state
          )
  
          sub_goal_is_missed = not sub_goal_reached
  
          if sub_goal_is_missed:
              transition.reward = -self.ap.algorithm.time_limit
      return transition
  
file_path: coach/rl_coach/agents/hac_ddpg_agent.py
imports: from typing import Union
  import numpy
  from rl_coach.agents.ddpg_agent import DDPGAgent, DDPGAgentParameters, DDPGAlgorithmParameters
  from rl_coach.core_types import RunPhase
  from rl_coach.spaces import SpacesDefinition
label_desc: Use image node_id 3 for calling the HACDDPGAgent obj's underlying member method code with example usage: obj.update_transition_before_adding_to_replay_buffer(transition) and returns: transition