Class LoggingPlugin
java.lang.Object
com.google.adk.plugins.BasePlugin
com.google.adk.plugins.LoggingPlugin
A plugin that logs important information at each callback point.
This plugin helps printing all critical events in the console.
-
Field Summary
Fields inherited from class com.google.adk.plugins.BasePlugin
name -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionio.reactivex.rxjava3.core.Maybe<com.google.genai.types.Content> afterAgentCallback(BaseAgent agent, CallbackContext callbackContext) Callback executed after an agent's primary logic has completed.io.reactivex.rxjava3.core.Maybe<LlmResponse> afterModelCallback(CallbackContext callbackContext, LlmResponse llmResponse) Callback executed after a response is received from the model.io.reactivex.rxjava3.core.CompletableafterRunCallback(InvocationContext invocationContext) Callback executed after an ADK runner run has completed.afterToolCallback(BaseTool tool, Map<String, Object> toolArgs, ToolContext toolContext, Map<String, Object> result) Callback executed after a tool has been called.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.io.reactivex.rxjava3.core.Maybe<LlmResponse> beforeModelCallback(CallbackContext callbackContext, LlmRequest llmRequest) Callback executed before a request is sent to the model.io.reactivex.rxjava3.core.Maybe<com.google.genai.types.Content> beforeRunCallback(InvocationContext invocationContext) Callback executed before the ADK runner runs.beforeToolCallback(BaseTool tool, Map<String, Object> toolArgs, ToolContext toolContext) Callback executed before a tool is called.io.reactivex.rxjava3.core.Maybe<Event> onEventCallback(InvocationContext invocationContext, Event event) Callback executed after an event is yielded from runner.io.reactivex.rxjava3.core.Maybe<LlmResponse> onModelErrorCallback(CallbackContext callbackContext, LlmRequest llmRequest, Throwable error) Callback executed when a model call encounters an error.onToolErrorCallback(BaseTool tool, Map<String, Object> toolArgs, ToolContext toolContext, Throwable error) Callback executed when a tool call encounters an error.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.Methods inherited from class com.google.adk.plugins.BasePlugin
getName
-
Constructor Details
-
LoggingPlugin
-
LoggingPlugin
public LoggingPlugin()
-
-
Method Details
-
onUserMessageCallback
public io.reactivex.rxjava3.core.Maybe<com.google.genai.types.Content> onUserMessageCallback(InvocationContext invocationContext, com.google.genai.types.Content userMessage) Description copied from class:BasePluginCallback executed when a user message is received before an invocation starts.- Overrides:
onUserMessageCallbackin classBasePlugin- Parameters:
invocationContext- The context for the entire invocation.userMessage- The message content input by user.- Returns:
- An optional Content to replace the user message. Returning Empty to proceed normally.
-
beforeRunCallback
public io.reactivex.rxjava3.core.Maybe<com.google.genai.types.Content> beforeRunCallback(InvocationContext invocationContext) Description copied from class:BasePluginCallback executed before the ADK runner runs.- Overrides:
beforeRunCallbackin classBasePlugin- Parameters:
invocationContext- The context for the entire invocation.- Returns:
- An optional Content to halt execution. Returning Empty to proceed normally.
-
onEventCallback
public io.reactivex.rxjava3.core.Maybe<Event> onEventCallback(InvocationContext invocationContext, Event event) Description copied from class:BasePluginCallback executed after an event is yielded from runner.- Overrides:
onEventCallbackin classBasePlugin- Parameters:
invocationContext- The context for the entire invocation.event- The event raised by the runner.- Returns:
- An optional Event to modify or replace the response. Returning Empty to proceed normally.
-
afterRunCallback
Description copied from class:BasePluginCallback executed after an ADK runner run has completed.- Overrides:
afterRunCallbackin classBasePlugin- Parameters:
invocationContext- The context for the entire invocation.
-
beforeAgentCallback
public io.reactivex.rxjava3.core.Maybe<com.google.genai.types.Content> beforeAgentCallback(BaseAgent agent, CallbackContext callbackContext) Description copied from class:BasePluginCallback executed before an agent's primary logic is invoked.- Overrides:
beforeAgentCallbackin classBasePlugin- Parameters:
agent- The agent that is about to run.callbackContext- The context for the agent invocation.- Returns:
- An optional Content object to bypass the agent's execution. Returning Empty to proceed normally.
-
afterAgentCallback
public io.reactivex.rxjava3.core.Maybe<com.google.genai.types.Content> afterAgentCallback(BaseAgent agent, CallbackContext callbackContext) Description copied from class:BasePluginCallback executed after an agent's primary logic has completed.- Overrides:
afterAgentCallbackin classBasePlugin- Parameters:
agent- The agent that has just run.callbackContext- The context for the agent invocation.- Returns:
- An optional Content object to replace the agent's original result. Returning Empty to use the original result.
-
beforeModelCallback
public io.reactivex.rxjava3.core.Maybe<LlmResponse> beforeModelCallback(CallbackContext callbackContext, LlmRequest llmRequest) Description copied from class:BasePluginCallback executed before a request is sent to the model.- Overrides:
beforeModelCallbackin classBasePlugin- Parameters:
callbackContext- The context for the current agent call.llmRequest- The prepared request object to be sent to the model.- Returns:
- An optional LlmResponse to trigger an early exit. Returning Empty to proceed normally.
-
afterModelCallback
public io.reactivex.rxjava3.core.Maybe<LlmResponse> afterModelCallback(CallbackContext callbackContext, LlmResponse llmResponse) Description copied from class:BasePluginCallback executed after a response is received from the model.- Overrides:
afterModelCallbackin classBasePlugin- Parameters:
callbackContext- The context for the current agent call.llmResponse- The response object received from the model.- Returns:
- An optional LlmResponse to modify or replace the response. Returning Empty to use the original response.
-
onModelErrorCallback
public io.reactivex.rxjava3.core.Maybe<LlmResponse> onModelErrorCallback(CallbackContext callbackContext, LlmRequest llmRequest, Throwable error) Description copied from class:BasePluginCallback executed when a model call encounters an error.- Overrides:
onModelErrorCallbackin classBasePlugin- Parameters:
callbackContext- The context for the current agent call.llmRequest- The request that was sent to the model.error- The exception that was raised.- Returns:
- An optional LlmResponse to use instead of propagating the error. Returning Empty to allow the original error to be raised.
-
beforeToolCallback
public io.reactivex.rxjava3.core.Maybe<Map<String,Object>> beforeToolCallback(BaseTool tool, Map<String, Object> toolArgs, ToolContext toolContext) Description copied from class:BasePluginCallback executed before a tool is called.- Overrides:
beforeToolCallbackin classBasePlugin- Parameters:
tool- The tool instance that is about to be executed.toolArgs- The dictionary of arguments to be used for invoking the tool.toolContext- The context specific to the tool execution.- Returns:
- An optional Map to stop the tool execution and return this response immediately. Returning Empty to proceed normally.
-
afterToolCallback
public io.reactivex.rxjava3.core.Maybe<Map<String,Object>> afterToolCallback(BaseTool tool, Map<String, Object> toolArgs, ToolContext toolContext, Map<String, Object> result) Description copied from class:BasePluginCallback executed after a tool has been called.- Overrides:
afterToolCallbackin classBasePlugin- Parameters:
tool- The tool instance that has just been executed.toolArgs- The original arguments that were passed to the tool.toolContext- The context specific to the tool execution.result- The dictionary returned by the tool invocation.- Returns:
- An optional Map to replace the original result from the tool. Returning Empty to use the original result.
-
onToolErrorCallback
public io.reactivex.rxjava3.core.Maybe<Map<String,Object>> onToolErrorCallback(BaseTool tool, Map<String, Object> toolArgs, ToolContext toolContext, Throwable error) Description copied from class:BasePluginCallback executed when a tool call encounters an error.- Overrides:
onToolErrorCallbackin classBasePlugin- Parameters:
tool- The tool instance that encountered an error.toolArgs- The arguments that were passed to the tool.toolContext- The context specific to the tool execution.error- The exception that was raised during tool execution.- Returns:
- An optional Map to be used as the tool response instead of propagating the error. Returning Empty to allow the original error to be raised.
-