Repository navigation
feat(tools): let a tool supply the hint and payload of its confirmation request - #7798
Open
inamdarmihir wants to merge 1 commit into
Open
inamdarmihir wants to merge 1 commit into
inamdarmihir wants to merge 1 commit into
Conversation
…on request The framework confirmation gate always asked with a fixed generic hint and no payload, so a tool gated through require_confirmation or check_require_confirmation could not tell the user what they were approving. Add BaseTool.get_confirmation_request(args, tool_context), returning a new ConfirmationRequest(hint, payload). The gate, and the run_async fallbacks of FunctionTool and McpTool, now request confirmation with what it returns. The default reproduces the previous hint with no payload, so nothing changes for existing tools. Enforcement of the answer is unchanged, and a hook that raises fails the call instead of letting it through. Fixes google#7737
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.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
Problem:
Since 2.10.0 the framework gate (
apply_confirmation_gate) holds any call whosecheck_require_confirmationis true beforerun_asyncruns, always with a fixed generic hint and no payload. A tool can no longer tell the user what they are approving: aFunctionToolsubclass that used to callrequest_confirmation(hint=..., payload=...)fromrun_asyncnow never gets there, and the client silently receives the generic text andpayload=None. The only alternative (callingrequest_confirmationinside the tool) moves enforcement back into every tool and is unavailable for tools you don't write.Solution:
Add an optional hook on
BaseTool:ConfirmationRequest(new, intool_confirmation.py) carrieshintand a JSON-serializablepayload. The gate, and therun_asyncfallback paths ofFunctionToolandMcpTool, request confirmation with what the hook returns. The default reproduces today's exact hint withpayload=None, so existing tools are unchanged. The hook is only called when the call is gated and not yet answered (never for approved, rejected or ungated calls). Enforcement is unchanged: the call still runs only once approved, whatever the hook returns. If the hook raises, the call is neither run nor recorded as awaiting confirmation and the error is handled like any tool error (fail closed, never skipping the gate). The workflowToolNodepicks it up through the shared gate.Left out on purpose to keep the API small: a
FunctionTool(...)constructor shortcut, feeding the hook from arequire_confirmationcallable, anMcpToolsetconstructor argument, and a rejection-text hook. A subclass override coversFunctionTool,McpTooland anyBaseTool.Testing Plan
Unit Tests:
Tests cover: default hint with
payload=None; custom hint, nested payload, payload with empty hint; the hook receives the call args and the sametool_context; hook not called for ungated, approved or rejected calls; hook raising records nothing, does not run the tool, and reacheson_tool_error_callback; approval and rejection resume (single agent and resumableSequentialAgent) end to end throughRunner;FunctionTool.run_asynccalled directly;McpToolthrough the gate andrun_async;ToolNodehint/payload through to approval. With the source change stashed, the touched test modules fail at import.Manual End-to-End (E2E) Tests:
Throwaway script: a gated tool overriding the hook emits an
adk_request_confirmationcall carrying its hint and payload; a plain gatedFunctionToolstill emits the generic hint.Checklist
Additional context
The tool-confirmation docs (
docs/guides/tools/tool_confirmation,base_tool) are updated. The hook name follows the sketch in the issue; happy to rename.