adk_stateful_plugin behaviour (erlang_adk v0.7.0)

View Source

Behaviour for an isolated, serializable stateful plugin instance.

Stateful callbacks run in bounded workers against an immutable state snapshot. adk_plugin_instance commits the returned state only when that worker completed before the invocation deadline and the caller is still alive. This keeps late or abandoned callbacks from mutating policy state. Instances use PID identity and are supervised as temporary children. They are not restarted after failure because doing so would reset state behind a new PID; owners explicitly create and distribute a replacement instead.

Summary

Types

callback_result/0

-type callback_result() :: adk_plugin:result().

state/0

-type state() :: term().

Callbacks

handle_hook/4

-callback handle_hook(adk_plugin:hook(), Context :: map(), Value :: term(), state()) ->
                         {ok, callback_result(), state()} | {stop, term(), state()}.

init/1

-callback init(Config :: map()) -> {ok, state()} | {stop, term()}.

terminate/2

(optional)
-callback terminate(Reason :: term(), state()) -> term().