Policy Engine¶
techrevati.runtime.policy_engine ¶
Policy Engine — Declarative rules for orchestration decisions.
Composable conditions (And/Or/QualityAt/...) evaluated against a PhaseContext, producing a flat list of PolicyActionData for the caller to dispatch. Rules are sorted by priority (lower first); all matching rules fire.
PolicyCondition ¶
Bases: ABC
Base class for policy conditions. Override matches().
matches
abstractmethod
¶
matches(ctx)
Return whether the condition matches the current phase context.
AgentFailed ¶
AgentFailed(role=None)
RetryExhausted ¶
RetryExhausted(scenario=None)
CostExceeded ¶
CostExceeded(budget_usd)
PolicyAction ¶
Bases: str, Enum
Actions a rule can recommend. The caller is responsible for dispatch.
PolicyRule
dataclass
¶
PolicyRule(name, condition, actions, priority=50)
A named rule with condition, action(s), and priority.
PhaseContext
dataclass
¶
PhaseContext(
phase="",
quality_level=None,
gate_score=0.0,
gate_threshold=0.0,
completed_roles=set(),
failed_roles=set(),
all_roles=set(),
elapsed_seconds=0.0,
retry_exhausted_scenarios=set(),
phase_completed=False,
total_cost_usd=0.0,
)
Input to policy evaluation. Captures current phase state.
PolicyEngine ¶
PolicyEngine(rules)
Evaluates rules against a PhaseContext.
evaluate_async
async
¶
evaluate_async(ctx)
Async sibling of evaluate.
Conditions whose matches is a coroutine function are awaited;
sync conditions are called in place. Falls back to the sync path
if every rule is sync, so existing engines run unchanged.