code: def generate_trajectory(sequence_fn, space, n_steps):
      """Generates random actions and observations that follow sequence_fn."""
      act = [space.sample() for _ in range(n_steps)]
      obs = [space.sample()]
  
      for o, a in zip(
          obs,
          act[:-1],  # Don't generate the last observation.
      ):
          context = list(np.array([o, a]).flatten())
          symbols = []
          for _ in range(np.array(o).size):
              symbol = sequence_fn(context + symbols)
              symbols.append(symbol)
          obs.append(np.reshape(symbols, space.shape))
  
      obs = np.array([obs])
      act = np.array([act])
      return (obs, act)
  
imports: import functools
  import io
  from unittest import mock
  from absl.testing import absltest
  from absl.testing import parameterized
  import gym
  import numpy
  from trax import models
  from trax import test_utils
  from trax.data import inputs
  from trax.layers import test_utils
  from trax.rl import serialization_utils
  from trax.rl import space_serializer
  from trax.supervised import callbacks
  from trax.supervised import lr_schedules
  from trax.supervised import trainer_lib
  from trax.supervised import training
label_desc: Use image node_id 3 for calling a global function with example usage: generate_trajectory(sequence_fn, space, n_steps) and returns: obs,  act