GenAgent.Response (GenAgent v0.2.0)

Copy Markdown View Source

The result of a completed prompt turn, delivered to 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.

Summary

Functions

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

Types

t()

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

Functions

from_events(events, opts \\ [])

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