1414
1515from unittest .mock import patch
1616
17- from google .adk .agents .caller_principal import CallerPrincipal
17+ from google .adk .agents ._caller_principal import CallerPrincipal
1818from google .adk .agents .llm_agent import LlmAgent
1919from google .adk .events .event import Event
2020from google .adk .events .event_actions import EventActions
@@ -1335,6 +1335,23 @@ def _build_pending_confirmation_events(agent_name: str) -> list[Event]:
13351335 name = MOCK_TOOL_NAME , args = {"param1" : "test" }, id = MOCK_FUNCTION_CALL_ID
13361336 )
13371337 tool_confirmation = ToolConfirmation (confirmed = False , hint = "test hint" )
1338+ confirmation_request = types .FunctionCall (
1339+ name = functions .REQUEST_CONFIRMATION_FUNCTION_CALL_NAME ,
1340+ args = {
1341+ "originalFunctionCall" : original_function_call .model_dump (
1342+ exclude_none = True , by_alias = True
1343+ ),
1344+ "toolConfirmation" : tool_confirmation .model_dump (
1345+ by_alias = True , exclude_none = True
1346+ ),
1347+ },
1348+ id = MOCK_CONFIRMATION_FUNCTION_CALL_ID ,
1349+ )
1350+ approval = types .FunctionResponse (
1351+ name = functions .REQUEST_CONFIRMATION_FUNCTION_CALL_NAME ,
1352+ id = MOCK_CONFIRMATION_FUNCTION_CALL_ID ,
1353+ response = {"response" : ToolConfirmation (confirmed = True ).model_dump_json ()},
1354+ )
13381355 return [
13391356 Event (
13401357 author = agent_name ,
@@ -1345,49 +1362,15 @@ def _build_pending_confirmation_events(agent_name: str) -> list[Event]:
13451362 Event (
13461363 author = agent_name ,
13471364 content = types .Content (
1348- parts = [
1349- types .Part (
1350- function_call = types .FunctionCall (
1351- name = functions .REQUEST_CONFIRMATION_FUNCTION_CALL_NAME ,
1352- args = {
1353- "originalFunctionCall" : (
1354- original_function_call .model_dump (
1355- exclude_none = True , by_alias = True
1356- )
1357- ),
1358- "toolConfirmation" : (
1359- tool_confirmation .model_dump (
1360- by_alias = True , exclude_none = True
1361- )
1362- ),
1363- },
1364- id = MOCK_CONFIRMATION_FUNCTION_CALL_ID ,
1365- )
1366- )
1367- ]
1365+ parts = [types .Part (function_call = confirmation_request )]
13681366 ),
13691367 ),
13701368 Event (
13711369 author = "user" ,
1372- content = types .Content (
1373- parts = [
1374- types .Part (
1375- function_response = types .FunctionResponse (
1376- name = functions .REQUEST_CONFIRMATION_FUNCTION_CALL_NAME ,
1377- id = MOCK_CONFIRMATION_FUNCTION_CALL_ID ,
1378- response = {
1379- "response" : ToolConfirmation (
1380- confirmed = True
1381- ).model_dump_json ()
1382- },
1383- )
1384- )
1385- ]
1386- ),
1370+ content = types .Content (parts = [types .Part (function_response = approval )]),
13871371 ),
13881372 ]
13891373
1390-
13911374async def _run_with_caller_principal (caller_principal ):
13921375 """Runs the processor over a pending approval under one caller principal.
13931376
@@ -1499,7 +1482,7 @@ async def test_confirmation_refused_for_unauthenticated_caller_when_strict(
14991482 instead is what made the earlier transport-keyed guard hang every
15001483 human-in-the-loop tool.
15011484 """
1502- monkeypatch .setenv ("ADK_STRICT_CALLER_PRINCIPAL " , "true " )
1485+ monkeypatch .setenv ("ADK_ENABLE_STRICT_CALLER_PRINCIPAL " , "1 " )
15031486
15041487 events , confirmation = await _run_with_caller_principal (
15051488 CallerPrincipal (authenticated = False , source = "a2a" )
@@ -1513,7 +1496,7 @@ async def test_confirmation_refused_for_unauthenticated_caller_when_strict(
15131496@pytest .mark .asyncio
15141497async def test_strict_mode_does_not_touch_in_process_callers (monkeypatch ):
15151498 """Strict mode must not refuse an invocation that crossed no boundary."""
1516- monkeypatch .setenv ("ADK_STRICT_CALLER_PRINCIPAL " , "true " )
1499+ monkeypatch .setenv ("ADK_ENABLE_STRICT_CALLER_PRINCIPAL " , "1 " )
15171500
15181501 events , confirmation = await _run_with_caller_principal (None )
15191502
@@ -1532,7 +1515,7 @@ async def test_strict_mode_keeps_multi_turn_reentry_a_noop(monkeypatch):
15321515 already acted on yields nothing rather than refusing or re-executing it.
15331516 This is the regression that got the previous guard reverted.
15341517 """
1535- monkeypatch .setenv ("ADK_STRICT_CALLER_PRINCIPAL " , "true " )
1518+ monkeypatch .setenv ("ADK_ENABLE_STRICT_CALLER_PRINCIPAL " , "1 " )
15361519 agent = LlmAgent (
15371520 name = "test_agent" ,
15381521 tools = [FunctionTool (mock_tool , require_confirmation = False )],
0 commit comments