# `ADK.Session`
[🔗](https://github.com/zeroasterisk/adk-elixir/blob/main/lib/adk/session.ex#L1)

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.

# `t`

```elixir
@type t() :: %ADK.Session{
  app_name: String.t(),
  events: [ADK.Event.t()],
  id: String.t(),
  state: map(),
  user_id: String.t()
}
```

# `append_event`

```elixir
@spec append_event(pid() | atom(), ADK.Event.t()) :: :ok | {:error, :noproc}
```

Append an event to the session.

Returns `:ok` on success, `{:error, :noproc}` if the session process
is no longer alive (e.g., stopped by a concurrent runner).

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `get`

```elixir
@spec get(pid() | atom()) :: {:ok, t()}
```

Get the full session struct.

# `get_all_state`

```elixir
@spec get_all_state(pid() | atom()) :: map()
```

Get all session state as a map.

# `get_events`

```elixir
@spec get_events(pid() | atom()) :: [ADK.Event.t()]
```

Get all events from the session.

# `get_state`

```elixir
@spec get_state(pid() | atom(), term()) :: term() | nil
```

Get a value from session state.

# `lookup`

```elixir
@spec lookup(String.t(), String.t(), String.t()) :: {:ok, pid()} | :error
```

Look up an existing session by app_name, user_id, and session_id.

Returns `{:ok, pid}` or `:error`.

# `put_state`

```elixir
@spec put_state(pid() | atom(), term(), term()) :: :ok
```

Put a value into session state.

# `save`

```elixir
@spec save(pid() | atom()) :: :ok | {:error, term()}
```

Persist the current session state to the configured store.

# `start_link`

```elixir
@spec start_link(keyword()) :: GenServer.on_start()
```

Start a session process.

# `start_supervised`

```elixir
@spec start_supervised(keyword()) :: {:ok, pid()} | {:error, term()}
```

Start a session under `ADK.SessionSupervisor`.

Returns `{:ok, pid}` or `{:error, reason}`.

# `subscribe`

```elixir
@spec subscribe(pid() | atom()) :: :ok
```

Subscribe to session events. The subscriber will receive `{:adk_session_event, event}` messages.

# `unsubscribe`

```elixir
@spec unsubscribe(pid() | atom()) :: :ok
```

Unsubscribe from session events.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
