Class MessageAggregator
java.lang.Object
org.springframework.ai.chat.model.MessageAggregator
Helper that for streaming chat responses, aggregate the chat response messages into a
single AssistantMessage. Job is performed in parallel to the chat response processing.
Parts stamped with a content block index (see StreamingParts) are merged per
index: deltas are appended, a complete part replaces the slot. Indexed parts are
grouped by the response id carried in ChatResponseMetadata; groups keep the
order in which they were first seen and parts are ordered by index within a group. When
a chat model does not stamp a response id, a new group starts whenever the block index
goes backwards or a slot that already holds content receives a part it cannot continue.
Parts without an index follow the legacy behavior: text is concatenated into one part,
tool calls are appended, reasoning and unknown parts are carried in arrival order,
media on chunks is not carried.
- Since:
- 1.0.0
- Author:
- Christian Tzolov, Alexandros Pappas, Thomas Vitale, Heonwoo Kim
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordDefault implementation ofUsagefor aggregated streaming responses. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionreactor.core.publisher.Flux<ChatResponse>aggregate(reactor.core.publisher.Flux<ChatResponse> fluxChatResponse, Consumer<ChatResponse> onAggregationComplete)
-
Constructor Details
-
MessageAggregator
public MessageAggregator()
-
-
Method Details
-
aggregate
public reactor.core.publisher.Flux<ChatResponse> aggregate(reactor.core.publisher.Flux<ChatResponse> fluxChatResponse, Consumer<ChatResponse> onAggregationComplete)
-