# Practical and Useful Patterns with ADK
โ "Are you sure you want to send this email?" โ ADK's Action Confirmations add pre-execution user approval for irreversible operations, building safer agents.
๐ Title: Action Confirmations โ Pre-Execution Approval for Irreversible Operations
๐ URL:
๐งฉ Overview
ADK's Action Confirmations require explicit user approval before executing hard-to-reverse operations like email sending, data deletion, and payment processing. The agent asks "Should I proceed?" and only executes upon user approval. This maintains human control at critical decision points while keeping agents autonomous for routine tasks.
๐ Usage
Defining tools with confirmation requirements.
To define tools with confirmation, import `Agent` and `ToolContext` from `google.adk`. In `send_email(to: str, subject: str, body: str, tool_context: ToolContext)`, call `tool_context.actions.request_confirmation(message=...)` before the actual send, displaying a preview with recipient, subject, and body. The email is only sent if the user approves. Similarly, `delete_records(table: str, condition: str, tool_context: ToolContext)` counts records to be deleted first, then displays the count in a confirmation message for user approval. Pass both tools to an `Agent` with `name="admin_assistant"` and `model="gemini-2.5-flash"` via the `tools` parameter.
๐ Practical Patterns
**When to Require Confirmation**: Add confirmation for these categories:
- External sends (email, messages, API calls)
- Data modification or deletion
- Operations that incur charges
- Permission or access control changes
For payment processing, define `process_payment(amount: float, currency: str, recipient: str, tool_context: ToolContext)`. This function calls `tool_context.actions.request_confirmation(message=...)` with the recipient, currency, and amount details. Only after user approval does it execute `payment_gateway.charge(amount=..., currency=..., recipient=...)` to process the transaction.
**Confirmation Message Design**: Include the target, scope of impact, and irreversibility in confirmation messages. Provide exactly the information users need to make an informed decision.
**Staged Confirmations**: For multi-step operations, decide whether to confirm at each step or summarize at the final step. Balance thoroughness with user experience.
๐ก Use Cases
๐ง Email and message send confirmation
๐๏ธ Database record deletion approval
๐ณ Payment and transfer execution confirmation
๐ Permission and access control change approval
โ ๏ธ Caveats
- Too many confirmations degrade user experience. Limit confirmations to truly irreversible operations.
- Insufficient confirmation messages prevent users from making informed decisions. Be specific about the operation's impact.
- Confirmations become bottlenecks in batch processing and automation pipelines. Consider skippable confirmations for automated scenarios.
โจ Properly configured Action Confirmations balance agent autonomy with human safety oversight. The key is confirming only "can't-undo" operations!
#
ADK# #
AIAgent#