Google ADK

Put a person's approval in front of any Google ADK tool with one before_tool_callback, and record each outcome.

In Google’s Agent Development Kit, every tool call passes through the agent’s before_tool_callback. That one function is enough to put a person in front of the tools that send, pay or delete: it asks VariantGate, waits for the answer, and lets the call through only on a yes. Tools you wrote, built-in ones and tools from an MCP toolset are all covered, because the check sits outside them.

1. Install the client

pip install https://variantgate.com/sdk/variantgate-latest.tar.gz

It has no dependencies beyond the standard library and works on Python 3.9 or newer. Make an agent key under Agents in your workspace and put it in VARIANTGATE_KEY. The client reads it from there.

2. Ask in the callback

import asyncio
import contextlib

from google.adk.agents import Agent
from variantgate import ApprovalClient, VariantGateError

approvals = ApprovalClient("support-adk")  # reads VARIANTGATE_KEY


def refund_order(order_id: str, amount_eur: str) -> dict:
    """Refund an order to the customer's original payment method."""
    return {"status": "refunded", "refund": shop.refund(order_id, amount_eur)}


# The tools that need a person's yes, and what that person is asked.
GATED = {
    "refund_order": lambda args: {
        "action": "payment.refund",
        "summary": f"Refund €{args['amount_eur']} for order {args['order_id']}",
        "amount": args["amount_eur"],
        "currency": "EUR",
        "details": {"order": args["order_id"]},
    },
}


async def ask_first(tool, args, tool_context):
    """Runs before every tool. Returning a dict skips the tool and answers with it."""
    describe = GATED.get(tool.name)
    if describe is None:
        return None  # not gated: run it
    try:
        decision = await asyncio.to_thread(
            approvals.wait_for_approval, **describe(args), timeout=900
        )
    except VariantGateError as no:
        return {"status": "not_done", "reason": str(no)}
    tool_context.state[f"temp:approval:{tool_context.function_call_id}"] = decision["id"]
    return None


async def report_outcome(tool, args, tool_context, tool_response):
    """Runs after a tool: tell the record how the approved action went."""
    approval = tool_context.state.get(f"temp:approval:{tool_context.function_call_id}")
    if approval:
        outcome = "failed" if tool_response.get("error") else "succeeded"
        with contextlib.suppress(VariantGateError):  # the tool ran: never fail the turn over the record
            await asyncio.to_thread(approvals.report_outcome, approval, outcome)
    return None


root_agent = Agent(
    name="support",
    model="gemini-2.5-flash",
    instruction="Help customers with their orders.",
    tools=[refund_order],
    before_tool_callback=ask_first,
    after_tool_callback=report_outcome,
)
  • GATED lists the tools that need approval and turns each call’s arguments into what a person reads. Any tool not in it runs as before.
  • On anything but an approval, the callback returns a dict. ADK skips the tool and gives the model that dict as the result, so the model can tell the user it was not done. That covers denied, expired, a paused workspace, an approval with changes, and an API that could not be reached.
  • The wait runs in a thread, so other sessions on the same server keep going while a person decides.
  • The approval’s id goes into temp: state under the call id, so the after-callback records the outcome for the right request even when the model calls several tools at once. It records failed when the tool answers with an error, and a failure to record never fails the turn once the tool has run.
  • State the amount, and a rule such as “always allow payment.refund up to €20” approves the small ones without waiting.

3. Run it

Nothing changes in how you run the agent: adk web, adk run or your own Runner. Ask it to refund an order, and the request appears in your inbox. Approve it and the refund runs; deny one on purpose and check that the agent says it was not done.

ADK’s own tool confirmation

ADK can also pause a tool for confirmation, with require_confirmation on a FunctionTool. The answer then comes back through your own client, which suits an app where the user in the chat is the one who decides. VariantGate suits agents that run on their own: someone else decides, from wherever they are, rules settle the routine calls, and every decision is kept on the record. The framework comparison covers when each fits.