# `Wardrik.Definition`

What an agent is and what it may do: an agent file's frontmatter, as a struct.

    definition =
      Wardrik.Definition.new!(
        model: "anthropic:claude-haiku-4-5",
        instructions: "You watch the incident queue.",
        tools: ["linear/*"],
        policy: [ask: ["linear/*"]]
      )

    Wardrik.Agent.define(scope, "acme/triage", definition)
    #=> {:ok, %Wardrik.Agent{id: "acme/triage", status: :idle, ...}}

Its fields follow the protocol's `agent_definition` schema. Tools and policies it names must be
ones Wardrik offers. See `Wardrik.start_link/1`.

`:policy`, `:workspace`, `:context`, `:retries`, `:compaction` and `:notify` stay as the
protocol's JSON. Each of `:triggers` is a `Wardrik.Trigger`.

# `t`

```elixir
@type t() :: %Wardrik.Definition{
  channels: term(),
  compaction: term(),
  context: term(),
  description: term(),
  display_name: term(),
  idle_timeout: term(),
  instructions: term(),
  max_iterations: term(),
  model: term(),
  notify: term(),
  policy: term(),
  retries: term(),
  timeout: term(),
  tools: term(),
  triggers: term(),
  workspace: term()
}
```

# `from_json`

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

Builds one from the protocol's JSON.

# `named`

```elixir
@spec named(map()) :: map()
```

Names each unnamed trigger by its position: `trigger-1`, `trigger-2`, and so on.

Takes and returns the definition as the protocol's JSON.

# `new!`

```elixir
@spec new!(keyword() | map()) :: t()
```

Builds a definition from a keyword list or map. Raises `ArgumentError` if it doesn't match the schema.

# `principal`

```elixir
@spec principal(String.t()) :: WardrikCore.Principal.t()
```

Returns the principal the agent `id` acts as: its user, as `acme/@maria`, or its org, as `acme`.

Raises `MatchError` if `id` isn't an agent ID.

# `to_json`

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

Returns it as the protocol's JSON, without fields that are `nil`.

---

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