Package com.axelor.ai.chat.plugin
Class ContextWindowPlugin
java.lang.Object
com.axelor.ai.chat.plugin.ContextWindowPlugin
- All Implemented Interfaces:
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.
-
Method Summary
Modifier and TypeMethodDescriptiondecorateProvider(ChatRequest request, ChatProvider provider) Wraps the provider to intercept or enrich LLM calls (e.g.decorateWriter(ChatRequest request, StreamWriter writer) Wraps the stream writer to intercept events (e.g.voidonComplete(ChatRequest request) Called after the loop completes successfully.voidonError(ChatRequest request, Exception error) Called when the loop fails with an exception.intpriority()Execution priority.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.axelor.ai.chat.ChatPlugin
decorateToolExecutor, estimateInjectedTokens, onMessage, onRequest
-
Method Details
-
priority
public int priority()Description copied from interface:ChatPluginExecution priority. Lower values run first. Default is 100.- Specified by:
priorityin interfaceChatPlugin
-
decorateWriter
Description copied from interface:ChatPluginWraps the stream writer to intercept events (e.g. persistence, metrics).- Specified by:
decorateWriterin interfaceChatPlugin
-
onComplete
Description copied from interface:ChatPluginCalled after the loop completes successfully.- Specified by:
onCompletein interfaceChatPlugin
-
onError
Description copied from interface:ChatPluginCalled when the loop fails with an exception.- Specified by:
onErrorin interfaceChatPlugin
-
decorateProvider
Description copied from interface:ChatPluginWraps the provider to intercept or enrich LLM calls (e.g. RAG, system prompt injection).- Specified by:
decorateProviderin interfaceChatPlugin
-