# `ADK.Phoenix.Controller`
[🔗](https://github.com/zeroasterisk/adk-elixir/blob/main/lib/adk/phoenix/controller.ex#L1)

Helper functions for building Phoenix controllers that interact with ADK agents.

These are plain functions — no `use` macro, no Phoenix dependency at compile time.
They expect a `Plug.Conn` and work with any Phoenix controller.

## Usage

    defmodule MyAppWeb.AgentController do
      use MyAppWeb, :controller

      def run(conn, params) do
        runner = %ADK.Runner{app_name: "my_app", agent: MyApp.agent()}
        ADK.Phoenix.Controller.run(conn, runner, params)
      end

      def stream(conn, params) do
        runner = %ADK.Runner{app_name: "my_app", agent: MyApp.agent()}
        ADK.Phoenix.Controller.stream_sse(conn, runner, params)
      end
    end

# `run`

```elixir
@spec run(Plug.Conn.t(), ADK.Runner.t(), map(), keyword()) :: Plug.Conn.t()
```

Run an agent synchronously and return JSON events.

Expects `params` to contain `"message"`, and optionally `"user_id"` and `"session_id"`.
Returns a JSON response with `%{events: [...]}`.

# `stream_sse`

```elixir
@spec stream_sse(Plug.Conn.t(), ADK.Runner.t(), map(), keyword()) :: Plug.Conn.t()
```

Run an agent and stream events as Server-Sent Events (SSE).

Each event is sent as an SSE `data:` line with JSON payload.
The stream ends with a `data: [DONE]` sentinel.

---

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