Event Publishing Conversation
A decorator that wraps any Conversation to publish MessageEvents when messages are added.
This enables event-driven patterns for any conversation implementation, including InMemoryConversation.
Usage
val conversation = InMemoryConversation(id = "session-1")
val eventPublishing = EventPublishingConversation(conversation, applicationEventPublisher)
// Now fires MessageEvent(status=ADDED) on every addMessage
eventPublishing.addMessage(UserMessage("Hello!"))Event Flow
This decorator fires MessageEvent with status MessageStatus.ADDED synchronously after the delegate adds the message.
For persistent conversations (like StoredConversation), additional events (MessageStatus.PERSISTED or MessageStatus.PERSISTENCE_FAILED) may be fired asynchronously by the underlying implementation.
Parameters
the underlying Conversation implementation
Spring's event publisher
optional default sender ID for published events
optional default recipient ID for published events
Constructors
Functions
Add a message and publish a MessageEvent with status ADDED.
Add a message with explicit author attribution. Useful for group chats or when the author differs per message.
Add a message with explicit author and recipient. Use this for multi-party chats where both sender and receiver need to be specified.
Create a nonpersistent conversation with the last n messages from this conversation.
Non-null if the conversation has messages and the last message is from the user.
The most recently timestamped assets
The most recently added assets
Prompt contributor that represents the conversation so far. Usually we will want to add messages from the conversation to a prompt instead of formatting the conversation
Convenience method to return references. References will be converted to matryoshka tools