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.
Summary
Functions
Run the agent loop until completion, error, or max turns.
Functions
@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.
Each turn is reported with :telemetry.span/3 as [:alloy, :turn, :start]
and [:alloy, :turn, :stop], or [:alloy, :turn, :exception] when the turn
raises. A turn's stop event fires when that turn ends; its :status is
:running when the loop goes on to another turn and the final status
otherwise.
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)