ReflectAndRetryToolPlugin

class ReflectAndRetryToolPlugin(val maxRetries: Int = 3, val throwExceptionIfRetryExceeded: Boolean = true, val trackingScope: ReflectAndRetryToolPlugin.TrackingScope = TrackingScope.INVOCATION, val resultErrorExtractor: ReflectAndRetryToolPlugin.ResultErrorExtractor? = null, val retryPredicate: ReflectAndRetryToolPlugin.RetryPredicate? = null, val name: String = DEFAULT_NAME) : Plugin

Answers a failed tool call with guidance for the model to reflect on the error and retry, allowing up to maxRetries consecutive failures per tool.

A failure is an exception from the tool, a call to an unregistered tool name, or an error that resultErrorExtractor finds in a result; a success resets that tool's count. Mirrors Python ADK's ReflectAndRetryToolPlugin.

InMemoryRunner(agent = agent, plugins = listOf(ReflectAndRetryToolPlugin(maxRetries = 3)))

Constructors

Link copied to clipboard
constructor(maxRetries: Int = 3, throwExceptionIfRetryExceeded: Boolean = true, trackingScope: ReflectAndRetryToolPlugin.TrackingScope = TrackingScope.INVOCATION, resultErrorExtractor: ReflectAndRetryToolPlugin.ResultErrorExtractor? = null, retryPredicate: ReflectAndRetryToolPlugin.RetryPredicate? = null, name: String = DEFAULT_NAME)

Types

Link copied to clipboard
class Builder

Fluent builder for ReflectAndRetryToolPlugin, provided primarily for Java callers. Any property left unset falls back to the same default as the constructor.

Link copied to clipboard
object Companion
Link copied to clipboard

Finds an error that a tool reported in its result instead of throwing.

Link copied to clipboard

Decides whether the model may retry a failed tool call.

Link copied to clipboard

How long ReflectAndRetryToolPlugin keeps counting a tool's consecutive failures.

Properties

Link copied to clipboard

The number of consecutive failures of one tool that are answered with retry guidance; the failure after that exceeds the limit. Must not be negative; 0 disables retries.

Link copied to clipboard
open override val name: String

The unique name of the plugin instance.

Link copied to clipboard

Finds errors that tools report in their results instead of throwing; when null, no result counts as a failure.

Link copied to clipboard

Decides which failures the model may retry. A failure it rejects is not counted and is answered at once with the guidance to stop using the tool, never by throwing; when null, every failure may be retried.

Link copied to clipboard

Once the limit is exceeded, whether to stop handling the error or to answer with guidance telling the model to stop using the tool. When set, a thrown error is left to the flow as if the plugin were absent, and an error found in a result is thrown.

Link copied to clipboard

Whether a tool's failures are counted per invocation or across them.

Functions

Link copied to clipboard
open suspend fun afterAgent(context: CallbackContext): CallbackChoice<Unit, Content>

Callback executed after a specific agent finishes its processing.

Link copied to clipboard
open suspend fun afterModel(context: CallbackContext, response: LlmResponse): LlmResponse

Callback executed after an LLM response is received.

Link copied to clipboard
open suspend override fun afterRun(invocationContext: InvocationContext)

Callback executed after the ADK runner completes its execution.

Link copied to clipboard
open suspend override fun afterTool(context: ToolContext, tool: BaseTool, args: Map<String, Any?>, result: Map<String, Any?>): Map<String, Any?>

Callback executed after a tool runs, or after a before-tool callback answers the call in its place.

Link copied to clipboard

Callback executed before a specific agent starts processing.

Link copied to clipboard

Callback executed before an LLM request is sent.

Link copied to clipboard
open suspend fun beforeRun(invocationContext: InvocationContext): CallbackChoice<Unit, Content>

Callback executed before the ADK runner starts the main execution loop.

Link copied to clipboard
open suspend fun beforeTool(context: ToolContext, tool: BaseTool, args: Map<String, Any?>): CallbackChoice<Map<String, Any?>, Map<String, Any?>>

Callback executed before a tool is invoked.

Link copied to clipboard
open override fun close()

Method executed when the runner is closed.

Link copied to clipboard
open suspend fun onEvent(invocationContext: InvocationContext, event: Event): Event

Callback executed when an event is yielded by an agent during execution.

Link copied to clipboard
open suspend fun onModelError(context: CallbackContext, request: LlmRequest, error: Throwable): CallbackChoice<Unit, LlmResponse>

Callback executed when an error occurs during an LLM interaction.

Link copied to clipboard
open suspend override fun onRunError(invocationContext: InvocationContext, error: Throwable)

Callback executed when an unhandled error escapes the ADK runner run.

Link copied to clipboard
open suspend override fun onToolError(context: ToolContext, tool: BaseTool, args: Map<String, Any?>, error: Throwable): CallbackChoice<Unit, Map<String, Any?>>

Callback executed when an error occurs during a tool invocation.

Link copied to clipboard
open suspend fun onUserMessage(invocationContext: InvocationContext, userMessage: Content): Content

Callback executed when a user message is received before an invocation starts.