code: def train_agent_with_evaluation(
      agent,
      env,
      steps,
      eval_n_steps,
      eval_n_episodes,
      eval_interval,
      outdir,
      checkpoint_freq=None,
      train_max_episode_len=None,
      step_offset=0,
      eval_max_episode_len=None,
      eval_env=None,
      successful_score=None,
      step_hooks=(),
      save_best_so_far_agent=True,
      logger=None,
  ):
      """Train an agent while periodically evaluating it.
  
      Args:
          agent: A chainerrl.agent.Agent
          env: Environment train the agent against.
          steps (int): Total number of timesteps for training.
          eval_n_steps (int): Number of timesteps at each evaluation phase.
          eval_n_episodes (int): Number of episodes at each evaluation phase.
          eval_interval (int): Interval of evaluation.
          outdir (str): Path to the directory to output data.
          checkpoint_freq (int): frequency at which agents are stored.
          train_max_episode_len (int): Maximum episode length during training.
          step_offset (int): Time step from which training starts.
          eval_max_episode_len (int or None): Maximum episode length of
              evaluation runs. If None, train_max_episode_len is used instead.
          eval_env: Environment used for evaluation.
          successful_score (float): Finish training if the mean score is greater
              than or equal to this value if not None
          step_hooks (Sequence): Sequence of callable objects that accepts
              (env, agent, step) as arguments. They are called every step.
              See chainerrl.experiments.hooks.
          save_best_so_far_agent (bool): If set to True, after each evaluation
              phase, if the score (= mean return of evaluation episodes) exceeds
              the best-so-far score, the current agent is saved.
          logger (logging.Logger): Logger used in this function.
      """
  
      logger = logger or logging.getLogger(__name__)
  
      os.makedirs(outdir, exist_ok=True)
  
      if eval_env is None:
          eval_env = env
  
      if eval_max_episode_len is None:
          eval_max_episode_len = train_max_episode_len
  
      evaluator = Evaluator(
          agent=agent,
          n_steps=eval_n_steps,
          n_episodes=eval_n_episodes,
          eval_interval=eval_interval,
          outdir=outdir,
          max_episode_len=eval_max_episode_len,
          env=eval_env,
          step_offset=step_offset,
          save_best_so_far_agent=save_best_so_far_agent,
          logger=logger,
      )
  
      train_agent(
          agent,
          env,
          steps,
          outdir,
          checkpoint_freq=checkpoint_freq,
          max_episode_len=train_max_episode_len,
          step_offset=step_offset,
          evaluator=evaluator,
          successful_score=successful_score,
          step_hooks=step_hooks,
          logger=logger,
      )
  
file_path: chainerrl/chainerrl/experiments/train_agent.py
imports: import logging
  import os
  from chainerrl.experiments.evaluator import Evaluator
  from chainerrl.experiments.evaluator import save_agent
  from chainerrl.misc.ask_yes_no import ask_yes_no
label_desc: Use image node_id 4 for calling a global function with example usage: train_agent_with_evaluation(agent, env, steps, eval_n_steps, eval_n_episodes, eval_interval, outdir, checkpoint_freq, train_max_episode_len, step_offset, eval_max_episode_len, eval_env, successful_score, step_hooks, save_best_so_far_agent, logger) without return types