Agentic.Loop.Phase (agentic v0.2.2)

Copy Markdown

Phase state machine with per-mode validated transitions.

All phase transitions in stages go through transition/2 — never direct ctx.phase mutation. This gives compile-time safety via transition!/2 in hot paths and {:error, _} returns for graceful handling elsewhere.

No external dependencies — plain data + pattern matching.

Summary

Functions

Return the initial phase for a given mode.

Attempt a phase transition. Returns {:ok, updated_context} or {:error, {:invalid_transition, mode, from, to}}.

Same as transition/2 but raises on invalid transition.

Check if a transition is valid without performing it.

Types

mode()

@type mode() :: :agentic | :agentic_planned | :turn_by_turn | :conversational

phase()

@type phase() :: :init | :plan | :execute | :review | :verify | :done

Functions

initial_phase(atom)

@spec initial_phase(mode()) :: phase()

Return the initial phase for a given mode.

mode_transitions()

phases()

transition(ctx, next_phase)

Attempt a phase transition. Returns {:ok, updated_context} or {:error, {:invalid_transition, mode, from, to}}.

transition!(ctx, next_phase)

Same as transition/2 but raises on invalid transition.

valid?(ctx, next_phase)

Check if a transition is valid without performing it.