Interface ChatPlugin

All Known Implementing Classes:
AgentResolverPlugin, ContextWindowPlugin, FieldContextPlugin, InputGuardPlugin, MentionContextPlugin, RiskScreenPlugin, SessionNotesPlugin, SkillPlugin, SubjectPlugin, TitleGeneratorPlugin, ToolExecutorPlugin

public interface ChatPlugin
Extension point for the chat loop. Plugins decorate the core dependencies (provider, tool executor, stream writer) on a per-request basis and receive lifecycle callbacks for completion and errors.

Each method has a no-op default so plugins override only what they need. Plugins are applied in registration order; decoration stacks so that the last plugin's decorator wraps all previous ones.

  • Method Details

    • priority

      default int priority()
      Execution priority. Lower values run first. Default is 100.
    • onRequest

      default ChatRequest onRequest(ChatRequest request)
      Called before the loop starts. May inspect or transform the request (e.g. resolve agent config, check rate limits).
    • estimateInjectedTokens

      default int estimateInjectedTokens(ChatRequest request)
      Estimates the number of tokens this plugin will inject into the message list during decorateProvider(com.axelor.ai.chat.ChatRequest, com.axelor.ai.chat.ChatProvider). Used by the context window plugin to compute an accurate budget that accounts for system prompts, RAG context, skill content, etc.

      Implementations should return a conservative (high) estimate. Return 0 if this plugin does not inject content.

    • decorateProvider

      default ChatProvider decorateProvider(ChatRequest request, ChatProvider provider)
      Wraps the provider to intercept or enrich LLM calls (e.g. RAG, system prompt injection).
    • decorateToolExecutor

      default ToolExecutor decorateToolExecutor(ChatRequest request, ToolExecutor executor)
      Wraps the tool executor to intercept tool calls (e.g. authorization, logging).
    • decorateWriter

      default StreamWriter decorateWriter(ChatRequest request, StreamWriter writer)
      Wraps the stream writer to intercept events (e.g. persistence, metrics).
    • onMessage

      default void onMessage(ChatRequest request, UIMessage message)
      Called for each new message created during the loop (assistant, tool).
    • onComplete

      default void onComplete(ChatRequest request)
      Called after the loop completes successfully.
    • onError

      default void onError(ChatRequest request, Exception error)
      Called when the loop fails with an exception.