Callbacks: Observe, Customize, and Control Agent Behavior
https://google.github.io/adk-docs/assets/callback_flow.png
Why use them? Callbacks unlock significant flexibility and enable advanced agent capabilities:
Observe & Debug
Implement Guardrails
LlmAgentにcallbackそれぞれを引数として指定
The framework provides special context objects (CallbackContext or ToolContext) as arguments.
Controlling the Flow (The Core Mechanism): The most powerful aspect of callbacks lies in how their return value influences the agent's subsequent actions.
Noneを返す場合はoverrideしない
return <Specific Object> (Override Default Behavior):
after_model_callback → LlmResponse: Replaces the LlmResponse received from the LLM. Useful for sanitizing outputs, adding standard disclaimers, or modifying the LLM's response structure.
on_tool_error_callback がある!