MCE models every run as a transformer stack that composes state, error handling, and effects into a single algebra. The formal type signature of the AgentMonad encapsulates these capabilities via Monad Transformer composition:
$$ \text{AgentMonad} \cong S \to \text{IO}(\text{Either}(E, (A, S))) $$
The Context Stack
Structure: Monad Transformers
1. StateT: Context as a first-class value. Threads memory and tool outputs without plumbing.
2. EitherT: Deterministic failures. Short-circuits execution upon error with structured info.
3. Task / IO: Explicit effects. Encapsulates async tool calls and side effects.
The Algebraic Interface
Operation: Functor / Applicative / Monad
$\text{map} (f)$: Transform values purely within the context.
$\text{then} (f)$: Sequence dependent steps (The "Railway"). Fails fast if previous step errored.
$\text{gather} ([f])$: Run independent async flows in parallel (Applicative).