Class AiMessage
java.lang.Object
dev.langchain4j.data.message.AiMessage
- All Implemented Interfaces:
ChatMessage
Represents a message generated by AI (language model).
This message can contain:
-text(): textual content -thinking(): thinking/reasoning content -toolExecutionRequests(): requests to execute tools -attributes(): additional attributes, typically provider-specific
In case this message contains tool execution requests,
the response to this message should be one ToolExecutionResultMessage for each tool execution request.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionAiMessage(AiMessage.Builder builder) Create a newAiMessagewith the given text.AiMessage(String text, List<ToolExecutionRequest> toolExecutionRequests) Create a newAiMessagewith the given text and tool execution requests.AiMessage(List<ToolExecutionRequest> toolExecutionRequests) Create a newAiMessagewith the given tool execution requests. -
Method Summary
Modifier and TypeMethodDescriptionstatic AiMessageaiMessage(ToolExecutionRequest... toolExecutionRequests) Create a newAiMessagewith the given tool execution requests.static AiMessageCreate a newAiMessagewith the given text.static AiMessageaiMessage(String text, List<ToolExecutionRequest> toolExecutionRequests) Create a newAiMessagewith the given text and tool execution requests.static AiMessageaiMessage(List<ToolExecutionRequest> toolExecutionRequests) Create a newAiMessagewith the given tool execution requests.<T> TReturns additional attribute by it's key.Returns additional attributes, typically provider-specific.static AiMessage.Builderbuilder()booleanstatic AiMessagefrom(ToolExecutionRequest... toolExecutionRequests) Create a newAiMessagewith the given tool execution requests.static AiMessageCreate a newAiMessagewith the given text.static AiMessagefrom(String text, List<ToolExecutionRequest> toolExecutionRequests) Create a newAiMessagewith the given text and tool execution requests.static AiMessagefrom(List<ToolExecutionRequest> toolExecutionRequests) Create a newAiMessagewith the given tool execution requests.inthashCode()booleanCheck if the message hasToolExecutionRequests.text()Get the text of the message.thinking()Get the thinking/reasoning text of the message.Get the tool execution requests of the message.toString()type()The type of the message.Create a clone of thisAiMessagewith the given text.
-
Constructor Details
-
AiMessage
-
AiMessage
Create a newAiMessagewith the given tool execution requests.- Parameters:
toolExecutionRequests- the tool execution requests of the message.
-
AiMessage
Create a newAiMessagewith the given text and tool execution requests.- Parameters:
text- the text of the message.toolExecutionRequests- the tool execution requests of the message.
-
AiMessage
- Since:
- 1.2.0
-
-
Method Details
-
withText
-
text
-
thinking
Get the thinking/reasoning text of the message.- Returns:
- the thinking/reasoning text of the message.
- Since:
- 1.2.0
-
toolExecutionRequests
Get the tool execution requests of the message.- Returns:
- the tool execution requests of the message.
-
hasToolExecutionRequests
public boolean hasToolExecutionRequests()Check if the message hasToolExecutionRequests.- Returns:
- true if the message has
ToolExecutionRequests, false otherwise.
-
attributes
Returns additional attributes, typically provider-specific.- Since:
- 1.2.0
- See Also:
-
attribute
Returns additional attribute by it's key.- Since:
- 1.2.0
- See Also:
-
type
Description copied from interface:ChatMessageThe type of the message.- Specified by:
typein interfaceChatMessage- Returns:
- the type of the message
-
equals
-
hashCode
-
toString
-
builder
-
from
-
from
-
from
-
from
-
aiMessage
-
aiMessage
-
aiMessage
-
aiMessage
-