Skip to main content
This example shows how to integrate Agent Control with Google ADK using the ADK native callback hooks. Use this example when you want manual lifecycle control. If you are starting fresh with Google ADK, use /examples/google-adk-plugin instead. This is the lower-level ADK example in this repo:
  • the callback pattern can protect model I/O through before_model_callback and after_model_callback
  • tool guardrails through before_tool_callback and after_tool_callback
  • this example uses server-side control execution

What It Demonstrates

  • pre-LLM prompt injection blocking
  • pre-tool restricted-city blocking
  • post-tool output filtering for synthetic unsafe output
  • fail-closed behavior when the Agent Control server cannot evaluate safely

Prerequisites

  1. Start the Agent Control server from the repo root:
  2. Install the example dependencies:
  3. Set your Google API key:
  4. Optional environment variables:

Setup

Create the demo controls and attach them to the example agent:
This creates:
  • adk-callbacks-block-prompt-injection
  • adk-callbacks-block-restricted-cities
  • adk-callbacks-block-internal-contact-output

Run

Run the ADK app from the example directory:

Suggested Scenarios

Safe request:
Prompt injection blocked before the model call:
Restricted city blocked before the tool call:
Synthetic unsafe tool output blocked after the tool call:
Testville is a deliberate demo trigger that makes the tool produce an internal contact note so the post-tool control can block it deterministically.

Files

  • setup_controls.py - registers the agent and creates the callback example controls
  • my_agent/agent.py - ADK app with Agent Control callbacks
  • .env.example - environment variables for local runs

Notes

  • This example is server-only by design.
  • The callback pattern itself can also support sdk-local evaluation when your callback wiring goes through Agent Control’s local-aware evaluation helpers instead of the server-only helper used here.
  • Google ADK also supports after_model_callback; this example keeps the manual flow smaller and wires before_model_callback plus the tool hooks.
  • If you want the recommended packaged integration, use /examples/google-adk-plugin.
  • If you want the @control() pattern or sdk-local execution, use /examples/google-adk-decorator.

Source Code

View the complete example with all scripts and setup instructions: Google ADK Callbacks Example