# `AgentBlueprintProtocol.Federation`
[🔗](https://github.com/baselabs/agent_blueprint_protocol/blob/v1.1.0/lib/agent_blueprint_protocol/federation.ex#L1)

This module validates Federation TaskEnvelope values and converts supported state and carrier shapes.

Use it when reading an envelope or mapping it to a supported task carrier.

This module does not authorize operations.

## Example

```elixir
bytes = File.read!(Application.app_dir(:agent_blueprint_protocol, "priv/examples/federation-envelope.json"))
match?({:ok, %AgentBlueprintProtocol.Federation{}}, AgentBlueprintProtocol.Federation.decode(bytes))
```

# `t`
*since 1.0.0* 

```elixir
@type t() :: %AgentBlueprintProtocol.Federation{
  value: AgentBlueprintProtocol.Json.value()
}
```

The public data type for AgentBlueprintProtocol.Federation.

# `a2a_carrier_key`
*since 1.0.0* 

```elixir
@spec a2a_carrier_key() :: binary()
```

Returns the carrier key used for A2A metadata.

## Example

    iex> is_binary(AgentBlueprintProtocol.Federation.a2a_carrier_key())
    true

# `canonical_bytes`
*since 1.0.0* 

```elixir
@spec canonical_bytes(t()) ::
  {:ok, binary()} | {:error, AgentBlueprintProtocol.Error.t()}
```

Returns canonical JSON bytes for the supplied artifact.

## Example
    iex> with {:ok, envelope} <- AgentBlueprintProtocol.Federation.decode(File.read!(Application.app_dir(:agent_blueprint_protocol, "priv/examples/federation-envelope.json"))), do: match?({:ok, bytes} when is_binary(bytes), AgentBlueprintProtocol.Federation.canonical_bytes(envelope))
    true

# `decode`
*since 1.0.0* 

```elixir
@spec decode(binary(), AgentBlueprintProtocol.Bounds.t() | map()) ::
  {:ok, t()} | {:error, AgentBlueprintProtocol.Error.t()}
```

Decodes a canonical Federation TaskEnvelope and validates its structure and portability.

## Example
    iex> bytes = File.read!(Application.app_dir(:agent_blueprint_protocol, "priv/examples/federation-envelope.json"))
    iex> match?({:ok, %AgentBlueprintProtocol.Federation{}}, AgentBlueprintProtocol.Federation.decode(bytes))
    true
    iex> match?({:ok, %AgentBlueprintProtocol.Federation{}}, AgentBlueprintProtocol.Federation.decode(bytes, %{bytes: 5000}))
    true

# `from_a2a_carrier`
*since 1.0.0* 

```elixir
@spec from_a2a_carrier(AgentBlueprintProtocol.Json.value()) ::
  {:ok, t()} | {:error, AgentBlueprintProtocol.Error.t()}
```

Builds a Federation envelope from an A2A carrier value.

## Example
    iex> with {:ok, envelope} <- AgentBlueprintProtocol.Federation.decode(File.read!(Application.app_dir(:agent_blueprint_protocol, "priv/examples/federation-envelope.json"))), {:ok, carrier} <- AgentBlueprintProtocol.Federation.to_a2a_carrier(envelope), do: match?({:ok, %AgentBlueprintProtocol.Federation{}}, AgentBlueprintProtocol.Federation.from_a2a_carrier(carrier))
    true

# `from_a2a_state`
*since 1.0.0* 

```elixir
@spec from_a2a_state(binary()) ::
  {:ok, atom()} | {:error, AgentBlueprintProtocol.Error.t()}
```

Maps an A2A state spelling to the logical state.

## Example

    iex> AgentBlueprintProtocol.Federation.from_a2a_state("TASK_STATE_COMPLETED")
    {:ok, :completed}

# `from_mcp_carrier`
*since 1.0.0* 

```elixir
@spec from_mcp_carrier(AgentBlueprintProtocol.Json.value()) ::
  {:ok, t()} | {:error, AgentBlueprintProtocol.Error.t()}
```

Builds a Federation envelope from an MCP carrier value.

## Example
    iex> with {:ok, envelope} <- AgentBlueprintProtocol.Federation.decode(File.read!(Application.app_dir(:agent_blueprint_protocol, "priv/examples/federation-envelope.json"))), {:ok, carrier} <- AgentBlueprintProtocol.Federation.to_mcp_carrier(envelope), do: match?({:ok, %AgentBlueprintProtocol.Federation{}}, AgentBlueprintProtocol.Federation.from_mcp_carrier(carrier))
    true

# `from_mcp_state`
*since 1.0.0* 

```elixir
@spec from_mcp_state(binary()) ::
  {:ok, atom()} | {:error, AgentBlueprintProtocol.Error.t()}
```

Maps an MCP state spelling to the logical state.

## Example

    iex> AgentBlueprintProtocol.Federation.from_mcp_state("completed")
    {:ok, :completed}

# `from_value`
*since 1.0.0* 

```elixir
@spec from_value(AgentBlueprintProtocol.Json.value()) ::
  {:ok, t()} | {:error, AgentBlueprintProtocol.Error.t()}
```

Validates a tagged JSON value and wraps it in this artifact type.

## Example
    iex> with {:ok, value} <- AgentBlueprintProtocol.Json.decode(File.read!(Application.app_dir(:agent_blueprint_protocol, "priv/examples/federation-envelope.json"))), do: match?({:ok, %AgentBlueprintProtocol.Federation{}}, AgentBlueprintProtocol.Federation.from_value(value))
    true

# `mapping`
*since 1.0.0* 

```elixir
@spec mapping() :: [AgentBlueprintProtocol.Federation.Mapping.Row.t()]
```

Returns the field mapping rows for the supported federation carriers.

## Example

    iex> Enum.all?(AgentBlueprintProtocol.Federation.mapping(), &is_struct(&1, AgentBlueprintProtocol.Federation.Mapping.Row))
    true

# `mcp_carrier_key`
*since 1.0.0* 

```elixir
@spec mcp_carrier_key() :: binary()
```

Returns the carrier key used for MCP metadata.

## Example

    iex> is_binary(AgentBlueprintProtocol.Federation.mcp_carrier_key())
    true

# `members`
*since 1.1.0* 

```elixir
@spec members(integer()) ::
  {:ok, [binary()]} | {:error, AgentBlueprintProtocol.Error.t()}
```

  Returns the sorted Federation TaskEnvelope member names for a supported protocol revision.

  Use this vocabulary when inspecting TaskEnvelope members. For
  `AgentBlueprintProtocol.Negotiation.Support.core_fields`, a host that
  supports every core field declares the union of
  `AgentBlueprintProtocol.Blueprint.members/1` and
  `AgentBlueprintProtocol.Deployment.members/1` for that revision.

  Revision 1 is supported. Other integers return `:protocol_revision_unsupported`
  with subject `["protocol_revision"]`; non-integers return `:invalid_type`.

  ## Example

      iex> with {:ok, names} <- AgentBlueprintProtocol.Federation.members(1), do: length(names)
      23

# `terminal_commitment`
*since 1.0.0* 

```elixir
@spec terminal_commitment(t()) ::
  {:ok, AgentBlueprintProtocol.Digest.t()}
  | {:error, AgentBlueprintProtocol.Error.t()}
```

Computes the commitment for a terminal Federation envelope.

## Example
    iex> with {:ok, envelope} <- AgentBlueprintProtocol.Federation.decode(File.read!(Application.app_dir(:agent_blueprint_protocol, "priv/examples/federation-envelope.json"))), do: match?({:ok, %AgentBlueprintProtocol.Digest{algorithm: :sha256, bytes: <<_::256>>}}, AgentBlueprintProtocol.Federation.terminal_commitment(envelope))
    true

# `to_a2a_carrier`
*since 1.0.0* 

```elixir
@spec to_a2a_carrier(t()) ::
  {:ok, AgentBlueprintProtocol.Json.value()}
  | {:error, AgentBlueprintProtocol.Error.t()}
```

Builds an A2A carrier value from a Federation envelope.

## Example
    iex> with {:ok, envelope} <- AgentBlueprintProtocol.Federation.decode(File.read!(Application.app_dir(:agent_blueprint_protocol, "priv/examples/federation-envelope.json"))), do: match?({:ok, {:object, _}}, AgentBlueprintProtocol.Federation.to_a2a_carrier(envelope))
    true

# `to_a2a_state`
*since 1.0.0* 

```elixir
@spec to_a2a_state(atom()) ::
  {:ok, binary()} | {:error, AgentBlueprintProtocol.Error.t()}
```

Maps a logical state to its A2A spelling.

## Example

    iex> AgentBlueprintProtocol.Federation.to_a2a_state(:completed)
    {:ok, "TASK_STATE_COMPLETED"}

# `to_mcp_carrier`
*since 1.0.0* 

```elixir
@spec to_mcp_carrier(t()) ::
  {:ok, AgentBlueprintProtocol.Json.value()}
  | {:error, AgentBlueprintProtocol.Error.t()}
```

Builds an MCP carrier value from a Federation envelope.

## Example
    iex> with {:ok, envelope} <- AgentBlueprintProtocol.Federation.decode(File.read!(Application.app_dir(:agent_blueprint_protocol, "priv/examples/federation-envelope.json"))), do: match?({:ok, {:object, _}}, AgentBlueprintProtocol.Federation.to_mcp_carrier(envelope))
    true

# `to_mcp_state`
*since 1.0.0* 

```elixir
@spec to_mcp_state(atom()) ::
  {:ok, binary()} | {:error, AgentBlueprintProtocol.Error.t()}
```

Maps a logical state to its MCP spelling.

## Example

    iex> AgentBlueprintProtocol.Federation.to_mcp_state(:completed)
    {:ok, "completed"}

# `verify_commitment`
*since 1.0.0* 

```elixir
@spec verify_commitment(t(), AgentBlueprintProtocol.Federation.Context.t()) ::
  {:ok, AgentBlueprintProtocol.Federation.Context.receipt_fact()}
  | {:error, AgentBlueprintProtocol.Error.t()}
```

Checks a Federation envelope against the supplied receiver context.

## Example
    iex> with {:ok, envelope} <- AgentBlueprintProtocol.Federation.decode(File.read!(Application.app_dir(:agent_blueprint_protocol, "priv/examples/federation-envelope.json"))), do: match?({:error, %AgentBlueprintProtocol.Error{}}, AgentBlueprintProtocol.Federation.verify_commitment(envelope, %AgentBlueprintProtocol.Federation.Context{}))
    true

---

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