adk_callbacks behaviour (erlang_adk v0.7.0)

View Source

adk_callbacks - Behavior and registry for ADK execution callbacks.

Callbacks allow hooking into the execution lifecycle (e.g., on_llm_start, on_tool_call, on_error) for logging, monitoring, or side-effects.

Summary

Functions

Execute a callback hook across all registered handlers.

Run handlers until one explicitly replaces or halts the operation. Observation-only callbacks return ok or continue. A callback may return {replace, Value} to replace an after-hook result, or {halt, Value} to skip the operation wrapped by a before-hook.

Types

callback_result/0

-type callback_result() :: ok | continue | {halt, term()} | {replace, term()}.

Callbacks

after_agent/2

(optional)
-callback after_agent(AgentName :: term(), Output :: term()) -> callback_result().

after_model/2

(optional)
-callback after_model(Config :: map(), Result :: term()) -> callback_result().

after_tool/4

(optional)
-callback after_tool(ToolName :: binary(), Args :: map(), Context :: map(), Result :: term()) ->
                        callback_result().

before_agent/2

(optional)
-callback before_agent(AgentName :: term(), Input :: term()) -> callback_result().

before_model/3

(optional)
-callback before_model(Config :: map(), Memory :: list(), Tools :: list()) -> callback_result().

before_tool/3

(optional)
-callback before_tool(ToolName :: binary(), Args :: map(), Context :: map()) -> callback_result().

on_agent_end/2

(optional)
-callback on_agent_end(AgentName :: binary(), Output :: term()) -> ok.

on_agent_start/2

(optional)
-callback on_agent_start(AgentName :: binary(), Input :: term()) -> ok.

on_error/1

(optional)
-callback on_error(Error :: term()) -> ok.

on_tool_end/2

(optional)
-callback on_tool_end(ToolName :: binary(), Result :: term()) -> ok.

on_tool_start/2

(optional)
-callback on_tool_start(ToolName :: binary(), Args :: map()) -> ok.

Functions

execute(Handlers, Hook, Args)

-spec execute(Handlers :: [module()], Hook :: atom(), Args :: [term()]) -> ok.

Execute a callback hook across all registered handlers.

run(Handlers, Hook, Args)

-spec run([module()], atom(), [term()]) -> continue | {halt, term()} | {replace, term()}.

Run handlers until one explicitly replaces or halts the operation. Observation-only callbacks return ok or continue. A callback may return {replace, Value} to replace an after-hook result, or {halt, Value} to skip the operation wrapped by a before-hook.