# `Agentic.Loop.Engine`

Composable pipeline engine for agent loops.

Runs a list of stages as a pipeline. Each stage wraps the next, forming a
middleware chain.

## Usage

    Engine.run(context, [ContextGuard, LLMCall, ModeRouter, ToolExecutor])

## Stop-reason routing

The loop doesn't use a step counter. The `ModeRouter` stage decides
whether to loop (tool_use), terminate (end_turn), or compact (max_tokens).
A hard `max_turns` limit exists only as a safety rail.

# `build_pipeline`

Build a pipeline function from a list of stage modules.

The pipeline is built right-to-left: the last stage in the list wraps the
terminal function, and each preceding stage wraps the one after it.

# `run`

Run the pipeline with the given stages.

Returns `{:ok, result_map}` or `{:error, reason}`.

---

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