def _run_trial(mdp, agent):
    """
    Reset the MDP to its initial state, then continually prompt the agent for 
    actions until the MDP reaches a terminal state.
    """
    mdp.reset()
    prev_state = None

    while not mdp.is_terminal():
        action = agent.get_next_action(mdp.copy())

        prev_state = mdp.copy()
        reward, terminal = mdp.step(action)

        agent.update(prev_state, mdp, reward, action, terminal)

    return mdp.timesteps