Skip to content

Commit 4ab3a72

Browse files
authored
workflow: shared resumed_tool_confirmation helper with the caller principal gate
Moves the principal decision made in _ToolNode._apply_confirmation_resume into _workflow_hitl_utils.resumed_tool_confirmation, next to confirmation_interrupt_id and parse_tool_confirmation from main, so every workflow consumer of a resumed confirmation answer makes the same decision. FunctionNode require_confirmation (988fd1a on main) is the second consumer and is switched over in the next commit.
1 parent 711d21b commit 4ab3a72

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

‎src/google/adk/workflow/utils/_workflow_hitl_utils.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
from google.genai import types
2424

25+
from ...agents._caller_principal import caller_may_confirm
2526
from ...auth.auth_credential import AuthCredential
2627
from ...auth.auth_credential import AuthCredentialTypes as _AuthCredentialTypes
2728
from ...auth.auth_credential import OAuth2Auth
@@ -34,6 +35,7 @@
3435
from .._errors import WorkflowDataError
3536

3637
if TYPE_CHECKING:
38+
from ...agents.context import Context
3739
from ...auth.auth_tool import AuthConfig
3840
from ...sessions.state import State
3941

@@ -67,6 +69,26 @@ def parse_tool_confirmation(response: Any) -> ToolConfirmation:
6769
) from e
6870

6971

72+
def resumed_tool_confirmation(ctx: Context) -> ToolConfirmation | None:
73+
"""Returns the caller's answer to this node run's confirmation request.
74+
75+
None when the run is not resuming from a confirmation request. An answer
76+
from a caller the serving layer could not authenticate comes back as a
77+
rejection, the same decision the agent pipeline makes for a confirmation
78+
carried in a user event. It is made here, before the answer is stored on
79+
the context, because tools such as `ExecuteBashTool` read
80+
`tool_confirmation` themselves rather than through
81+
`apply_confirmation_gate`.
82+
"""
83+
response = ctx.resume_inputs.get(confirmation_interrupt_id(ctx.node_path))
84+
if response is None:
85+
return None
86+
confirmation = parse_tool_confirmation(response)
87+
if not caller_may_confirm(ctx.get_invocation_context().caller_principal):
88+
confirmation = confirmation.model_copy(update={'confirmed': False})
89+
return confirmation
90+
91+
7092
def create_request_input_event(request_input: RequestInput) -> Event:
7193
"""Creates a RequestInput event from a RequestInput object."""
7294
args = request_input.model_dump(exclude={'response_schema'}, by_alias=True)

0 commit comments

Comments
 (0)