# `Sagents.Supervisor`

Top-level supervisor for Sagents infrastructure.

Starts the process registry, agent dynamic supervisor, and filesystem dynamic
supervisor as children under a single supervisor.

## Why use this in your application?

OTP shuts down supervision tree children in reverse start order. By adding
`Sagents.Supervisor` to your application's supervision tree **after** your
Repo and PubSub, you ensure that agent processes terminate **before** Repo and
PubSub shut down. This allows agents to persist state and broadcast shutdown
events during `terminate/2`.

## Usage

Add `Sagents.Supervisor` to your application's supervision tree after your
Repo, PubSub, and Presence:

    # lib/my_app/application.ex
    def start(_type, _args) do
      children = [
        MyApp.Repo,
        {Phoenix.PubSub, name: MyApp.PubSub},
        MyAppWeb.Presence,
        Sagents.Supervisor,
        MyAppWeb.Endpoint
      ]

      opts = [strategy: :one_for_one, name: MyApp.Supervisor]
      Supervisor.start_link(children, opts)
    end

## What it starts

- `Sagents.ProcessRegistry` — Process registry (local `Registry` or
  `Horde.Registry`)
- Agents dynamic supervisor — For managing `AgentSupervisor` instances
- Filesystem dynamic supervisor — For managing `FileSystemServer` instances

The backend (local vs Horde) is determined by application config:

    # Single-node (default — no config needed)
    config :sagents, :distribution, :local

    # Distributed cluster
    config :sagents, :distribution, :horde

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `start_link`

---

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