Google ADK Compliance: How to Add Audit Logging to Agent Development Kit Pipelines
Google Agent Development Kit provides six lifecycle callbacks as designated integration points for cross-cutting concerns including compliance logging. The primary compliance capture points are after_agent_callback (final decision record with full response content) and before_tool_callback (consequential tool invocations before they execute). Multi-agent pipelines using SequentialAgent use the ADK session ID as the correlation key, linking all agent callbacks in a pipeline to the same compliance decision. Ghost SDK fires asynchronously from callbacks with under 5ms overhead and no agent logic changes required.
ADK Callback Architecture for Compliance
ADK exposes six callback hooks that fire during agent execution. For compliance, the primary capture points are: after_agent_callback (fires when the agent finishes, has the final response content — this is the definitive compliance record), and before_tool_callback (fires before a tool executes, has tool name and arguments — captures consequential tool invocations at the intent stage, before real-world effects). before_agent_callback is useful for initializing the decision context (setting decision_id, recording start time). after_model_callback captures intermediate LLM reasoning for complex multi-step decisions. Callbacks are attached at agent instantiation time and require zero changes to agent logic.
after_agent_callback: Primary Decision Record
after_agent_callback fires after the agent finishes its invocation and before the response is returned to the caller. It has access to the callback_context (agent name, session information) and the llm_response (final content). In the callback, extract the final agent text, call ghost.capture() with subject_id (from the outer function closure), decision_type, context (input context provided at pipeline entry), reasoning and action (from the final agent text), and decision_id. The callback must return the llm_response unchanged (or return a modified response if content filtering is needed). Ghost SDK fires asynchronously — the callback returns in under 5ms.
before_tool_callback: Consequential Tool Capture
before_tool_callback fires before a tool executes, providing the tool name and arguments. For compliance, filter for consequential tools — those that write to databases, send notifications, approve or deny requests. Non-consequential tools (lookup, search, calculation) may not require individual compliance records. In the callback, call ghost.capture() with the tool name as the decision_type and tool arguments as the action. Return None to allow the tool to execute normally, or return a ToolResponse to intercept execution (useful for pre-approval workflows where tool execution requires compliance check before proceeding).
Multi-Agent Pipeline Correlation with Session ID
ADK SequentialAgent, ParallelAgent, and LoopAgent compose multiple agents into pipelines. The ADK session provides a natural correlation key — all agents in a session share the same session_id. For compliance, use the session_id as the decision_id in all callback captures across all agents in the pipeline. Each callback has access to the callback_context which includes session information. Include agent_name (from callback_context.agent_name) in metadata to distinguish which agent in the pipeline made each captured decision. When retrieving the complete decision trail for a specific pipeline invocation, query by session_id (decision_id) to return all records in pipeline order.