Session GenServer — one process per active session.
Holds session state (key-value map) and event history.
Persistence
Sessions can optionally persist to a store. Pass the :store option
to start_link/1:
ADK.Session.start_link(
app_name: "my_app",
user_id: "user1",
session_id: "sess1",
store: {ADK.Session.Store.InMemory, []}
)On init, the session will attempt to load existing data from the store.
Call save/1 to persist the current state, or configure auto_save: true
to auto-save on process termination.
Summary
Functions
Append an event to the session.
Returns a specification to start this module under a supervisor.
Get the full session struct.
Get all session state as a map.
Get all events from the session.
Get a value from session state.
Look up an existing session by app_name, user_id, and session_id.
Put a value into session state.
Persist the current session state to the configured store.
Start a session process.
Start a session under ADK.SessionSupervisor.
Subscribe to session events. The subscriber will receive {:adk_session_event, event} messages.
Unsubscribe from session events.
Types
@type t() :: %ADK.Session{ app_name: String.t(), events: [ADK.Event.t()], id: String.t(), state: map(), user_id: String.t() }
Functions
@spec append_event(pid() | atom(), ADK.Event.t()) :: :ok
Append an event to the session.
Returns a specification to start this module under a supervisor.
See Supervisor.
Get the full session struct.
Get all session state as a map.
@spec get_events(pid() | atom()) :: [ADK.Event.t()]
Get all events from the session.
Get a value from session state.
Look up an existing session by app_name, user_id, and session_id.
Returns {:ok, pid} or :error.
Put a value into session state.
Persist the current session state to the configured store.
@spec start_link(keyword()) :: GenServer.on_start()
Start a session process.
Start a session under ADK.SessionSupervisor.
Returns {:ok, pid} or {:error, reason}.
Subscribe to session events. The subscriber will receive {:adk_session_event, event} messages.
Unsubscribe from session events.