Files
google__adk-docs/docs/integrations/reflect-and-retry.md
George Weale d9e930e823 docs(integrations): fix unresolvable imports and stale API claims (#2031)
* docs(integrations): fix unresolvable imports and stale API claims

* docs: apply style pass and drop out-of-scope import cleanup

* docs(integrations): address review feedback on gcs, cloud-trace, reflect-and-retry

Restore the gcs_ tool name prefixes in the GCS tool tables, since both
toolsets set tool_name_prefix="gcs" and the tables list names as the
model sees them. Use the current Agent Platform SDK name in cloud-trace
prose, make the reflect-and-retry failure description language-neutral
for Python and Go, and drop the redundant re-export clause.

* docs(gcs): note that tool_filter matches unprefixed tool names

Tool filtering runs inside get_tools() against the unprefixed name, and
get_tools_with_prefix() applies the gcs_ prefix afterwards, so the names
in the tables are not the names tool_filter expects.

* docs(computer-use): drop unused Gemini and override imports

---------

Co-authored-by: Kristopher Overholt <koverholt@google.com>
2026-08-11 18:11:00 -05:00

4.4 KiB

catalog_title, catalog_description, catalog_icon, catalog_tags
catalog_title catalog_description catalog_icon catalog_tags
Reflect and Retry Plugin Automatically retry tool calls that fail /integrations/assets/adk.png
google
resilience

Reflect and Retry plugin for ADK

Supported in ADKPython v1.16.0Go v0.5.0

The Reflect and Retry plugin can help your agent recover from error responses from ADK Tools and automatically retry the tool request. This plugin intercepts tool failures, provides structured guidance to the AI model for reflection and correction, and retries the operation up to a configurable limit. This plugin can help you build more resilience into your agent workflows, including the following capabilities:

  • Concurrency safe: Uses locking to safely handle parallel tool executions.
  • Configurable scope: Tracks failures per-invocation (default) or globally.
  • Granular tracking: Failure counts are tracked per-tool.
  • Custom error extraction: Supports detecting errors in normal tool responses.

Add Reflect and Retry Plugin

Add this plugin to your ADK workflow by adding it to the plugins setting of your ADK project's App object, as shown below:

=== "Python"

```python
from google.adk.apps.app import App
from google.adk.plugins import ReflectAndRetryToolPlugin

app = App(
    name="my_app",
    root_agent=root_agent,
    plugins=[
        ReflectAndRetryToolPlugin(max_retries=3),
    ],
)
```

=== "Go"

```go
import (
	"google.golang.org/adk/v2/plugin/retryandreflect"
	"google.golang.org/adk/v2/runner"
)

// ... create rootAgent and sessionService ...

r, err := runner.New(runner.Config{
	AppName:        "my_app",
	Agent:          rootAgent,
	SessionService: sessionService,
	PluginConfig: runner.PluginConfig{
		Plugins: []*plugin.Plugin{
			retryandreflect.MustNew(retryandreflect.WithMaxRetries(3)),
		},
	},
})
```

With this configuration, if any tool called by an agent fails with an error, the request is updated and tried again, up to 3 retries per tool, for a maximum of 4 attempts. A tool that instead reports the problem in an otherwise successful result is not retried by default; see Advanced configuration for how to opt into that.

Configuration settings

The Reflect and Retry Plugin has the following configuration options:

  • max_retries: (optional) Total number of additional attempts the system makes to receive a non-error response. Default value is 3.
  • throw_exception_if_retry_exceeded: (optional) If set to False, the system does not raise an error if the final retry attempt fails. Default value is True. The Go equivalent, WithErrorIfRetryExceeded, defaults to false, so once retries are exhausted Go returns a message telling the model to stop using the tool, where Python raises the original error.
  • tracking_scope: (optional) A TrackingScope value, imported from google.adk.plugins.reflect_retry_tool_plugin:
    • TrackingScope.INVOCATION: Track tool failures across a single invocation and user. This value is the default.
    • TrackingScope.GLOBAL: Track tool failures across all invocations and all users.

Advanced configuration

You can further modify the behavior of this plugin by extending the ReflectAndRetryToolPlugin class. The following code sample demonstrates a simple extension of the behavior by selecting responses with an error status:

class CustomRetryPlugin(ReflectAndRetryToolPlugin):
  async def extract_error_from_result(self, *, tool, tool_args,tool_context,
  result):
    # Detect error based on response content
    if result.get('status') == 'error':
        return result
    return None  # No error detected

# add this modified plugin to your App object:
error_handling_plugin = CustomRetryPlugin(max_retries=5)

Next steps

For complete code samples using the Reflect and Retry plugin, see the following: