# `GenAgent.Response`
[🔗](https://github.com/genagent/gen_agent/blob/v0.2.0/lib/gen_agent/response.ex#L1)

The result of a completed prompt turn, delivered to `c:GenAgent.handle_response/3`.

A `Response` is built by the state machine after a terminal event
(`:result` or `:error`) arrives from the backend. It carries:

  * `:text` -- the full assembled assistant text for the turn.
  * `:events` -- the complete event log for the turn, in arrival order.
  * `:usage` -- token usage if the backend reported any, otherwise `nil`.
  * `:duration_ms` -- wall-clock time from prompt dispatch to terminal event.
  * `:session_id` -- the backend's session identifier, if any.

# `t`

```elixir
@type t() :: %GenAgent.Response{
  duration_ms: non_neg_integer(),
  events: [GenAgent.Event.t()],
  session_id: String.t() | nil,
  text: String.t(),
  usage: map() | nil
}
```

# `from_events`

```elixir
@spec from_events(
  [GenAgent.Event.t()],
  keyword()
) :: t()
```

Build a `Response` from a completed turn's event list and wall-clock duration.

The `events` list must include exactly one terminal event (`:result` or
`:error`). Text is taken from the `:result` event's `:text` field if
present, otherwise assembled from any `:text` deltas. Usage is taken from
the most recent `:usage` event, if any.

---

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