Package dev.langchain4j.data.message
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 newAiMessage
with the given text.AiMessage
(String text, List<ToolExecutionRequest> toolExecutionRequests) Create a newAiMessage
with the given text and tool execution requests.AiMessage
(List<ToolExecutionRequest> toolExecutionRequests) Create a newAiMessage
with the given tool execution requests. -
Method Summary
Modifier and TypeMethodDescriptionstatic AiMessage
aiMessage
(ToolExecutionRequest... toolExecutionRequests) Create a newAiMessage
with the given tool execution requests.static AiMessage
Create a newAiMessage
with the given text.static AiMessage
aiMessage
(String text, List<ToolExecutionRequest> toolExecutionRequests) Create a newAiMessage
with the given text and tool execution requests.static AiMessage
aiMessage
(List<ToolExecutionRequest> toolExecutionRequests) Create a newAiMessage
with the given tool execution requests.<T> T
Returns additional attribute by it's key.Returns additional attributes, typically provider-specific.static AiMessage.Builder
builder()
boolean
static AiMessage
from
(ToolExecutionRequest... toolExecutionRequests) Create a newAiMessage
with the given tool execution requests.static AiMessage
Create a newAiMessage
with the given text.static AiMessage
from
(String text, List<ToolExecutionRequest> toolExecutionRequests) Create a newAiMessage
with the given text and tool execution requests.static AiMessage
from
(List<ToolExecutionRequest> toolExecutionRequests) Create a newAiMessage
with the given tool execution requests.int
hashCode()
boolean
Check if the message hasToolExecutionRequest
s.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.
-
Constructor Details
-
AiMessage
Create a newAiMessage
with the given text.- Parameters:
text
- the text of the message.
-
AiMessage
Create a newAiMessage
with the given tool execution requests.- Parameters:
toolExecutionRequests
- the tool execution requests of the message.
-
AiMessage
Create a newAiMessage
with 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
-
text
Get the text of the message.- Returns:
- the text of the message.
-
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 hasToolExecutionRequest
s.- Returns:
- true if the message has
ToolExecutionRequest
s, 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:ChatMessage
The type of the message.- Specified by:
type
in interfaceChatMessage
- Returns:
- the type of the message
-
equals
-
hashCode
public int hashCode() -
toString
-
builder
-
from
Create a newAiMessage
with the given text.- Parameters:
text
- the text of the message.- Returns:
- the new
AiMessage
.
-
from
Create a newAiMessage
with the given tool execution requests.- Parameters:
toolExecutionRequests
- the tool execution requests of the message.- Returns:
- the new
AiMessage
.
-
from
Create a newAiMessage
with the given tool execution requests.- Parameters:
toolExecutionRequests
- the tool execution requests of the message.- Returns:
- the new
AiMessage
.
-
from
Create a newAiMessage
with the given text and tool execution requests.- Parameters:
text
- the text of the message.toolExecutionRequests
- the tool execution requests of the message.- Returns:
- the new
AiMessage
.
-
aiMessage
Create a newAiMessage
with the given text.- Parameters:
text
- the text of the message.- Returns:
- the new
AiMessage
.
-
aiMessage
Create a newAiMessage
with the given tool execution requests.- Parameters:
toolExecutionRequests
- the tool execution requests of the message.- Returns:
- the new
AiMessage
.
-
aiMessage
Create a newAiMessage
with the given tool execution requests.- Parameters:
toolExecutionRequests
- the tool execution requests of the message.- Returns:
- the new
AiMessage
.
-
aiMessage
Create a newAiMessage
with the given text and tool execution requests.- Parameters:
text
- the text of the message.toolExecutionRequests
- the tool execution requests of the message.- Returns:
- the new
AiMessage
.
-