docstr: Check for timed-out agents in pool.
  
  :param world_type:
      world type
  :param agent_pool:
      list of AgentStates
  :param max_time_in_pool:
      maximum time allowed for agent to be in pool
  :param backup_task:
      backup_task to start if we reach a timeout in the original pool
code: def check_timeout_in_pool(
      self,
      world_type: str,
      agent_pool: List[AgentState],
      max_time_in_pool: int,
      backup_task: str = None,
  ):
      """
      Check for timed-out agents in pool.
  
      :param world_type:
          world type
      :param agent_pool:
          list of AgentStates
      :param max_time_in_pool:
          maximum time allowed for agent to be in pool
      :param backup_task:
          backup_task to start if we reach a timeout in the original pool
      """
      for agent_state in agent_pool:
          time_in_pool = agent_state.time_in_pool.get(world_type)
          if (
              time_in_pool
              and time.time() - time_in_pool > max_time_in_pool
          ):
              # remove agent from agent_pool
              self.remove_agent_from_pool(agent_state, world_type)
              # put agent back in overworld
              agent_state.set_active_agent(
                  agent_state.get_overworld_agent()
              )
  
              agent_state.stored_data["removed_after_timeout"] = True
              self.after_agent_removed(agent_state.service_id)
  
              if backup_task is not None:
                  self.add_agent_to_pool(agent_state, backup_task)
  
              # reset wait message state
              agent_state.stored_data["seen_wait_message"] = False
  
          elif time_in_pool and time.time() - time_in_pool > 30:
              # tell agent that a match is taking longer than
              # expected
              if (
                  not agent_state.stored_data.get("seen_wait_message")
                  or not agent_state.stored_data["seen_wait_message"]
              ):
                  self.observe_message(
                      agent_state.service_id,
                      "Pairing is taking longer than expected. "
                      "If you wish to exit, type *EXIT*.",
                  )
                  self.sender.typing_on(agent_state.service_id)  # type: ignore
                  agent_state.stored_data["seen_wait_message"] = True
  
imports: from abc import ABC, abstractmethod
  from asyncio import Future
  import copy
  import sys
  import logging
  import datetime
  import threading
  import time
  import traceback
  from typing import Dict, Any, Optional, List, Callable
  from parlai.chat_service.core.agents import ChatServiceAgent
  import parlai.chat_service.utils.logging
  import parlai.chat_service.utils.misc
  import parlai.chat_service.utils.server
  from parlai.chat_service.core.world_runner import ChatServiceWorldRunner
  from parlai.core.opt import Opt
label_desc: Use image node_id 28 for calling the ChatServiceManager obj's underlying member method code with example usage: obj.check_timeout_in_pool(world_type, agent_pool, max_time_in_pool, backup_task) without return types