Context engine
Rules, conditions, and control-flow helpers for evolving context beyond a single infer call.
Beyond “call the model once,” Mozaik includes a context engine for describing how context should evolve when certain conditions hold. This is useful for structured loops, guarded updates, and building higher-level workflows on top of the same Context primitives.
Building blocks
Exports from the main package include:
Condition/BaseCondition— Predicates over a candidate value (your design-time type is whatever you pass through the rule).Action/AsyncAction— Synchronous or asynchronous transformations of that candidate.Rule/AsyncRule— Pairs a condition with an action;applyruns the action when the condition is satisfied.If— If the condition is satisfied, run the async action and return the result; otherwise return the candidate unchanged.Loop— While the condition stays satisfied, repeatedly run the async action, threading the updated candidate through each iteration.
These types are intentionally small composable pieces: you can wrap inference steps, persistence, compaction, or custom business logic inside AsyncAction implementations.
When to use this
Reach for the context engine when you need explicit control flow over context (e.g. “keep calling the model until a tool returns success” or “only summarize when token usage exceeds a threshold”) without encoding that logic only in imperative spaghetti.
For the exact signatures and generic parameters, refer to the source on GitHub for your installed version.