Class BedrockSystemTextContent

java.lang.Object
dev.langchain4j.model.bedrock.BedrockSystemTextContent
All Implemented Interfaces:
BedrockSystemContent

public final class BedrockSystemTextContent extends Object implements BedrockSystemContent
Text content block for BedrockSystemMessage with optional cache point.

Example usage:

// Without cache point
BedrockSystemTextContent.from("Instructions");

// With cache point (content will be cached)
BedrockSystemTextContent.withCachePoint("Large static context");

AWS Bedrock Caching Requirements:

  • Minimum ~1,024 tokens required for caching to activate
  • Cache has 5-minute TTL (resets on each hit)
  • Only Claude 3.x and Amazon Nova models support caching
  • Maximum 4 cache points per request (see BedrockSystemMessage.MAX_CACHE_POINTS)

Thread Safety: Instances of this class are immutable and thread-safe.

Since:
1.11.0
See Also:
  • Field Details

    • MAX_TEXT_LENGTH

      public static final int MAX_TEXT_LENGTH
      Maximum allowed text length (1MB) to prevent resource exhaustion.
      See Also:
  • Constructor Details

    • BedrockSystemTextContent

      public BedrockSystemTextContent(String text, boolean cachePoint)
      Creates text content with optional cache point.
      Parameters:
      text - the text content (must not be blank, max 1MB)
      cachePoint - whether to add a cache point after this content
      Throws:
      IllegalArgumentException - if text is null, blank, or exceeds max length
    • BedrockSystemTextContent

      public BedrockSystemTextContent(String text)
      Creates text content without cache point.
      Parameters:
      text - the text content (must not be blank)
  • Method Details

    • text

      public String text()
      Returns the text content.
      Returns:
      the text
    • hasCachePoint

      public boolean hasCachePoint()
      Description copied from interface: BedrockSystemContent
      Returns whether this content block has a cache point marker. When true, a cache point will be inserted AFTER this content block in the AWS Bedrock request.
      Specified by:
      hasCachePoint in interface BedrockSystemContent
      Returns:
      true if this content has a cache point
    • type

      public BedrockSystemContentType type()
      Description copied from interface: BedrockSystemContent
      Returns the content type.
      Specified by:
      type in interface BedrockSystemContent
      Returns:
      the content type enum value
    • from

      public static BedrockSystemTextContent from(String text)
      Creates text content without cache point.
      Parameters:
      text - the text content
      Returns:
      new BedrockSystemTextContent
    • withCachePoint

      public static BedrockSystemTextContent withCachePoint(String text)
      Creates text content WITH cache point marker. A cache point will be inserted after this content in the Bedrock request.

      Note: For caching to activate, content should be at least ~1,024 tokens.

      Parameters:
      text - the text content
      Returns:
      new BedrockSystemTextContent with cache point
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object