class_docstr: Tensorforce agent interface.
class_docstr_tok: ["Tensorforce","agent","interface","."]
docstr: Saves the agent to a checkpoint.
  
  Args:
      directory (str): Checkpoint directory
          (<span style="color:#C00000"><b>required</b></span>).
      filename (str): Checkpoint filename, without extension
          (<span style="color:#00C000"><b>default</b></span>: agent name).
      format ("checkpoint" | "saved-model" | "numpy" | "hdf5"): File format, "checkpoint"
          uses the [TensorFlow Checkpoint](https://www.tensorflow.org/guide/checkpoint) to
          save the model, "saved-model" uses the
          [TensorFlow SavedModel](https://www.tensorflow.org/guide/saved_model) to save an
          optimized act-only model (use only if you really need TF's SavedModel format,
          loading not supported), whereas the others store only variables as NumPy/HDF5 file
          (<span style="color:#00C000"><b>default</b></span>: TensorFlow Checkpoint).
      append ("timesteps" | "episodes" | "updates"): Append timestep/episode/update to
          checkpoint filename
          (<span style="color:#00C000"><b>default</b></span>: none).
  
  Returns:
      str: Checkpoint path.
docstr_tok: ["Saves","the","agent","to","a","checkpoint",".","Args",":","directory","(","str",")",":","Checkpoint","directory","(","<","span","style=","''","color",":","#","C00000","''",">","<","b",">","required","<","\/b",">","<","\/span",">",")",".","filename","(","str",")",":","Checkpoint","filename",",","without","extension","(","<","span","style=","''","color",":","#","00C000","''",">","<","b",">","default","<","\/b",">","<","\/span",">",":","agent","name",")",".","format","(","``","checkpoint","''","|","``","saved-model","''","|","``","numpy","''","|","``","hdf5","''",")",":","File","format",",","``","checkpoint","''","uses","the","[","TensorFlow","Checkpoint","]","(","https",":","\/\/www.tensorflow.org\/guide\/checkpoint",")","to","save","the","model",",","``","saved-model","''","uses","the","[","TensorFlow","SavedModel","]","(","https",":","\/\/www.tensorflow.org\/guide\/saved_model",")","to","save","an","optimized","act-only","model","(","use","only","if","you","really","need","TF","'s","SavedModel","format",",","loading","not","supported",")",",","whereas","the","others","store","only","variables","as","NumPy\/HDF5","file","(","<","span","style=","''","color",":","#","00C000","''",">","<","b",">","default","<","\/b",">","<","\/span",">",":","TensorFlow","Checkpoint",")",".","append","(","``","timesteps","''","|","``","episodes","''","|","``","updates","''",")",":","Append","timestep\/episode\/update","to","checkpoint","filename","(","<","span","style=","''","color",":","#","00C000","''",">","<","b",">","default","<","\/b",">","<","\/span",">",":","none",")",".","Returns",":","str",":","Checkpoint","path","."]
code: def save(
      self, directory, filename=None, format="checkpoint", append=None
  ):
      """
      Saves the agent to a checkpoint.
  
      Args:
          directory (str): Checkpoint directory
              (<span style="color:#C00000"><b>required</b></span>).
          filename (str): Checkpoint filename, without extension
              (<span style="color:#00C000"><b>default</b></span>: agent name).
          format ("checkpoint" | "saved-model" | "numpy" | "hdf5"): File format, "checkpoint"
              uses the [TensorFlow Checkpoint](https://www.tensorflow.org/guide/checkpoint) to
              save the model, "saved-model" uses the
              [TensorFlow SavedModel](https://www.tensorflow.org/guide/saved_model) to save an
              optimized act-only model (use only if you really need TF's SavedModel format,
              loading not supported), whereas the others store only variables as NumPy/HDF5 file
              (<span style="color:#00C000"><b>default</b></span>: TensorFlow Checkpoint).
          append ("timesteps" | "episodes" | "updates"): Append timestep/episode/update to
              checkpoint filename
              (<span style="color:#00C000"><b>default</b></span>: none).
  
      Returns:
          str: Checkpoint path.
      """
      # TODO: Messes with required parallel disentangling, better to remove unfinished episodes
      # from memory, but currently entire episode buffered anyway...
      # Empty buffers before saving
      # for parallel in range(self.parallel_interactions):
      #     if self.buffer_indices[parallel] > 0:
      #         self.model_observe(parallel=parallel)
      os.makedirs(directory, exist_ok=True)
      path = self.model.save(
          directory=directory,
          filename=filename,
          format=format,
          append=append,
      )
  
      if filename is None:
          filename = self.model.name
      spec_path = os.path.join(directory, filename + ".json")
      try:
          with open(spec_path, "w") as fp:
              spec = OrderedDict(self.spec)
              spec["internals"] = self.internals_spec
              spec["initial_internals"] = self.initial_internals()
              json.dump(obj=spec, fp=fp, cls=TensorforceJSONEncoder)
      except BaseException:
          logging.warning(
              "Some agent argument could not be encoded to JSON as part of "
              "Agent.save(), likely a Python object or class. Either specify as "
              "module string or dictionary, or pass the full set of agent arguments "
              "when loading via Agent.load()."
          )
          try:
              with open(spec_path, "w") as fp:
                  spec = OrderedDict()
                  spec["states"] = self.spec["states"]
                  spec["actions"] = self.spec["actions"]
                  spec["internals"] = self.internals_spec
                  spec["initial_internals"] = self.initial_internals()
                  json.dump(obj=spec, fp=fp, cls=TensorforceJSONEncoder)
          except BaseException:
              os.remove(spec_path)
  
      return path
  
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 15 for calling the Agent obj's underlying member method code with example usage: obj.save(directory, filename, format, append) and returns: path