code: def n_step_from_trajectory(
      trajectory: reverb_base.Trajectory,
      agent_discount: float,
  ) -> types.Transition:
      """Converts an (n+1)-step trajectory into an n-step transition."""
  
      rewards, discount = _compute_cumulative_quantities(
          rewards=trajectory.reward,
          discounts=trajectory.discount,
          additional_discount=agent_discount,
      )
  
      tmap = tree.map_structure
      return types.Transition(
          observation=tmap(lambda x: x[0], trajectory.observation),
          action=tmap(lambda x: x[0], trajectory.action),
          reward=rewards,
          discount=discount,
          next_observation=tmap(
              lambda x: x[-1], trajectory.observation
          ),
          extras=tmap(lambda x: x[0], trajectory.extras),
      )
  
imports: import itertools
  import time
  from typing import Callable, List, Optional, Sequence, Sized
  from absl import logging
  from acme import specs
  from acme import types
  from acme.adders import base
  from acme.adders.reverb import base
  from acme.adders.reverb import sequence
  from acme.utils import tree_utils
  import dm_env
  import numpy
  import reverb
  from reverb import structured_writer
  import tensorflow
  import tree
label_desc: Use image node_id 5 for calling a global function with example usage: n_step_from_trajectory(trajectory, agent_discount) and returns: types