# `Raxol.AgentClientProtocol.Rpc.Response`
[🔗](https://github.com/DROOdotFOO/raxol-agent/blob/raxol_agent_client_protocol-v0.1.0/packages/raxol_agent_client_protocol/lib/raxol/agent_client_protocol/rpc.ex#L120)

JSON-RPC 2.0 Response object: either a result or an error, represented as
a tagged tuple `{:result, id, result}` | `{:error, id, error}` rather than
a struct (a Response is a discriminated union at the wire level, and the
two shapes are mutually exclusive per spec).

`id` may legitimately be `nil` — a server-side parse error or
invalid-request error detected before any request id could be read is
answered with a `null`-id error response; this is not an absent id, it is
the spec-mandated value for an uncorrelatable error.

Ported from the MIT `f1729/agent_client_protocol` (c) 2025 f1729; see NOTICE.md.

# `t`

```elixir
@type t() ::
  {:result, Raxol.AgentClientProtocol.Rpc.RequestId.t(), any()}
  | {:error, Raxol.AgentClientProtocol.Rpc.RequestId.t(),
     Raxol.AgentClientProtocol.Error.t()}
```

# `error`

```elixir
@spec error(
  Raxol.AgentClientProtocol.Rpc.RequestId.t(),
  Raxol.AgentClientProtocol.Error.t()
) :: t()
```

# `from_json`

```elixir
@spec from_json(term()) :: {:ok, t()} | {:error, :invalid_request}
```

Decode a Response object. Total: a missing/wrong-typed `id`, or an
unparseable `error` payload, returns `{:error, :invalid_request}` rather
than raising or crashing on a hard match.

# `new`

```elixir
@spec new(
  Raxol.AgentClientProtocol.Rpc.RequestId.t(),
  {:ok, any()} | {:error, Raxol.AgentClientProtocol.Error.t()}
) :: t()
```

# `result`

```elixir
@spec result(Raxol.AgentClientProtocol.Rpc.RequestId.t(), any()) :: t()
```

# `to_json`

```elixir
@spec to_json(t()) :: map()
```

---

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