Class ToolExecutionResultMessage
java.lang.Object
dev.langchain4j.data.message.ToolExecutionResultMessage
- All Implemented Interfaces:
ChatMessage
Represents the result of a tool execution in response to a
The result is stored as a list of
ToolExecutionRequest.
ToolExecutionRequests come from a previous AiMessage.toolExecutionRequests().
The result is stored as a list of
Contents. Typically, the result is a single TextContent,
but some LLM providers also support ImageContent in tool results.-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionCreates aToolExecutionResultMessagefrom a builder.ToolExecutionResultMessage(String id, String toolName, String text) Creates aToolExecutionResultMessage. -
Method Summary
Modifier and TypeMethodDescriptionReturns attributes of a message.builder()Creates a builder forToolExecutionResultMessage.contents()Returns theContents of the tool execution result.booleanstatic ToolExecutionResultMessagefrom(ToolExecutionRequest request, String toolExecutionResult) Creates aToolExecutionResultMessagefrom aToolExecutionRequestand the result of the tool execution.static ToolExecutionResultMessageCreates aToolExecutionResultMessagefrom aToolExecutionRequestand the result of the tool execution.inthashCode()booleanWhether this message contains a singleTextContent.id()Returns the id of the tool.isError()Returns whether the tool execution resulted in an error.text()Returns the result of the tool execution as text.static ToolExecutionResultMessagetoolExecutionResultMessage(ToolExecutionRequest request, String toolExecutionResult) Creates aToolExecutionResultMessagefrom aToolExecutionRequestand the result of the tool execution.static ToolExecutionResultMessagetoolExecutionResultMessage(String id, String toolName, String toolExecutionResult) Creates aToolExecutionResultMessagefrom aToolExecutionRequestand the result of the tool execution.toolName()Returns the name of the tool.toString()type()The type of the message.
-
Constructor Details
-
ToolExecutionResultMessage
Creates aToolExecutionResultMessagefrom a builder.- Since:
- 1.11.0
-
ToolExecutionResultMessage
Creates aToolExecutionResultMessage.- Parameters:
id- the id of the tool.toolName- the name of the tool.text- the result of the tool execution.
-
-
Method Details
-
id
-
toolName
-
text
Returns the result of the tool execution as text.- Returns:
- the text result of the tool execution.
- Throws:
IllegalStateException- if contents contains non-text or multiple content elements. Usecontents()instead.
-
contents
Returns theContents of the tool execution result.- Returns:
- the contents.
- Since:
- 1.13.0
-
hasSingleText
Whether this message contains a singleTextContent.- Returns:
trueif this message contains exactly one element which is aTextContent.- Since:
- 1.13.0
- See Also:
-
isError
Returns whether the tool execution resulted in an error.- Returns:
- true if the tool execution resulted in an error, false if it did not, null if unknown.
-
attributes
Returns attributes of a message. These attributes are not sent to the LLM, but can be persisted in aChatMemory.- Since:
- 1.12.0
-
type
Description copied from interface:ChatMessageThe type of the message.- Specified by:
typein interfaceChatMessage- Returns:
- the type of the message
-
equals
-
hashCode
-
toString
-
builder
Creates a builder forToolExecutionResultMessage.- Returns:
- the builder.
-
from
public static ToolExecutionResultMessage from(ToolExecutionRequest request, String toolExecutionResult) Creates aToolExecutionResultMessagefrom aToolExecutionRequestand the result of the tool execution.- Parameters:
request- the request.toolExecutionResult- the result of the tool execution.- Returns:
- the
ToolExecutionResultMessage.
-
from
public static ToolExecutionResultMessage from(String id, String toolName, String toolExecutionResult) Creates aToolExecutionResultMessagefrom aToolExecutionRequestand the result of the tool execution.- Parameters:
id- the id of the tool.toolName- the name of the tool.toolExecutionResult- the result of the tool execution.- Returns:
- the
ToolExecutionResultMessage.
-
toolExecutionResultMessage
public static ToolExecutionResultMessage toolExecutionResultMessage(ToolExecutionRequest request, String toolExecutionResult) Creates aToolExecutionResultMessagefrom aToolExecutionRequestand the result of the tool execution.- Parameters:
request- the request.toolExecutionResult- the result of the tool execution.- Returns:
- the
ToolExecutionResultMessage.
-
toolExecutionResultMessage
public static ToolExecutionResultMessage toolExecutionResultMessage(String id, String toolName, String toolExecutionResult) Creates aToolExecutionResultMessagefrom aToolExecutionRequestand the result of the tool execution.- Parameters:
id- the id of the tool.toolName- the name of the tool.toolExecutionResult- the result of the tool execution.- Returns:
- the
ToolExecutionResultMessage.
-