Package datadog.trace.api.aiguard
Class AIGuard.Message
java.lang.Object
datadog.trace.api.aiguard.AIGuard.Message
- Enclosing class:
AIGuard
Represents a message in an AI conversation. Messages can represent user prompts, assistant
responses, system messages, or tool outputs.
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 Summary
ConstructorsConstructorDescriptionCreates a new message with the specified parameters.Message(String role, List<AIGuard.ContentPart> contentParts, List<AIGuard.ToolCall> toolCalls, String toolCallId) Creates a new message with content parts (text and/or images). -
Method Summary
Modifier and TypeMethodDescriptionstatic AIGuard.Messageassistant(AIGuard.ToolCall... toolCalls) Creates an assistant message with tool calls but no text content.Returns the text content of the message.Returns the content parts of the message.getRole()Returns the role of the message sender.Returns the tool call ID that this message is responding to.Returns the list of tool calls associated with this message.static AIGuard.MessageCreates a message with specified role and text content.static AIGuard.Messagemessage(String role, List<AIGuard.ContentPart> contentParts) Creates a message with specified role and content parts (text and/or images).static AIGuard.MessageCreates a tool response message.
-
Constructor Details
-
Message
public Message(@Nonnull String role, @Nullable String content, @Nullable List<AIGuard.ToolCall> toolCalls, @Nullable String toolCallId) Creates a new message with the specified parameters.- Parameters:
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 response
-
Message
public Message(@Nonnull String role, @Nonnull List<AIGuard.ContentPart> contentParts, @Nullable List<AIGuard.ToolCall> toolCalls, @Nullable String toolCallId) Creates a new message with content parts (text and/or images).- Parameters:
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 null- Throws:
IllegalArgumentException- if contentParts contains null elements
-
-
Method Details
-
getRole
Returns the role of the message sender.- Returns:
- the role (e.g., "user", "assistant", "system", "tool")
-
getContent
Returns the text content of the message.- Returns:
- the message content, or null if using content parts or for assistant messages with only tool calls
-
getContentParts
Returns the content parts of the message.- Returns:
- the content parts (text and images), or null if using plain text content
-
getToolCalls
Returns the list of tool calls associated with this message.- Returns:
- list of tool calls, or null if this message has no tool calls
-
getToolCallId
Returns the tool call ID that this message is responding to.- Returns:
- the tool call ID, or null if this is not a tool response message
-
message
Creates a message with specified role and text content.- Parameters:
role- the role of the message sender (e.g., "user", "system")content- the text content of the message- Returns:
- a new Message instance
-
message
@Nonnull public static AIGuard.Message message(@Nonnull String role, @Nonnull List<AIGuard.ContentPart> contentParts) Creates a message with specified role and content parts (text and/or images).- Parameters:
role- the role of the message sender (e.g., "user", "system")contentParts- list of content parts (text and/or images)- Returns:
- a new Message instance
-
tool
Creates a tool response message.- Parameters:
toolCallId- the ID of the tool call this message is responding tocontent- the result or output from the tool execution- Returns:
- a new Message instance with role "tool"
-
assistant
Creates an assistant message with tool calls but no text content.- Parameters:
toolCalls- the tool calls the assistant wants to make- Returns:
- a new Message instance with role "assistant" and no text content
-