# Class BasePlugin

java.lang.Object
com.google.adk.plugins.BasePlugin

All Implemented Interfaces:
  `Plugin`

Direct Known Subclasses:
  `BigQueryAgentAnalyticsPlugin, ContextFilterPlugin, GlobalInstructionPlugin, LoggingPlugin, PluginManager, ReplayPlugin`

public abstract class BasePlugin extends Object implements Plugin
Base class for creating plugins.

Plugins provide a structured way to intercept and modify agent, tool, and LLM behaviors at critical execution points in a callback manner. While agent callbacks apply to a particular agent, plugins applies globally to all agents added in the runner. Plugins are best used for adding custom behaviors like logging, monitoring, caching, or modifying requests and responses at key stages.

A plugin can implement one or more methods of callbacks, but should not implement the same method of callback for multiple times.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected final String`
  `name`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `BasePlugin(String name)`
  Constructs a new plugin with the given name.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `String`
  `getName()`

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface Plugin

  `afterAgentCallback, afterModelCallback, afterRunCallback, afterToolCallback, beforeAgentCallback, beforeModelCallback, beforeRunCallback, beforeToolCallback, close, onEventCallback, onModelErrorCallback, onToolErrorCallback, onUserMessageCallback`
  Modifier and Type
  Method
  Description
  `default io.reactivex.rxjava3.core.Maybe<com.google.genai.types.Content>`
  `afterAgentCallback(BaseAgent agent, CallbackContext callbackContext)`
  Callback executed after an agent's primary logic has completed.
  `default io.reactivex.rxjava3.core.Maybe<LlmResponse>`
  `afterModelCallback(CallbackContext callbackContext, LlmResponse llmResponse)`
  Callback executed after a response is received from the model.
  `default io.reactivex.rxjava3.core.Completable`
  `afterRunCallback(InvocationContext invocationContext)`
  Callback executed after an ADK runner run has completed.
  `default io.reactivex.rxjava3.core.Maybe<Map<String,Object>>`
  `afterToolCallback(BaseTool tool, Map<String,Object> toolArgs, ToolContext toolContext, Map<String,Object> result)`
  Callback executed after a tool has been called.
  `default io.reactivex.rxjava3.core.Maybe<com.google.genai.types.Content>`
  `beforeAgentCallback(BaseAgent agent, CallbackContext callbackContext)`
  Callback executed before an agent's primary logic is invoked.
  `default io.reactivex.rxjava3.core.Maybe<LlmResponse>`
  `beforeModelCallback(CallbackContext callbackContext, LlmRequest.Builder llmRequest)`
  Callback executed before a request is sent to the model.
  `default io.reactivex.rxjava3.core.Maybe<com.google.genai.types.Content>`
  `beforeRunCallback(InvocationContext invocationContext)`
  Callback executed before the ADK runner runs.
  `default io.reactivex.rxjava3.core.Maybe<Map<String,Object>>`
  `beforeToolCallback(BaseTool tool, Map<String,Object> toolArgs, ToolContext toolContext)`
  Callback executed before a tool is called.
  `default io.reactivex.rxjava3.core.Completable`
  `close()`
  Method executed when the runner is closed.
  `default io.reactivex.rxjava3.core.Maybe<Event>`
  `onEventCallback(InvocationContext invocationContext, Event event)`
  Callback executed after an event is yielded from runner.
  `default io.reactivex.rxjava3.core.Maybe<LlmResponse>`
  `onModelErrorCallback(CallbackContext callbackContext, LlmRequest.Builder llmRequest, Throwable error)`
  Callback executed when a model call encounters an error.
  `default io.reactivex.rxjava3.core.Maybe<Map<String,Object>>`
  `onToolErrorCallback(BaseTool tool, Map<String,Object> toolArgs, ToolContext toolContext, Throwable error)`
  Callback executed when a tool call encounters an error.
  `default io.reactivex.rxjava3.core.Maybe<com.google.genai.types.Content>`
  `onUserMessageCallback(InvocationContext invocationContext, com.google.genai.types.Content userMessage)`
  Callback executed when a user message is received before an invocation starts.

- ## Field Details

  - ### name

    protected final String name

- ## Constructor Details

  - ### BasePlugin

    public BasePlugin(String name)
    Constructs a new plugin with the given name.
    Parameters:
      `name` - The name of the plugin.

- ## Method Details

  - ### getName

    public String getName()
    Specified by:
      `getName` in interface `Plugin`