code: def handle_agent_outputs(outputs, output_types=None):
      if isinstance(outputs, dict):
          decoded_outputs = {}
          for i, (k, v) in enumerate(outputs.items()):
              if output_types is not None:
                  # If the class has defined outputs, we can map directly according to the class definition
                  if output_types[i] in AGENT_TYPE_MAPPING:
                      decoded_outputs[k] = AGENT_TYPE_MAPPING[
                          output_types[i]
                      ](v)
                  else:
                      decoded_outputs[k] = AgentType(v)
  
              else:
                  # If the class does not have defined output, then we map according to the type
                  for _k, _v in INSTANCE_TYPE_MAPPING.items():
                      if isinstance(v, _k):
                          decoded_outputs[k] = _v(v)
                  if k not in decoded_outputs:
                      decoded_outputs[k] = AgentType[v]
  
      elif isinstance(outputs, (list, tuple)):
          decoded_outputs = type(outputs)()
          for i, v in enumerate(outputs):
              if output_types is not None:
                  # If the class has defined outputs, we can map directly according to the class definition
                  if output_types[i] in AGENT_TYPE_MAPPING:
                      decoded_outputs.append(
                          AGENT_TYPE_MAPPING[output_types[i]](v)
                      )
                  else:
                      decoded_outputs.append(AgentType(v))
              else:
                  # If the class does not have defined output, then we map according to the type
                  found = False
                  for _k, _v in INSTANCE_TYPE_MAPPING.items():
                      if isinstance(v, _k):
                          decoded_outputs.append(_v(v))
                          found = True
  
                  if not found:
                      decoded_outputs.append(AgentType(v))
  
      else:
          if output_types[0] in AGENT_TYPE_MAPPING:
              # If the class has defined outputs, we can map directly according to the class definition
              decoded_outputs = AGENT_TYPE_MAPPING[output_types[0]](
                  outputs
              )
  
          else:
              # If the class does not have defined output, then we map according to the type
              for _k, _v in INSTANCE_TYPE_MAPPING.items():
                  if isinstance(outputs, _k):
                      return _v(outputs)
              return AgentType(outputs)
  
      return decoded_outputs
  
imports: import os
  import pathlib
  import tempfile
  import uuid
  import numpy
  from ..utils import is_soundfile_availble, is_torch_available, is_vision_available, logging
label_desc: Use image node_id 2 for calling a global function with example usage: handle_agent_outputs(outputs, output_types) and returns: decoded_outputs, AgentType, _v