Class ContextPlacement

java.lang.Object
com.axelor.ai.chat.plugin.ContextPlacement

public final class ContextPlacement extends Object
Places per-turn context beside the message it serves, not at the top of the prompt.

Two reasons. The model reads context best next to the question it answers; and a provider's prompt cache reuses the longest unchanged prefix, so anything that changes each turn placed before the history makes the whole history uncacheable. Placed at the latest user message, it only costs the turn it belongs to.

  • Method Details

    • latestUserIndex

      public static int latestUserIndex(List<UIMessage> messages)
      The index of the latest user message, or -1 when there is none.
    • appendToLatestUser

      public static List<UIMessage> appendToLatestUser(List<UIMessage> messages, String text)
      Adds text as a trailing part of the latest user message.
    • insertBeforeLatestUser

      public static List<UIMessage> insertBeforeLatestUser(List<UIMessage> messages, UIMessage context)
      Inserts context just before the latest user message, or last when there is none.