AgentBlueprintProtocol.Federation (Agent Blueprint Protocol v1.1.0)

Copy Markdown View Source

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

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

Summary

Types

t()

The public data type for AgentBlueprintProtocol.Federation.

Functions

Returns the carrier key used for A2A metadata.

Returns canonical JSON bytes for the supplied artifact.

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

Builds a Federation envelope from an A2A carrier value.

Maps an A2A state spelling to the logical state.

Builds a Federation envelope from an MCP carrier value.

Maps an MCP state spelling to the logical state.

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

Returns the field mapping rows for the supported federation carriers.

Returns the carrier key used for MCP metadata.

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

Computes the commitment for a terminal Federation envelope.

Builds an A2A carrier value from a Federation envelope.

Maps a logical state to its A2A spelling.

Builds an MCP carrier value from a Federation envelope.

Maps a logical state to its MCP spelling.

Checks a Federation envelope against the supplied receiver context.

Types

t()

(since 1.0.0)
@type t() :: %AgentBlueprintProtocol.Federation{
  value: AgentBlueprintProtocol.Json.value()
}

The public data type for AgentBlueprintProtocol.Federation.

Functions

a2a_carrier_key()

(since 1.0.0)
@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(arg1)

(since 1.0.0)
@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(binary, bounds \\ Bounds.maximum())

(since 1.0.0)
@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(carrier)

(since 1.0.0)
@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(spelling)

(since 1.0.0)
@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(carrier)

(since 1.0.0)
@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(spelling)

(since 1.0.0)
@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(value)

(since 1.0.0)
@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)

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)
@spec mcp_carrier_key() :: binary()

Returns the carrier key used for MCP metadata.

Example

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

members(revision)

(since 1.1.0)
@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(arg1)

(since 1.0.0)
@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(envelope)

(since 1.0.0)
@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(logical)

(since 1.0.0)
@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(envelope)

(since 1.0.0)
@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(logical)

(since 1.0.0)
@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(arg1, context)

(since 1.0.0)

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