Package org.springframework.ai.session
Class SessionEvent
java.lang.Object
org.springframework.ai.session.SessionEvent
An entry of a session's log. An event has an
EventType: a
EventType.MESSAGE event wraps a Spring AI Message and adds what the
message intentionally lacks, identity, ordering and the session it belongs to; every
other type records runtime state, a compaction or an application's own event, in
getPayload() instead of a message, and getMessage() throws for it.
Message events are the conversation: they alone take part in prompt assembly and
compaction.
An event is never changed once appended. A compaction records what left the active view
in a EventType.COMPACTION event of its own, and a covered event stays in the
log, readable through EventFilter.all(). A synthetic
event is one a compaction wrote: the user message that opens a summary turn and the
assistant message that closes it.
- Since:
- 2.1.0
- Author:
- Christian Tzolov
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringMetadata key of a synthetic event: the id of theEventType.COMPACTIONboundary it belongs to.static final StringMetadata key naming the strategy that wrote a synthetic event.static final StringMetadata key of the synthetic flag, aBoolean. -
Method Summary
Modifier and TypeMethodDescriptionstatic SessionEvent.Builderbuilder()Returns a newSessionEvent.Builder.booleangetId()The identity of the event, unique across sessions.The wrapped Spring AI message.The type of the wrapped message.Framework flags such asMETADATA_SYNTHETICandMETADATA_COMPACTION_SOURCE, and whatever the application adds.The data of an event that is not a message, the ids aEventType.COMPACTIONboundary names for example; empty for a message event.The session the event belongs to.When the event was recorded.getType()What the event records;EventType.MESSAGEfor a conversation message.inthashCode()booleanWhether the event carries a message, so thatgetMessage()can be called: aEventType.MESSAGEevent does; seeEventType.canCarryMessage().booleanWhether the event is an assistant message with tool calls;falsefor an event without a message.booleanWhether a compaction wrote this event, a summary rather than something a participant said.booleanWhether the event starts a turn: aMessageType.USERmessage event.
-
Field Details
-
METADATA_SYNTHETIC
Metadata key of the synthetic flag, aBoolean.- See Also:
-
METADATA_COMPACTION_SOURCE
Metadata key naming the strategy that wrote a synthetic event.- See Also:
-
METADATA_COMPACTION_ID
Metadata key of a synthetic event: the id of theEventType.COMPACTIONboundary it belongs to.- See Also:
-
-
Method Details
-
getId
The identity of the event, unique across sessions. -
getSessionId
The session the event belongs to. -
getTimestamp
When the event was recorded. A log is ordered by insertion, not by this. -
getType
What the event records;EventType.MESSAGEfor a conversation message. -
hasMessage
public boolean hasMessage()Whether the event carries a message, so thatgetMessage()can be called: aEventType.MESSAGEevent does; seeEventType.canCarryMessage(). -
getMessage
The wrapped Spring AI message.- Throws:
IllegalStateException- if the event carries no message; seehasMessage()
-
getPayload
The data of an event that is not a message, the ids aEventType.COMPACTIONboundary names for example; empty for a message event. Values must be JSON-serializable. -
getMetadata
Framework flags such asMETADATA_SYNTHETICandMETADATA_COMPACTION_SOURCE, and whatever the application adds. -
getMessageType
The type of the wrapped message.- Throws:
IllegalStateException- if the event carries no message; seehasMessage()
-
isSynthetic
public boolean isSynthetic()Whether a compaction wrote this event, a summary rather than something a participant said. -
isTurnStart
public boolean isTurnStart()Whether the event starts a turn: aMessageType.USERmessage event. A turn is a user message plus everything up to the next one, the assistant replies, the tool calls and their results, so it is the unit no read or compaction cut may split. A synthetic shadow prompt is a user message too, so a summary turn is never separated from its summary. An event that is not aEventType.MESSAGEnever starts a turn. -
hasToolCalls
public boolean hasToolCalls()Whether the event is an assistant message with tool calls;falsefor an event without a message. -
equals
-
hashCode
public int hashCode() -
builder
Returns a newSessionEvent.Builder.
-