Package com.axelor.ai.chat
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 Summary
Modifier and TypeMethodDescriptiondefault ChatProviderdecorateProvider(ChatRequest request, ChatProvider provider) Wraps the provider to intercept or enrich LLM calls (e.g.default ToolExecutordecorateToolExecutor(ChatRequest request, ToolExecutor executor) Wraps the tool executor to intercept tool calls (e.g.default StreamWriterdecorateWriter(ChatRequest request, StreamWriter writer) Wraps the stream writer to intercept events (e.g.default intestimateInjectedTokens(ChatRequest request) Estimates the number of tokens this plugin will inject into the message list duringdecorateProvider(com.axelor.ai.chat.ChatRequest, com.axelor.ai.chat.ChatProvider).default voidonComplete(ChatRequest request) Called after the loop completes successfully.default voidonError(ChatRequest request, Exception error) Called when the loop fails with an exception.default voidonMessage(ChatRequest request, UIMessage message) Called for each new message created during the loop (assistant, tool).default ChatRequestonRequest(ChatRequest request) Called before the loop starts.default intpriority()Execution priority.
-
Method Details
-
priority
default int priority()Execution priority. Lower values run first. Default is 100. -
onRequest
Called before the loop starts. May inspect or transform the request (e.g. resolve agent config, check rate limits). -
estimateInjectedTokens
Estimates the number of tokens this plugin will inject into the message list duringdecorateProvider(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
Wraps the provider to intercept or enrich LLM calls (e.g. RAG, system prompt injection). -
decorateToolExecutor
Wraps the tool executor to intercept tool calls (e.g. authorization, logging). -
decorateWriter
Wraps the stream writer to intercept events (e.g. persistence, metrics). -
onMessage
Called for each new message created during the loop (assistant, tool). -
onComplete
Called after the loop completes successfully. -
onError
Called when the loop fails with an exception.
-