# `A2UICore.Message.RendererToAgent`
[🔗](https://github.com/a2ui-elixir/a2ui/blob/v0.1.1/umbrella/apps/a2ui_core/lib/a2ui_core/message/renderer_to_agent.ex#L1)

Builders for the messages a renderer sends to the agent
(`renderer_to_agent.json`):

  * `action/2` — a user action on a component;
  * `error/3` — a renderer-side error, about a surface or a function call;
  * `call_agent_function/4` — the renderer asks the agent to run a
    function (v1.0);
  * `function_response/3` — the result of an agent's `callRendererFunction`
    (v1.0).

Every builder returns the wire map, version included (`:version`,
`"v1.0"` unless given), ready to be encoded by a transport.

    iex> A2UICore.Message.RendererToAgent.function_response("call-1", {:ok, 42})
    %{
      "version" => "v1.0",
      "rendererFunctionResponse" => %{"functionCallId" => "call-1", "value" => 42}
    }

# `action`
*since 0.1.0* 

```elixir
@spec action(map(), keyword()) :: map()
```

An `action` message carrying `event`, the map
`A2UICore.State.Surface.dispatch_action/4` returns.

# `call_agent_function`
*since 0.1.0* 

```elixir
@spec call_agent_function(String.t(), String.t(), map(), keyword()) :: map()
```

A `callAgentFunction` message: the renderer asks the agent to run
`call` (a function call object, `"@call"`/`"catalogId"`/`"args"`).

# `error`
*since 0.1.0* 

```elixir
@spec error(String.t(), String.t(), keyword()) :: map()
```

An `error` message. Options: `:surface_id`, `:function_call_id` and
`:path`, each included when present, and `:version`.

The schema requires a validation error (`VALIDATION_FAILED`,
`UNALLOWED_PARENT`, `UNALLOWED_CHILD`) to carry `surfaceId` and `path`,
and any other error to carry exactly one of `surfaceId` and
`functionCallId`.

# `function_response`
*since 0.1.0* 

```elixir
@spec function_response(
  String.t(),
  {:ok, term()} | {:error, String.t(), String.t()},
  keyword()
) ::
  map()
```

A `rendererFunctionResponse` message: `{:ok, value}` for a result
(`value` is always present, `nil` for a void function) or
`{:error, code, message}`.

---

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