-
Notifications
You must be signed in to change notification settings - Fork 635
docs: Reflect and Retry Tool Plugin - Update ADK doc according to issue #796 - 3 #802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7733d19
docs: Add documentation for ReflectAndRetryToolPlugin
adk-bot 92c9755
docs: add Reflect and Retry plugin page
joefernandez 3eec2ea
Merge branch 'main' into agent-changes-20251022-210417
joefernandez ae8da9b
docs: Reflect and Retry Plugin page
joefernandez 215ce6a
resolve review comments
joefernandez ecb0df6
final review comments
joefernandez 58ef7bd
Merge branch 'main' into agent-changes-20251022-210417
joefernandez 64850f1
fix broken link
joefernandez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.