Class ContextWindowPlugin

java.lang.Object
com.axelor.ai.chat.plugin.ContextWindowPlugin
All Implemented Interfaces:
ChatPlugin

@Singleton public class ContextWindowPlugin extends Object implements ChatPlugin
Manages the LLM context window by transparently trimming message history when it exceeds the model's input token limit. Uses a hybrid approach: older messages are summarized by the LLM, and a sliding window of recent messages is preserved intact.

Priority 40 makes this the outermost decorator. It intercepts the raw conversation messages before prompt enhancements are applied — system prompt (AgentResolverPlugin), RAG context (KnowledgePlugin), and skill context (SkillPlugin) are injected by inner decorators after trimming. The budget is computed dynamically by querying each plugin's ChatPlugin.estimateInjectedTokens(com.axelor.ai.chat.ChatRequest) to reserve accurate headroom for those injections.

A singleton: what it learns outlives a request — each model's calibration, each chat's summarization failures — while the streamer, and the plugin set with it, is built per request.