class_docstr: Tensorforce agent interface.
class_docstr_tok: ["Tensorforce","agent","interface","."]
docstr: Restores an agent from a directory/file.
  
  Args:
      directory (str): Checkpoint directory
          (<span style="color:#C00000"><b>required</b></span>, unless saver is specified).
      filename (str): Checkpoint filename, with or without append and extension
          (<span style="color:#00C000"><b>default</b></span>: "agent").
      format ("checkpoint" | "numpy" | "hdf5"): File format
          (<span style="color:#00C000"><b>default</b></span>: format matching directory and
          filename, required to be unambiguous).
      environment (Environment object): Environment which the agent is supposed to be trained
          on, environment-related arguments like state/action space specifications and
          maximum episode length will be extract if given
          (<span style="color:#C00000"><b>recommended</b></span>).
      kwargs: Additional agent arguments.
docstr_tok: ["Restores","an","agent","from","a","directory\/file",".","Args",":","directory","(","str",")",":","Checkpoint","directory","(","<","span","style=","''","color",":","#","C00000","''",">","<","b",">","required","<","\/b",">","<","\/span",">",",","unless","saver","is","specified",")",".","filename","(","str",")",":","Checkpoint","filename",",","with","or","without","append","and","extension","(","<","span","style=","''","color",":","#","00C000","''",">","<","b",">","default","<","\/b",">","<","\/span",">",":","``","agent","''",")",".","format","(","``","checkpoint","''","|","``","numpy","''","|","``","hdf5","''",")",":","File","format","(","<","span","style=","''","color",":","#","00C000","''",">","<","b",">","default","<","\/b",">","<","\/span",">",":","format","matching","directory","and","filename",",","required","to","be","unambiguous",")",".","environment","(","Environment","object",")",":","Environment","which","the","agent","is","supposed","to","be","trained","on",",","environment-related","arguments","like","state\/action","space","specifications","and","maximum","episode","length","will","be","extract","if","given","(","<","span","style=","''","color",":","#","C00000","''",">","<","b",">","recommended","<","\/b",">","<","\/span",">",")",".","kwargs",":","Additional","agent","arguments","."]
code: def load(
      directory=None,
      filename=None,
      format=None,
      environment=None,
      **kwargs,
  ):
      """
      Restores an agent from a directory/file.
  
      Args:
          directory (str): Checkpoint directory
              (<span style="color:#C00000"><b>required</b></span>, unless saver is specified).
          filename (str): Checkpoint filename, with or without append and extension
              (<span style="color:#00C000"><b>default</b></span>: "agent").
          format ("checkpoint" | "numpy" | "hdf5"): File format
              (<span style="color:#00C000"><b>default</b></span>: format matching directory and
              filename, required to be unambiguous).
          environment (Environment object): Environment which the agent is supposed to be trained
              on, environment-related arguments like state/action space specifications and
              maximum episode length will be extract if given
              (<span style="color:#C00000"><b>recommended</b></span>).
          kwargs: Additional agent arguments.
      """
      if directory is not None:
          if filename is None:
              filename = "agent"
          agent = os.path.join(
              directory, os.path.splitext(filename)[0] + ".json"
          )
          if (
              not os.path.isfile(agent)
              and agent[agent.rfind("-") + 1 : -5].isdigit()
          ):
              agent = agent[: agent.rindex("-")] + ".json"
          if os.path.isfile(agent):
              with open(agent, "r") as fp:
                  agent = json.load(fp=fp)
              if "agent" in kwargs:
                  if (
                      "agent" in agent
                      and agent["agent"] != kwargs["agent"]
                  ):
                      raise TensorforceError.value(
                          name="Agent.load",
                          argument="agent",
                          value=kwargs["agent"],
                      )
                  agent["agent"] = kwargs.pop("agent")
          else:
              agent = kwargs
              kwargs = dict()
      else:
          agent = kwargs
          kwargs = dict()
  
      # Overwrite values
      if agent.get("max_episode_timesteps") is None:
          if (
              environment is not None
              and environment.max_episode_timesteps() is not None
          ):
              if "max_episode_timesteps" in kwargs:
                  assert (
                      kwargs["max_episode_timesteps"]
                      >= environment.max_episode_timesteps()
                  )
                  agent["max_episode_timesteps"] = kwargs[
                      "max_episode_timesteps"
                  ]
              else:
                  agent[
                      "max_episode_timesteps"
                  ] = environment.max_episode_timesteps()
      if (
          "parallel_interactions" in kwargs
          and kwargs["parallel_interactions"] > 1
      ):
          agent["parallel_interactions"] = kwargs[
              "parallel_interactions"
          ]
  
      agent.pop("internals", None)
      agent.pop("initial_internals", None)
      saver_restore = False
      if "saver" in agent and isinstance(agent["saver"], dict):
          if not agent.get("load", True):
              raise TensorforceError.value(
                  name="Agent.load",
                  argument="saver[load]",
                  value=agent["saver"]["load"],
              )
          agent["saver"] = dict(agent["saver"])
          agent["saver"]["load"] = True
          saver_restore = True
      elif "saver" in kwargs and isinstance(kwargs["saver"], dict):
          if not kwargs.get("load", True):
              raise TensorforceError.value(
                  name="Agent.load",
                  argument="saver[load]",
                  value=kwargs["saver"]["load"],
              )
          kwargs["saver"] = dict(kwargs["saver"])
          kwargs["saver"]["load"] = True
          saver_restore = True
      agent = Agent.create(
          agent=agent, environment=environment, **kwargs
      )
      if not saver_restore:
          agent.restore(
              directory=directory, filename=filename, format=format
          )
  
      return agent
  
imports: from collections import OrderedDict
  import json
  import logging
  import os
  import random
  import numpy
  import tensorflow
  from tensorforce import util, TensorforceError
  from tensorforce.agents import Recorder
  import tensorforce.agents
  from tensorforce.core import ArrayDict, TensorSpec, TensorforceConfig
label_desc: Use image node_id 2 for calling the Agent obj's underlying member method code with example usage: obj.load(directory, filename, format, environment) and returns: agent