Package com.tnsai.session.replay
Class SessionReplay
java.lang.Object
com.tnsai.session.replay.SessionReplay
- All Implemented Interfaces:
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordStatistics about a session replay. -
Method Summary
Modifier and TypeMethodDescriptionGets only assistant message steps.Generates a compact summary.current()Gets the current step.filterSteps(Predicate<ReplayStep> predicate) Gets steps filtered by predicate.first()Goes to the first step.Gets all steps as a list.intGets the current step index.Gets the session being replayed.getStats()Gets statistics about the session.getStep(int index) Gets a step by index without changing position.goTo(int index) Goes to a specific step by index.booleanhasNext()booleanChecks if there is a previous step.booleanisEmpty()Checks if the session is empty.last()Goes to the last step.next()static SessionReplayof(AgentSession session) Creates a replay for the given session.previous()Goes to the previous step.replayUntil(Predicate<ReplayStep> stopCondition) Replays until a condition is met.voidreset()Resets the replay to the beginning.intsize()Gets the total number of steps.stream()Returns a stream of all steps.Generates a text summary of the session.Gets only tool call steps.Gets only user message steps.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Iterator
forEachRemaining, remove
-
Method Details
-
of
Creates a replay for the given session.- Parameters:
session- the session to replay- Returns:
- the replay instance
-
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
Gets the current step.- Returns:
- current step, or empty if not started or finished
-
hasNext
public boolean hasNext()- Specified by:
hasNextin interfaceIterator<ReplayStep>
-
next
- Specified by:
nextin interfaceIterator<ReplayStep>
-
hasPrevious
public boolean hasPrevious()Checks if there is a previous step. -
previous
Goes to the previous step.- Returns:
- the previous step
- Throws:
NoSuchElementException- if at the beginning
-
goTo
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
Goes to the first step.- Returns:
- the first step
- Throws:
NoSuchElementException- if session is empty
-
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
Gets a step by index without changing position.- Parameters:
index- the step index- Returns:
- the step
-
getAllSteps
Gets all steps as a list. -
stream
Returns a stream of all steps. -
userMessages
Gets only user message steps. -
assistantMessages
Gets only assistant message steps. -
toolCalls
Gets only tool call steps. -
filterSteps
Gets steps filtered by predicate. -
replayUntil
Replays until a condition is met.- Parameters:
stopCondition- condition to stop at- Returns:
- the step where replay stopped, or empty if end reached
-
summarize
Generates a text summary of the session. -
compactSummary
Generates a compact summary. -
getStats
Gets statistics about the session.
-