class_docstr: OPT BB3 Agent.
class_docstr_tok: ["OPT","BB3","Agent","."]
docstr: Get the opening message.
  
  :param observations:
      raw observations
  
  :return batch_act:
      return batch act from the opening dialogue agent.
docstr_tok: ["Get","the","opening","message",".",":","param","observations",":","raw","observations",":","return","batch_act",":","return","batch","act","from","the","opening","dialogue","agent","."]
code: def get_opening(
      self, observations: List[Dict[Union[str, Module], Message]]
  ) -> List[Message]:
      """
      Get the opening message.
  
      :param observations:
          raw observations
  
      :return batch_act:
          return batch act from the opening dialogue agent.
      """
      module = Module.OPENING_DIALOGUE
      batch_act = [Message({"text": self.self_prefix})] * len(
          observations
      )
  
      def _failed_messages(replies):
          return any(
              p in o["text"]
              for p in [self.self_prefix, self.partner_prefix]
              for o in replies
          )
  
      retries = 0
      opening_obs = [o[module] for o in observations]
      while _failed_messages(batch_act) and retries < 3:
          batch_act = self.batch_agents[
              Module.OPENING_DIALOGUE
          ].batch_act(opening_obs)
          self.batch_agents[Module.OPENING_DIALOGUE].reset()
          retries += 1
          n_mems = [
              min(1, len(obs["memories"]) // 3) for obs in opening_obs
          ]
          for i, o in enumerate(opening_obs):
              mem_indices = random.sample(
                  range(len(o["memories"])), n_mems[i]
              )
              o.force_set(
                  "memories",
                  {
                      m: v
                      for i, (m, v) in enumerate(o["memories"].items())
                      if i in mem_indices
                  },
              )
      if _failed_messages(batch_act):
          for reply in batch_act:
              text = reply.pop("text")
              for p in [
                  self.self_memory_prefix,
                  self.partner_memory_prefix,
                  self.self_prefix,
                  self.partner_prefix,
              ]:
                  text = text.replace(f"{p}:", "").replace(p, "")
              reply["text"] = text
  
      return batch_act
  
imports: import copy
  import random
  from typing import List, Optional, Dict, Any, Union, Tuple
  from parlai.agents.rag.retrievers import Document
  from parlai.core.agents import Agent, create_agent
  from parlai.core.message import Message
  from parlai.core.params import ParlaiParser
  from parlai.core.opt import Opt
  import parlai.utils.logging
  from projects.bb3.agents.module import Module
  from projects.bb3.agents.r2c2_bb3_agent import BlenderBot3Agent
  from projects.bb3.agents.opt_api_agent import BB3OPTAgent
  from projects.bb3.agents.search_agent import SearchAgent
  from projects.bb3.agents.utils import Decision, APIUtils, is_opener, DisplayUtils, set_failed_reply
  import projects.bb3.prompts
label_desc: Use image node_id 21 for calling the BlenderBot3Agent obj's underlying member method code with example usage: obj.get_opening(observations) and returns: batch_act, any