# `AshAi.Actions.Result`
[🔗](https://github.com/ash-project/ash_ai/blob/v1.1.0/lib/ash_ai/actions/result.ex#L5)

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 the `of` type
- `model` - the model that answered, as reported by the provider (for example
  the versioned id behind a `jev-latest` alias)
- `usage` - token usage as normalized by ReqLLM; for prompt actions this sums the
  tool loop iterations and the final generation
- `provider_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.

# `t`

```elixir
@type t() :: %AshAi.Actions.Result{
  model: String.t() | nil,
  provider_meta: map() | nil,
  result: term(),
  usage: map() | nil
}
```

# `handle_change?`

# `prepare_change?`

# `unwrap`

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

# `wrap`

```elixir
@spec wrap(term(), map() | nil, map() | nil) :: map()
```

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.

# `wrapped?`

```elixir
@spec wrapped?(Ash.Type.t() | nil) :: boolean()
```

Returns true if `returns` is this wrapper type.

---

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