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

The core agent loop.

Sends messages to a provider, executes tool calls, and loops until
the provider signals completion or the turn limit is reached.

This is a pure function — no GenServer, no process overhead.

# `run_loop`

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

Run the agent loop until completion, error, or max turns.

Takes an initialized `State` with messages and returns the
final state with status set to `:completed`, `:error`, or `:max_turns`.

## Options

  - `:streaming` - boolean, whether to use streaming (default: `false`)
  - `:on_chunk` - function called for each streamed chunk (default: no-op)
  - `:on_event` - function called with event envelopes:
    `%{v: 1, seq:, correlation_id:, turn:, ts_ms:, event:, payload:}`
    (default: no-op)

---

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