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

This module validates and evaluates the protocol predicate algebra.

Use it when handling deterministic predicates over named input ports.

This module does not authorize operations.

## Example

```elixir
predicate = {:object, [{"op", {:string, "present"}}, {"path", {:array, [{:string, "request"}]}}]}
AgentBlueprintProtocol.Predicate.validate(predicate, ["request"])
```

# `evaluate`
*since 1.0.0* 

```elixir
@spec evaluate(AgentBlueprintProtocol.Json.value(), %{
  optional(binary()) =&gt; AgentBlueprintProtocol.Json.value()
}) :: {:ok, boolean()} | {:error, AgentBlueprintProtocol.Error.t()}
```

Evaluates a predicate against the supplied port values.

## Example

    iex> predicate = {:object, [{"op", {:string, "eq"}}, {"path", {:array, [{:string, "request"}, {:string, "name"}]}}, {"value", {:string, "Ada"}}]}
    iex> ports = %{"request" => {:object, [{"name", {:string, "Ada"}}]}}
    iex> AgentBlueprintProtocol.Predicate.evaluate(predicate, ports)
    {:ok, true}

# `validate`
*since 1.0.0* 

```elixir
@spec validate(AgentBlueprintProtocol.Json.value(), [binary()] | :any_root) ::
  :ok | {:error, AgentBlueprintProtocol.Error.t()}
```

Checks whether the supplied predicate has a valid shape for the given ports.

## Example

    iex> predicate = {:object, [{"op", {:string, "eq"}}, {"path", {:array, [{:string, "request"}, {:string, "name"}]}}, {"value", {:string, "Ada"}}]}
    iex> AgentBlueprintProtocol.Predicate.validate(predicate, ["request"])
    :ok

---

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