Class ToolResponseMessage
java.lang.Object
org.springframework.ai.chat.messages.AbstractMessage
org.springframework.ai.chat.messages.ToolResponseMessage
The ToolResponseMessage class represents a message with a function content in a chat
application.
The message content is an ordered list of MessageParts, one
ToolResultPart per tool result, so a result can carry more than a string, for
example media or an error flag. getResponses() is a view over the parts that
keeps only the text of each result. Messages built through the legacy constructor or
the ToolResponseMessage.Builder.responses(List) setter get one text-only result part per response,
so existing code keeps working unchanged.
- Since:
- 1.0.0
- Author:
- Christian Tzolov, Eric Bottard
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder forToolResponseMessage.static final recordA tool response. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final List<ToolResponseMessage.ToolResponse>Deprecated, for removal: This API element is subject to removal in a future version.Fields inherited from class org.springframework.ai.chat.messages.AbstractMessage
MESSAGE_TYPE, messageType, metadata, textContent -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedToolResponseMessage(List<ToolResponseMessage.ToolResponse> responses, Map<String, Object> metadata) protectedToolResponseMessage(Map<String, Object> metadata, List<MessagePart> parts) Creates a message from an ordered list of parts. -
Method Summary
Modifier and TypeMethodDescriptionstatic ToolResponseMessage.Builderbuilder()The tool responses of this message: the text of eachToolResultPart, in part order.The tool results of this message, in part order.getText()Tool response messages never had anulltext, even with no responses at all; onlyAbstractMessage's generic rule for an empty parts list would say otherwise.mutate()A builder pre-populated with this message's parts and metadata.toString()Methods inherited from class org.springframework.ai.chat.messages.AbstractMessage
equals, getMessageType, getMetadata, getParts, hashCode, legacyParts, select
-
Field Details
-
responses
@Deprecated(since="2.1.0", forRemoval=true) protected final List<ToolResponseMessage.ToolResponse> responsesDeprecated, for removal: This API element is subject to removal in a future version.since 2.1.0 in favor ofgetResponses(); kept so existing subclasses that read the field keep compiling. Will be removed in a future release.The responses of this message, derived from itsToolResultParts.
-
-
Constructor Details
-
ToolResponseMessage
protected ToolResponseMessage(List<ToolResponseMessage.ToolResponse> responses, Map<String, Object> metadata) -
ToolResponseMessage
Creates a message from an ordered list of parts. The metadata comes first because the legacy constructor already takes a list and a map in the other order and the two would otherwise have the same erasure.- Parameters:
metadata- the message metadataparts- the parts, in order- Since:
- 2.1.0
-
-
Method Details
-
builder
-
getResults
The tool results of this message, in part order.- Returns:
- an unmodifiable list of result parts
- Since:
- 2.1.0
-
getResponses
The tool responses of this message: the text of eachToolResultPart, in part order. Content a string cannot carry, such as media, is not included; readgetResults()for it.- Returns:
- an unmodifiable list of responses
-
getText
Tool response messages never had anulltext, even with no responses at all; onlyAbstractMessage's generic rule for an empty parts list would say otherwise.- Specified by:
getTextin interfaceContent- Overrides:
getTextin classAbstractMessage- Returns:
- the content of the message
-
mutate
A builder pre-populated with this message's parts and metadata.- Returns:
- the builder
- Since:
- 2.1.0
-
toString
-
getResponses(); kept so existing subclasses that read the field keep compiling.