feat(plugins): port ReflectAndRetryToolPlugin from adk-python - #1391
Open
svetanis wants to merge 1 commit into
Open
feat(plugins): port ReflectAndRetryToolPlugin from adk-python#1391svetanis wants to merge 1 commit into
svetanis wants to merge 1 commit into
Conversation
svetanis
force-pushed
the
feature/reflect-and-retry-tool-plugin
branch
from
August 3, 2026 01:11
368f767 to
9cb1c70
Compare
Contributor
|
Hi @svetanis, thank you for your contribution! We appreciate you taking the time to submit this pull request. Currently this PR is under review by our team, we will keep you posted if any additional information is required. thank you. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
2. Or, if no issue exists, describe the change:
Problem:
When a tool fails, adk-java gives the model no way to learn what went wrong and try again. The run
ends on the first failure even when the failure is one the model could have corrected — malformed
arguments, the wrong tool, an unmet precondition. adk-python ships
ReflectAndRetryToolPluginforexactly this; adk-java has no equivalent.
Solution:
A port of that plugin. Seven new files in a new
com.google.adk.plugins.reflectandretrysubpackage, no existing file modified and no existing API changed — registration uses the surface
that is already there:
ReflectAndRetryToolPlugin.javaReflectionGuidance.javaToolFailureTracker.javaToolFailureResponse.javatoMap()TrackingScope.javaINVOCATION/GLOBALReflectAndRetryToolPluginTest.javaToolFailureTrackerTest.javaBoth hooks it overrides are already declared on
Plugin, and both already return the type theplugin needs —
Maybe<Map<String, Object>>, matching Python'sOptional[dict[str, Any]]:onToolErrorCallbackcounts the failure and, under the limit, substitutes a structured response —error type, error details, retry count, and guidance telling the model to analyze its arguments and
not repeat the identical call. Past the limit it either propagates the original error or returns a
final "stop using this tool" message, per a constructor flag.
afterToolCallbackresets that tool'scounter on success, routes an extracted error into the same logic, and passes the plugin's own
reflection responses straight through — reflecting on a reflection would count one tool failure
twice, and there is a test for it.
Ported from
adk-python/src/google/adk/plugins/reflect_retry_tool_plugin.py(382 lines). Theguidance strings are upstream's, including a grammatical slip in item 5 — copied rather than
corrected so the two implementations do not drift.
Testing Plan
Unit Tests:
Twenty-five tests, all new — these are new classes, so there is no before/after state to contrast:
onToolError_withinRetryLimit_returnsReflectionGuidanceonToolError_guidanceCarriesToolNameAndArgumentsonToolError_countsConsecutiveFailuresretry_countsequenceonToolError_pastRetryLimit_propagatesOriginalErroronToolError_pastRetryLimit_whenNotThrowing_returnsGiveUpMessagemaxRetriesZero_propagatesImmediatelynegativeMaxRetries_isRejectedafterTool_onSuccess_resetsThatToolsCounterafterTool_successOfOneTool_doesNotForgiveAnotherafterTool_ownReflectionResponse_isPassedThroughUncountedinvocationScope_countsAreIsolatedPerInvocationINVOCATIONscopeglobalScope_countsSurviveAcrossInvocationsGLOBALscopeextractErrorFromResult_whenOverridden_treatsSuccessfulResultAsFailureextractErrorFromResultoverridescopeKey_whenOverridden_outranksTheConfiguredTrackingScopescopeKeyoverrideonToolError_errorWithoutMessage_reportsEmptyDetails(+ past-limit twin)"", as in PythonmaxRetriesZero_whenNotThrowing_returnsGiveUpMessagemaxRetries=0onToolError_whenArgumentsCannotBeSerialized_fallsBackToMapRenderingnullTrackingScope_isRejectedAtConstructionrecordFailure_inParallel_countsEachFailureExactlyOncerecordFailure_countsEachToolSeparately/...EachScopeSeparatelyreset_clearsOnlyThatTool/reset_clearsOnlyThatScope/reset_onUnknownScope_isASilentNoOpManual End-to-End (E2E) Tests:
Two scenarios run against
gemini-2.5-flashthrough anInMemoryRunner, each alongside a control —the same model, prompt and tools with the plugin unregistered:
Checklist