public static class AIGuard.Message extends Object
Messages can contain either plain text content or structured content parts (text and images):
Example usage:
// User prompt with text
var userPrompt = AIGuard.Message.message("user", "What's the weather like?");
// User prompt with text and image
var multimodalPrompt = AIGuard.Message.message("user", List.of(
AIGuard.ContentPart.text("Describe this image:"),
AIGuard.ContentPart.imageUrl("https://example.com/image.jpg")
));
// Assistant response with tool calls
var assistantWithTools = AIGuard.Message.assistant(
AIGuard.ToolCall.toolCall("call_123", "get_weather", "{\"location\": \"New York\"}")
);
// Tool response
var toolResponse = AIGuard.Message.tool("call_123", "Sunny, 75°F");
| Constructor and Description |
|---|
Message(String role,
List<AIGuard.ContentPart> contentParts,
List<AIGuard.ToolCall> toolCalls,
String toolCallId)
Creates a new message with content parts (text and/or images).
|
Message(String role,
String content,
List<AIGuard.ToolCall> toolCalls,
String toolCallId)
Creates a new message with the specified parameters.
|
| Modifier and Type | Method and Description |
|---|---|
static AIGuard.Message |
assistant(AIGuard.ToolCall... toolCalls)
Creates an assistant message with tool calls but no text content.
|
String |
getContent()
Returns the text content of the message.
|
List<AIGuard.ContentPart> |
getContentParts()
Returns the content parts of the message.
|
String |
getRole()
Returns the role of the message sender.
|
String |
getToolCallId()
Returns the tool call ID that this message is responding to.
|
List<AIGuard.ToolCall> |
getToolCalls()
Returns the list of tool calls associated with this message.
|
static AIGuard.Message |
message(String role,
List<AIGuard.ContentPart> contentParts)
Creates a message with specified role and content parts (text and/or images).
|
static AIGuard.Message |
message(String role,
String content)
Creates a message with specified role and text content.
|
static AIGuard.Message |
tool(String toolCallId,
String content)
Creates a tool response message.
|
public Message(@Nonnull String role, @Nullable String content, @Nullable List<AIGuard.ToolCall> toolCalls, @Nullable String toolCallId)
role - the role of the message sender (e.g., "user", "assistant", "system", "tool")content - the text content of the message, or null for assistant messages with only tool
callstoolCalls - list of tool calls associated with this message, or null if no tool callstoolCallId - the tool call ID this message is responding to, or null if not a tool
responsepublic Message(@Nonnull String role, @Nonnull List<AIGuard.ContentPart> contentParts, @Nullable List<AIGuard.ToolCall> toolCalls, @Nullable String toolCallId)
role - the role of the message sendercontentParts - list of content partstoolCalls - list of tool calls, or nulltoolCallId - the tool call ID this message responds to, or nullIllegalArgumentException - if contentParts contains null elementspublic String getRole()
@Nullable public String getContent()
@Nullable public List<AIGuard.ContentPart> getContentParts()
public List<AIGuard.ToolCall> getToolCalls()
public String getToolCallId()
@Nonnull public static AIGuard.Message message(@Nonnull String role, @Nonnull String content)
role - the role of the message sender (e.g., "user", "system")content - the text content of the message@Nonnull public static AIGuard.Message message(@Nonnull String role, @Nonnull List<AIGuard.ContentPart> contentParts)
role - the role of the message sender (e.g., "user", "system")contentParts - list of content parts (text and/or images)public static AIGuard.Message tool(String toolCallId, String content)
toolCallId - the ID of the tool call this message is responding tocontent - the result or output from the tool execution@Nonnull public static AIGuard.Message assistant(@Nonnull AIGuard.ToolCall... toolCalls)
toolCalls - the tool calls the assistant wants to make