5.3 ADK Callbacks & Human-in-the-Loop (HITL) Controls
1. The 60-Second Anchor
Section titled “1. The 60-Second Anchor”Cloud IAM and OAuth 2.0 only check who is calling a tool—they cannot look inside the tool’s parameters (like amount = 50000). To inspect live payloads and enforce deterministic guardrails inside the Agent Development Kit (ADK), Google Cloud gives you two runtime callback hooks:
- Before-Model Callback (
before_model_callback): The Thought Guard. Runs before the request reaches the Gemini LLM. Use it to check incoming context/prompts, inject dynamic system instructions, or return a pre-built response (LlmResponse) to skip calling the LLM completely! - Before-Tool Callback (
before_tool_callback): The Action Guard. Runs after Gemini decides to call a tool, but before the tool actually executes. Use it to inspect exact tool arguments (args), block dangerous parameter values, or pause execution for Human-in-the-Loop (HITL) approval!
2. Interactive Showdown: Before-Model vs. Before-Tool Callbacks
Section titled “2. Interactive Showdown: Before-Model vs. Before-Tool Callbacks”Toggle between the 3 Exam Callback Scenarios below and step through the 4 stages to see exactly what ADK inspects—and what return values (None, LlmResponse, or dict) control execution on the exam:
3. Exam Cheat Sheet: The ADK Callback Showdown Matrix
Section titled “3. Exam Cheat Sheet: The ADK Callback Showdown Matrix”Memorize the exact inputs and return values for both ADK callbacks—the exam loves testing what happens when a callback returns None versus an override object!
| Feature | before_model_callback (Thought Guard) |
before_tool_callback (Action Guard) |
|---|---|---|
| When Does It Run? | Right before the request is sent to the Gemini LLM. | Right before a selected tool function or MCP tool is executed. |
| What Inputs Does It Inspect? | callback_context and llm_request (the prompt, conversation history, and system instructions). |
tool, args (the dictionary of tool parameters like amount=50000), and tool_context. |
What Happens If It Returns None? |
Proceeds normally: Sends the llm_request to the Gemini model. |
Proceeds normally: Executes the actual tool with the provided args. |
| How Do You Block / Override Execution? | Return an LlmResponse object (skips calling Gemini completely and sends your custom response). |
Return a dict (skips running the tool completely and passes your dictionary back to the agent as the tool output). |
4. High-Yield Exam Split: The 2 Types of Human-in-the-Loop (HITL)
Section titled “4. High-Yield Exam Split: The 2 Types of Human-in-the-Loop (HITL)”On the PAAC exam, “Human-in-the-Loop” can mean two very different architectural patterns depending on whether you are pausing a single high-risk tool call or escalating an entire customer conversation. Here is how to pick the right answer every time:
| HITL Pattern | 1. ADK Tool-Level HITL (Action Approval) | 2. Customer Engagement Suite (CES) Conversation-Level HITL (Live Agent Handoff) |
|---|---|---|
| What Gets Paused or Transferred? | Only the specific high-risk tool execution (e.g., wiring $50,000, deleting a production database, or issuing a large refund). | The entire live chat or voice conversation is handed off to a human contact-center rep. |
| How It Works Under the Hood | Implemented via ADK’s before_tool_callback or built-in Tool Confirmation flow. The callback intercepts args, pauses execution, requests human sign-off on the parameters, and resumes once approved. |
Configured in CX Agent Studio / Customer Engagement Suite (CES) using escalation rules triggered by negative sentiment, repeated fallback/no-match, or explicit user requests (“Talk to a human”). |
| What the Human Reviewer Sees | A structured Approval Request Payload showing the tool name, exact arguments (amount: $50,000), and Approve/Reject buttons. |
The Full Conversation Transcript + AI-Generated Context Summary inside the human agent desktop so the customer doesn’t have to repeat themselves. |
| Exam Keyword Triggers | “High-value transaction,” “sensitive API mutation,” “approve tool arguments,” “deterministic parameter threshold.” | “Frustrated customer,” “contact center escalation,” “live agent warm transfer,” “omnichannel voice/chat support.” |