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

This module intersects Blueprint, Deployment, and host bound sets.

Use it when an application needs effective bounds and records of any narrowing.

This module does not authorize operations.

## Example

```elixir
base = %{
  approval_trait: :none,
  authority_trait: :none,
  classification_ceiling: %{ordinal: :internal, markers: MapSet.new([])},
  disclosure_ceiling: :summary,
  effect_impact_ceiling: :ordinary,
  max_attempts: 3,
  max_concurrency: 2,
  max_cost: %{amount: 1000, currency: "USD"},
  max_depth: 8,
  max_descendants: 64,
  max_elapsed_ms: 60_000,
  max_fan_out: 4,
  max_tokens: 100_000
}
{:ok, bounds} = AgentBlueprintProtocol.BoundsAlgebra.BoundSet.new(base)
sources = %AgentBlueprintProtocol.BoundsAlgebra.Sources{blueprint: bounds, deployment: bounds, host: bounds}
match?({:ok, %AgentBlueprintProtocol.BoundsAlgebra.Result{}}, AgentBlueprintProtocol.BoundsAlgebra.intersect(sources))
```

# `from_blueprint`
*since 1.0.0* 

```elixir
@spec from_blueprint(AgentBlueprintProtocol.Blueprint.t()) ::
  {:ok, AgentBlueprintProtocol.BoundsAlgebra.BoundSet.t()}
  | {:error, AgentBlueprintProtocol.Error.t()}
```

Builds a bound set from a Blueprint.

## Example

```elixir
{:ok, blueprint} =
  AgentBlueprintProtocol.Blueprint.decode(
    File.read!(Application.app_dir(:agent_blueprint_protocol, "priv/examples/echo-blueprint.json"))
  )

match?({:ok, %AgentBlueprintProtocol.BoundsAlgebra.BoundSet{}}, AgentBlueprintProtocol.BoundsAlgebra.from_blueprint(blueprint))
```

# `from_deployment`
*since 1.0.0* 

```elixir
@spec from_deployment(AgentBlueprintProtocol.Deployment.t()) ::
  {:ok, AgentBlueprintProtocol.BoundsAlgebra.BoundSet.t()}
  | {:error, AgentBlueprintProtocol.Error.t()}
```

Builds a bound set from a Deployment.

## Example

```elixir
{:ok, deployment} =
  AgentBlueprintProtocol.Deployment.decode(
    File.read!(Application.app_dir(:agent_blueprint_protocol, "priv/examples/echo-deployment.json"))
  )

match?({:ok, %AgentBlueprintProtocol.BoundsAlgebra.BoundSet{}}, AgentBlueprintProtocol.BoundsAlgebra.from_deployment(deployment))
```

# `intersect`
*since 1.0.0* 

```elixir
@spec intersect(AgentBlueprintProtocol.BoundsAlgebra.Sources.t()) ::
  {:ok, AgentBlueprintProtocol.BoundsAlgebra.Result.t()}
  | {:error, AgentBlueprintProtocol.Error.t()}
```

Intersects the Blueprint, Deployment, and host bound sources.

## Example

```elixir
base = %{
  approval_trait: :none,
  authority_trait: :none,
  classification_ceiling: %{ordinal: :internal, markers: MapSet.new([])},
  disclosure_ceiling: :summary,
  effect_impact_ceiling: :ordinary,
  max_attempts: 3,
  max_concurrency: 2,
  max_cost: %{amount: 1000, currency: "USD"},
  max_depth: 8,
  max_descendants: 64,
  max_elapsed_ms: 60_000,
  max_fan_out: 4,
  max_tokens: 100_000
}

{:ok, bounds} = AgentBlueprintProtocol.BoundsAlgebra.BoundSet.new(base)
sources = %AgentBlueprintProtocol.BoundsAlgebra.Sources{
  blueprint: bounds,
  deployment: bounds,
  host: bounds
}
AgentBlueprintProtocol.BoundsAlgebra.intersect(sources)
```

# `widens?`
*since 1.0.0* 

```elixir
@spec widens?(
  AgentBlueprintProtocol.BoundsAlgebra.BoundSet.t(),
  AgentBlueprintProtocol.BoundsAlgebra.BoundSet.t()
) :: boolean()
```

Reports whether one bound set is wider than another.

## Example

```elixir
base = %{
  approval_trait: :none,
  authority_trait: :none,
  classification_ceiling: %{ordinal: :internal, markers: MapSet.new([])},
  disclosure_ceiling: :summary,
  effect_impact_ceiling: :ordinary,
  max_attempts: 3,
  max_concurrency: 2,
  max_cost: %{amount: 1000, currency: "USD"},
  max_depth: 8,
  max_descendants: 64,
  max_elapsed_ms: 60_000,
  max_fan_out: 4,
  max_tokens: 100_000
}

{:ok, bounds} = AgentBlueprintProtocol.BoundsAlgebra.BoundSet.new(base)
AgentBlueprintProtocol.BoundsAlgebra.widens?(bounds, bounds)
```

---

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