Record Class ToolResultPart
java.lang.Object
java.lang.Record
org.springframework.ai.chat.messages.part.ToolResultPart
- Record Components:
id- the id of the tool call this result answers, ornullwhen the provider returned no id (Ollama can)name- the tool name, ornullwhen unknowncontent- the result content, copied and unmodifiableisError- whether the tool reported an errorpayload- provider data to replay with this part, ornullattributes- free-form attributes, copied and unmodifiable
- All Implemented Interfaces:
MessagePart
public record ToolResultPart(@Nullable String id, @Nullable String name, List<MessagePart> content, boolean isError, @Nullable OpaquePayload payload, Map<String,String> attributes)
extends Record
implements MessagePart
The result of one tool call. The nested
content lets a result carry media,
which a plain string cannot.- Since:
- 2.1.0
- Author:
- Christian Tzolov
-
Constructor Summary
ConstructorsConstructorDescriptionToolResultPart(@Nullable String id, @Nullable String name, List<MessagePart> content, boolean isError, @Nullable OpaquePayload payload, Map<String, String> attributes) Creates an instance of aToolResultPartrecord class. -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of theattributesrecord component.content()Returns the value of thecontentrecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.@Nullable Stringid()Returns the value of theidrecord component.booleanisError()Returns the value of theisErrorrecord component.@Nullable Stringname()Returns the value of thenamerecord component.static ToolResultPartof(ToolResponseMessage.ToolResponse response) Wraps a legacyToolResponseMessage.ToolResponseas a result part with a single text part.@Nullable OpaquePayloadpayload()Returns the value of thepayloadrecord component.final StringtoString()Returns a string representation of this record class.Converts this part back to a legacyToolResponseMessage.ToolResponseby joining its text content.withAttributes(Map<String, String> attributes) Returns a copy of this part with the given attributes replacing the current ones.
-
Constructor Details
-
ToolResultPart
public ToolResultPart(@Nullable String id, @Nullable String name, List<MessagePart> content, boolean isError, @Nullable OpaquePayload payload, Map<String, String> attributes) Creates an instance of aToolResultPartrecord class.- Parameters:
id- the value for theidrecord componentname- the value for thenamerecord componentcontent- the value for thecontentrecord componentisError- the value for theisErrorrecord componentpayload- the value for thepayloadrecord componentattributes- the value for theattributesrecord component
-
-
Method Details
-
withAttributes
Description copied from interface:MessagePartReturns a copy of this part with the given attributes replacing the current ones. All other components are unchanged.- Specified by:
withAttributesin interfaceMessagePart- Parameters:
attributes- the new attributes, copied- Returns:
- the copy
-
of
Wraps a legacyToolResponseMessage.ToolResponseas a result part with a single text part. A response without text (anullresponse data, which the tool execution allows) becomes a part without content, so it converts back to the same response.- Parameters:
response- the tool response- Returns:
- the part
-
toToolResponse
Converts this part back to a legacyToolResponseMessage.ToolResponseby joining its text content. Non-text content is dropped, since aToolResponseMessage.ToolResponsecan only carry a string, and a part without any text content yields anullresponse data.- Returns:
- the tool response
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
id
Returns the value of theidrecord component.- Returns:
- the value of the
idrecord component
-
name
Returns the value of thenamerecord component.- Returns:
- the value of the
namerecord component
-
content
Returns the value of thecontentrecord component.- Returns:
- the value of the
contentrecord component
-
isError
public boolean isError()Returns the value of theisErrorrecord component.- Returns:
- the value of the
isErrorrecord component
-
payload
Returns the value of thepayloadrecord component.- Specified by:
payloadin interfaceMessagePart- Returns:
- the value of the
payloadrecord component
-
attributes
Returns the value of theattributesrecord component.- Specified by:
attributesin interfaceMessagePart- Returns:
- the value of the
attributesrecord component
-