ExAgent.Response (ExAgent v0.3.0)

Copy Markdown View Source

A completed assistant turn.

Returned by ExAgent.chat/3 and by ExAgent.collect/1 on a chunk stream, so streaming and non-streaming share one downstream code path.

{:ok, response} = ExAgent.chat(agent, "Explain OTP")
response.content            #=> "OTP is ..."
response.usage.total_tokens #=> 412
response.finish_reason      #=> :stop

:message holds the ExAgent.Message appended to conversation history; :content is a shortcut for response.message.content.

:thinking carries a reasoning trace when the model emitted one. It is deliberately kept out of :message - reasoning is not conversation history, and replaying it corrupts the next turn.

Summary

Functions

Wraps an assistant message in a response.

Types

t()

@type t() :: %ExAgent.Response{
  content: String.t(),
  finish_reason: ExAgent.Chunk.finish_reason(),
  message: ExAgent.Message.t(),
  thinking: String.t() | nil,
  tool_calls: [map()] | nil,
  usage: usage()
}

usage()

@type usage() :: %{
  optional(:input_tokens) => non_neg_integer() | nil,
  optional(:output_tokens) => non_neg_integer() | nil,
  optional(:total_tokens) => non_neg_integer() | nil
}

Functions

new(message, attrs \\ [])

@spec new(
  ExAgent.Message.t(),
  keyword()
) :: t()

Wraps an assistant message in a response.

Examples

iex> {:ok, message} = ExAgent.Message.new(role: :assistant, content: "hi")
iex> ExAgent.Response.new(message).content
"hi"