Alloy.Result (alloy v0.7.4)

Copy Markdown View Source

Structured result from an agent run.

Returned by Alloy.run/2 and Alloy.Agent.Server.chat/3. Implements Access for bracket-syntax compatibility (result[:text]).

Fields

  • :text — the final assistant text (or nil if the model returned no text)
  • :messages — full conversation history
  • :usage — accumulated %Alloy.Usage{} token counts
  • :tool_calls — list of tool execution metadata maps
  • :status — final run status (:completed, :max_turns, :error, :halted)
  • :turns — number of agent loop iterations
  • :error — error term (or nil on success)
  • :request_id — correlation ID for async requests (or nil for sync)

Summary

Functions

Build a Result from a final State.

Types

t()

@type t() :: %Alloy.Result{
  error: term() | nil,
  messages: [Alloy.Message.t()],
  request_id: binary() | nil,
  status: Alloy.Agent.State.status(),
  text: String.t() | nil,
  tool_calls: [map()],
  turns: non_neg_integer(),
  usage: Alloy.Usage.t()
}

Functions

from_state(state)

@spec from_state(Alloy.Agent.State.t()) :: t()

Build a Result from a final State.

Extracts text, messages, usage, tool calls, status, turns, and error from the state. The request_id is left as nil — async callers overlay it via %{result | request_id: id}.