code: def prepare_agent_readme(agent):
      """
      Load agent readme, add title if necessary.
  
      :param agent:
          string indicating agent module
  
      :return:
          agent's readme
      """
      readme_path = (
          f"{os.path.join(parlai.agents.__path__[0], agent)}/README.md"
      )
      if not os.path.exists(readme_path):
          raise RuntimeError(f"Agent {agent} must have README.md")
      with open(readme_path) as f:
          readme = f.readlines()
  
      if "# " not in readme[0]:
          readme[0] = f"# {agent}"
  
      # try to import all of the agents and look for their classes
      root = os.path.join(parlai.agents.__path__[0], agent)
      submodules = pkgutil.iter_modules([root])
      for sm in submodules:
          # look in the main folder
          if not (sm.name == agent or sm.name == "agents"):
              continue
          module_name = f"parlai.agents.{agent}.{sm.name}"
          module = importlib.import_module(module_name)
          for itemname in dir(module):
              # skip all private items
              if itemname.startswith("_"):
                  continue
              item = getattr(module, itemname)
              # avoid catching TorchAgent/TorchRankerAgent/...
              if (
                  inspect.isclass(item)
                  and issubclass(item, parlai.core.agents.Agent)
                  and hasattr(item, "add_cmdline_args")
                  and not inspect.isabstract(item)
              ):
                  # gather all the options
                  options = _make_argparse_table(item)
                  if options:
                      # if there were no options, don't mention it
                      readme.append(f"## {itemname} Options\n\n")
                      readme += options
  
      return readme
  
file_path: ParlAI/docs/source/generate_agent_list.py
imports: import parlai.core.agents
  import parlai.agents
  from parlai.core.params import ParlaiParser
  import argparse
  import os
  import pkgutil
  import importlib
  import inspect
label_desc: Use image node_id 2 for calling a global function with example usage: prepare_agent_readme(agent) and returns: readme