# `Alloy.Agent.Events`
[🔗](https://github.com/alloy-ex/alloy/blob/v0.10.1/lib/alloy/agent/events.ex#L1)

Event envelope construction and runtime opts normalization.

Builds v1 event envelopes, manages sequence counters, and derives
correlation IDs. Extracted from `Alloy.Agent.Turn` to separate
event plumbing from agent loop control flow.

# `build_correlation_id`

```elixir
@spec build_correlation_id(Alloy.Agent.State.t()) :: binary()
```

Derive a correlation ID from the agent state's context.

Precedence: `context[:request_id]` > `context[:correlation_id]` >
generated from `agent_id`.

# `emit`

```elixir
@spec emit(keyword(), non_neg_integer(), term()) :: :ok
```

Emit an event envelope.

Builds a v1 envelope from the raw event, calls the `on_event` callback,
and fires a `:telemetry` event.

# `normalize_opts`

```elixir
@spec normalize_opts(
  Alloy.Agent.State.t(),
  keyword()
) :: keyword()
```

Normalize runtime opts for event emission.

Ensures `:on_event`, `:event_seq_ref`, and `:event_correlation_id`
are present in the opts keyword list.

---

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