ADK.Phoenix.Controller (ADK v0.0.1-alpha.1)

Copy Markdown View Source

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

Summary

Functions

Run an agent synchronously and return JSON events.

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

Functions

run(conn, runner, params, opts \\ [])

@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(conn, runner, params, opts \\ [])

@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.