Runtime¶
This is where decisions happen. Module holds one compiled policy and
the current state of one entity; Module.decide(event, evidence) takes
one step and returns a DecisionRecord. Pipeline runs several modules
on the same input and compose_parent combines their records (act only
if every child acted; any abstain wins over any degrade). Open this page when you need the exact signature
of decide, from_expr, restore or reset.
Public here: Module, Pipeline, compose_parent. A Module is not
thread-safe: restore state per request under a lock, or keep one module
per worker. Step-by-step walk-through:
One decision, step by step; combining
modules: Composing modules.
module ¶
Encapsulated decision module.
A module owns a grammar (optional), a statechart, an envelope, and the
six-check conjunction. Parent modules compose by feeding child
DecisionRecords as evidence, not by reaching into child state.
Module
dataclass
¶
Module(
name: str,
chart: Statechart,
envelope: Envelope = P_EXACT,
limits: Limits = DEFAULT_LIMITS,
expr: Expr | None = None,
star_h: int = 0,
)
Encapsulated decision module.
Owns a statechart, an optional source expression, an envelope, and
the six-check conjunction. Compile-time solvers (star-height,
Zielonka, Karp) run in __post_init__. Per-event work is
decide.
state
property
¶
Current chart state. Persist this on the worker; restore on the next request.
from_expr
classmethod
¶
from_expr(
name: str,
expr: Expr,
*,
envelope: Envelope = P_EXACT,
limits: Limits = DEFAULT_LIMITS,
) -> Module
Compile a grammar expression to a module.
Checks star-height, builds a Thompson NFA / subset DFA, derives
a statechart, and solves the game. Raises StarHeightError or
CompileError before any decide call.
Source code in src/grounded_decision/runtime/module.py
peek_proposed_action ¶
The action decide would propose for this event, without deciding.
Does not change the state. Useful when the evidence depends on the
proposed action, for example
LearnedParameters.apply(evidence, proposed_action), which picks
the calibration scores for that action.
Source code in src/grounded_decision/runtime/module.py
restore ¶
Load a previously persisted state name. Unknown names raise KeyError.
Source code in src/grounded_decision/runtime/module.py
decide ¶
decide(
event: Event, evidence: EvidenceSnapshot
) -> DecisionRecord
Take one step.
Advances the statechart on event.name, then evaluates the
six checks (certificate, game, reconstruction, threshold,
conformal, support). Any failed channel yields Verdict.ABSTAIN with
proposed_action filled. Persist DecisionRecord.to_dict().
Source code in src/grounded_decision/runtime/module.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | |
compose_parent ¶
compose_parent(
name: str, children: Sequence[DecisionRecord]
) -> Verdict
Conservative aggregate of child verdicts.
Any child abstained: abstain. Otherwise any child degraded: degrade. Every child acted: act. No children: abstain. Abstain dominates degrade because a held child means part of the decision has no support at all, while a degraded child still ran its fallback.
Source code in src/grounded_decision/runtime/module.py
pipeline ¶
A pipeline is an ordered list of modules with a shared evidence snapshot.
Each module sees the same event stream. The pipeline verdict is the conservative aggregate of module verdicts.