Class SessionReplay

java.lang.Object
com.tnsai.session.replay.SessionReplay
All Implemented Interfaces:
Iterator<ReplayStep>

public class SessionReplay extends Object implements Iterator<ReplayStep>
Provides replay functionality for agent sessions.

SessionReplay allows stepping through a completed session turn by turn, generating summaries, and navigating to specific points in the conversation.

Usage


 AgentSession session = sessionStore.load("session-123").orElseThrow();
 SessionReplay replay = SessionReplay.of(session);

 // Step-by-step replay
 while (replay.hasNext()) {
     ReplayStep step = replay.next();
     System.out.println(step.index() + ": " + step.description());
     System.out.println("  " + step.contentPreview(100));
 }

 // Navigate to specific step
 replay.goTo(5);

 // Get summary
 String summary = replay.summarize();
 
Author:
TnsAI Team
  • Method Details

    • of

      public static SessionReplay of(AgentSession session)
      Creates a replay for the given session.
      Parameters:
      session - the session to replay
      Returns:
      the replay instance
    • getSession

      public AgentSession getSession()
      Gets the session being replayed.
    • size

      public int size()
      Gets the total number of steps.
    • isEmpty

      public boolean isEmpty()
      Checks if the session is empty.
    • getCurrentIndex

      public int getCurrentIndex()
      Gets the current step index.
      Returns:
      current index, or -1 if not started
    • current

      public Optional<ReplayStep> current()
      Gets the current step.
      Returns:
      current step, or empty if not started or finished
    • hasNext

      public boolean hasNext()
      Specified by:
      hasNext in interface Iterator<ReplayStep>
    • next

      public ReplayStep next()
      Specified by:
      next in interface Iterator<ReplayStep>
    • hasPrevious

      public boolean hasPrevious()
      Checks if there is a previous step.
    • previous

      public ReplayStep previous()
      Goes to the previous step.
      Returns:
      the previous step
      Throws:
      NoSuchElementException - if at the beginning
    • goTo

      public ReplayStep goTo(int index)
      Goes to a specific step by index.
      Parameters:
      index - the step index (0-based)
      Returns:
      the step at that index
      Throws:
      IndexOutOfBoundsException - if index is invalid
    • first

      public ReplayStep first()
      Goes to the first step.
      Returns:
      the first step
      Throws:
      NoSuchElementException - if session is empty
    • last

      public ReplayStep last()
      Goes to the last step.
      Returns:
      the last step
      Throws:
      NoSuchElementException - if session is empty
    • reset

      public void reset()
      Resets the replay to the beginning.
    • getStep

      public ReplayStep getStep(int index)
      Gets a step by index without changing position.
      Parameters:
      index - the step index
      Returns:
      the step
    • getAllSteps

      public List<ReplayStep> getAllSteps()
      Gets all steps as a list.
    • stream

      public Stream<ReplayStep> stream()
      Returns a stream of all steps.
    • userMessages

      public List<ReplayStep> userMessages()
      Gets only user message steps.
    • assistantMessages

      public List<ReplayStep> assistantMessages()
      Gets only assistant message steps.
    • toolCalls

      public List<ReplayStep> toolCalls()
      Gets only tool call steps.
    • filterSteps

      public List<ReplayStep> filterSteps(Predicate<ReplayStep> predicate)
      Gets steps filtered by predicate.
    • replayUntil

      public Optional<ReplayStep> replayUntil(Predicate<ReplayStep> stopCondition)
      Replays until a condition is met.
      Parameters:
      stopCondition - condition to stop at
      Returns:
      the step where replay stopped, or empty if end reached
    • summarize

      public String summarize()
      Generates a text summary of the session.
    • compactSummary

      public String compactSummary()
      Generates a compact summary.
    • getStats

      public SessionReplay.ReplayStats getStats()
      Gets statistics about the session.