Class AIGuard.Message

java.lang.Object
datadog.trace.api.aiguard.AIGuard.Message
Enclosing class:
AIGuard

public static class AIGuard.Message extends Object
Represents a message in an AI conversation. Messages can represent user prompts, assistant responses, system messages, or tool outputs.

Example usage:


 // User prompt
 var userPrompt = AIGuard.Message.message("user", "What's the weather like?");

 // 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 Details

    • Message

      public Message(String role, String content, List<AIGuard.ToolCall> toolCalls, 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 calls
      toolCalls - list of tool calls associated with this message, or null if no tool calls
      toolCallId - the tool call ID this message is responding to, or null if not a tool response
  • Method Details

    • getRole

      public String getRole()
      Returns the role of the message sender.
      Returns:
      the role (e.g., "user", "assistant", "system", "tool")
    • getContent

      public String getContent()
      Returns the text content of the message.
      Returns:
      the message content, or null for assistant messages with only tool calls
    • getToolCalls

      public List<AIGuard.ToolCall> 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

      public String 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

      public static AIGuard.Message message(String role, String content)
      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
    • tool

      public static AIGuard.Message tool(String toolCallId, String content)
      Creates a tool response message.
      Parameters:
      toolCallId - the ID of the tool call this message is responding to
      content - the result or output from the tool execution
      Returns:
      a new Message instance with role "tool"
    • assistant

      public static AIGuard.Message assistant(AIGuard.ToolCall... toolCalls)
      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