ADK.Plugin (adk_ex v1.1.0)

Copy Markdown View Source

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

Functions

Creates a new plugin from keyword options.

Types

after_agent_callback()

@type after_agent_callback() :: (ADK.Agent.CallbackContext.t() ->
                             {ADK.Types.Content.t() | nil,
                              ADK.Agent.CallbackContext.t()})

after_model_callback()

after_run_callback()

@type after_run_callback() :: (ADK.Agent.InvocationContext.t() -> :ok)

after_tool_callback()

@type after_tool_callback() :: (ADK.Tool.Context.t(), struct(), map(), map() ->
                            {map() | nil, ADK.Tool.Context.t()})

before_agent_callback()

@type before_agent_callback() :: (ADK.Agent.CallbackContext.t() ->
                              {ADK.Types.Content.t() | nil,
                               ADK.Agent.CallbackContext.t()})

before_model_callback()

before_run_callback()

@type before_run_callback() :: (ADK.Agent.InvocationContext.t() ->
                            {ADK.Types.Content.t() | nil,
                             ADK.Agent.InvocationContext.t()})

before_tool_callback()

@type before_tool_callback() :: (ADK.Tool.Context.t(), struct(), map() ->
                             {map() | nil, ADK.Tool.Context.t()})

on_event_callback()

@type on_event_callback() :: (ADK.Agent.InvocationContext.t(), ADK.Event.t() ->
                          {ADK.Event.t() | nil, ADK.Agent.InvocationContext.t()})

on_model_error_callback()

on_tool_error_callback()

@type on_tool_error_callback() :: (ADK.Tool.Context.t(), struct(), map() ->
                               {map() | nil, ADK.Tool.Context.t()})

on_user_message_callback()

@type on_user_message_callback() :: (ADK.Agent.InvocationContext.t(),
                               ADK.Types.Content.t() ->
                                 {ADK.Types.Content.t() | nil,
                                  ADK.Agent.InvocationContext.t()})

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
}

Functions

new(opts)

@spec new(keyword()) :: t()

Creates a new plugin from keyword options.

Requires :name. All callback fields are optional (default nil).