Wraps the result of a prompt-backed or evaluation action with model metadata.
By default those actions return only the value the model produced. Declare this
type as the action's return type, with of naming the real return type, to also
receive which model answered and what it cost. The action plans against the inner
type exactly as it would without the wrapper.
Fields
result- the value, cast to theoftypemodel- the model that answered, as reported by the provider (for example the versioned id behind ajev-latestalias)usage- token usage as normalized by ReqLLM; for prompt actions this sums the tool loop iterations and the final generationprovider_meta- provider-specific response metadata
Example
action :triage, AshAi.Actions.Result do
argument :ticket, :string, allow_nil?: false
constraints of: AshAi.Evaluate.Judgments,
constraints: [
fields: [
urgent: [type: :boolean, description: "Does `ticket` convey urgency?"]
]
]
run evaluate("typesafe:jev-latest")
end
%AshAi.Actions.Result{result: %{urgent: %AshAi.Evaluate.Noul{}}, model: "jev-1.13.0", usage: %{input_tokens: 312, ...}}For cross-cutting logging or cost accounting, prefer ReqLLM telemetry
([:req_llm, :token_usage] and [:req_llm, :request, :stop]) over changing
return types.
Summary
Functions
Returns the type an action actually produces: the of type when returns is
this wrapper, otherwise returns itself.
Builds the map to cast into this type from a result and a ReqLLM response (or
any map with model, usage, and provider_meta keys). usage overrides the
response's usage when given, for callers that sum several requests.
Returns true if returns is this wrapper type.
Types
Functions
@spec unwrap(Ash.Type.t() | nil, Keyword.t()) :: {Ash.Type.t() | nil, Keyword.t()}
Returns the type an action actually produces: the of type when returns is
this wrapper, otherwise returns itself.
Builds the map to cast into this type from a result and a ReqLLM response (or
any map with model, usage, and provider_meta keys). usage overrides the
response's usage when given, for callers that sum several requests.
@spec wrapped?(Ash.Type.t() | nil) :: boolean()
Returns true if returns is this wrapper type.