Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions docs/plugins/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,24 @@ related callback functions together to be used across a workflow. This makes
Plugins an ideal solution for implementing features that cut across your entire
agent application.

## Prebuilt Plugins

ADK includes several plugins that you can add to your agent workflows
immediately:

* [**Reflect and Retry Tools**](/adk-docs/plugins/reflect-and-retry/):
Tracks tool failures and intelligently retries tool requests.
* [**BigQuery Logging**](https://github.com/google/adk-python/blob/main/src/google/adk/plugins/bigquery_logging_plugin.py):
Enables agent logging and analysis with BigQuery.
* [**Context Filter**](https://github.com/google/adk-python/blob/main/src/google/adk/plugins/context_filter_plugin.py):
Filters the generative AI context to reduce its size.
* [**Global Instruction**](https://github.com/google/adk-python/blob/main/src/google/adk/plugins/global_instruction_plugin.py):
Plugin that provides global instructions functionality at the App level.
* [**Save Files as Artifacts**](https://github.com/google/adk-python/blob/main/src/google/adk/plugins/save_files_as_artifacts_plugin.py):
Saves files included in user messages as Artifacts.
* [**Logging**](https://github.com/google/adk-python/blame/main/src/google/adk/plugins/logging_plugin.py):
Log important information at each agent workflow callback point.

## Define and register Plugins

This section explains how to define Plugin classes and register them as part of
Expand Down
82 changes: 82 additions & 0 deletions docs/plugins/reflect-and-retry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Reflect and Retry Tool Plugin

<div class="language-support-tag">
<span class="lst-supported">Supported in ADK</span><span class="lst-python">Python v1.16.0</span>
</div>

The Reflect and Retry Tool plugin can help your agent recover from error
responses from ADK [Tools](/adk-docs/tools-custom/) 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
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),
],
)
```

With this configuration, if any tool called by an agent returns an error, the
request is updated and tried again, up to a maximum of 3 attempts, per tool.

## 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`.
* **`tracking_scope`**: (optional)
* **`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:

```python
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:

* [Basic](https://github.com/google/adk-python/tree/main/contributing/samples/plugin_reflect_tool_retry/basic)
code sample
* [Hallucinating function name](https://github.com/google/adk-python/tree/main/contributing/samples/plugin_reflect_tool_retry/hallucinating_func_name)
code sample
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ nav:
- events/index.md
- Plugins:
- plugins/index.md
- Reflect and retry: plugins/reflect-and-retry.md
- MCP:
- mcp/index.md
- A2A Protocol:
Expand Down