Plugin struct for hooking into the agent lifecycle.
Plugins provide callbacks at Runner, Agent, Model, and Tool levels.
Callbacks follow the standard {value | nil, updated_context} pattern:
non-nil values short-circuit, nil continues to the next plugin/callback.
Example
plugin = ADK.Plugin.new(
name: "logging",
before_model: fn cb_ctx, _request ->
IO.puts("Model called for #{ADK.Agent.CallbackContext.agent_name(cb_ctx)}")
{nil, cb_ctx}
end
)
Summary
Types
@type after_agent_callback() :: (ADK.Agent.CallbackContext.t() -> {ADK.Types.Content.t() | nil, ADK.Agent.CallbackContext.t()})
@type after_model_callback() :: (ADK.Agent.CallbackContext.t(), ADK.Model.LlmResponse.t() -> {ADK.Model.LlmResponse.t() | nil, ADK.Agent.CallbackContext.t()})
@type after_run_callback() :: (ADK.Agent.InvocationContext.t() -> :ok)
@type after_tool_callback() :: (ADK.Tool.Context.t(), struct(), map(), map() -> {map() | nil, ADK.Tool.Context.t()})
@type before_agent_callback() :: (ADK.Agent.CallbackContext.t() -> {ADK.Types.Content.t() | nil, ADK.Agent.CallbackContext.t()})
@type before_model_callback() :: (ADK.Agent.CallbackContext.t(), ADK.Model.LlmRequest.t() -> {ADK.Model.LlmResponse.t() | nil, ADK.Agent.CallbackContext.t()})
@type before_run_callback() :: (ADK.Agent.InvocationContext.t() -> {ADK.Types.Content.t() | nil, ADK.Agent.InvocationContext.t()})
@type before_tool_callback() :: (ADK.Tool.Context.t(), struct(), map() -> {map() | nil, ADK.Tool.Context.t()})
@type on_event_callback() :: (ADK.Agent.InvocationContext.t(), ADK.Event.t() -> {ADK.Event.t() | nil, ADK.Agent.InvocationContext.t()})
@type on_model_error_callback() :: (ADK.Agent.CallbackContext.t(), ADK.Model.LlmRequest.t(), term() -> {ADK.Model.LlmResponse.t() | nil, ADK.Agent.CallbackContext.t()})
@type on_tool_error_callback() :: (ADK.Tool.Context.t(), struct(), map() -> {map() | nil, ADK.Tool.Context.t()})
@type on_user_message_callback() :: (ADK.Agent.InvocationContext.t(), ADK.Types.Content.t() -> {ADK.Types.Content.t() | nil, ADK.Agent.InvocationContext.t()})
@type t() :: %ADK.Plugin{ after_agent: after_agent_callback() | nil, after_model: after_model_callback() | nil, after_run: after_run_callback() | nil, after_tool: after_tool_callback() | nil, before_agent: before_agent_callback() | nil, before_model: before_model_callback() | nil, before_run: before_run_callback() | nil, before_tool: before_tool_callback() | nil, name: String.t(), on_event: on_event_callback() | nil, on_model_error: on_model_error_callback() | nil, on_tool_error: on_tool_error_callback() | nil, on_user_message: on_user_message_callback() | nil }