ontocast.stategraph.atomic¶
Reusable per-unit render/critic retry loops.
These loops are designed for map/reduce execution where each content unit
is processed independently. They deep-copy the incoming unit state, retry a
failed render up to MAX_VISITS times, then run bounded critic passes whose
critiques are compiled and applied as patches. A successful render is never
repeated.
Ontology context assembly (resolve_unit_ontology_context) runs at the
start of both ontology_loop and facts_loop so each unit chooses its
own ontology context according to mode/policy.
Attributes¶
FACTS_PHASE = LoopPhase(name='facts', render_node=WorkflowNode.TEXT_TO_FACTS, critic_node=WorkflowNode.CRITICISE_FACTS, render_stage=FailureStage.GENERATE_GRAPH_UPDATE_FOR_FACTS, critic_stage=FailureStage.FACTS_CRITIQUE, prepare=_prepare_facts, render=_render_facts_phase, criticise=_criticise_facts_phase, collect_findings=_collect_facts_findings, repair_patch=_repair_facts_patch, critic_passes=lambda atomic: atomic.facts_critic_passes, patch_policy=lambda atomic: atomic.facts_patch_policy, acceptance_policy=lambda atomic: atomic.acceptance_policy, critic_skip_reason=_facts_critic_skip_reason)
module-attribute
¶
ONTOLOGY_PHASE = LoopPhase(name='ontology', render_node=WorkflowNode.TEXT_TO_ONTOLOGY, critic_node=WorkflowNode.CRITICISE_ONTOLOGY, render_stage=FailureStage.GENERATE_GRAPH_UPDATE_FOR_ONTOLOGY, critic_stage=FailureStage.ONTOLOGY_CRITIQUE, prepare=_prepare_ontology, render=_render_ontology_phase, criticise=_criticise_ontology_phase, collect_findings=_collect_ontology_findings, repair_patch=_repair_ontology_patch, critic_passes=lambda atomic: atomic.ontology_critic_passes, patch_policy=lambda atomic: atomic.ontology_patch_policy, acceptance_policy=lambda atomic: atomic.ontology_acceptance_policy, critic_skip_reason=_ontology_critic_skip_reason)
module-attribute
¶
UnitStateT = TypeVar('UnitStateT', UnitFactsState, UnitOntologyState)
module-attribute
¶
logger = logging.getLogger(__name__)
module-attribute
¶
Classes¶
LoopPhase
dataclass
¶
Everything that differs between the facts and ontology unit loops.
Source code in ontocast/stategraph/atomic.py
Attributes¶
acceptance_policy
instance-attribute
¶
collect_findings
instance-attribute
¶
critic_node
instance-attribute
¶
critic_passes
instance-attribute
¶
critic_skip_reason
instance-attribute
¶
critic_stage
instance-attribute
¶
criticise
instance-attribute
¶
name
instance-attribute
¶
patch_policy
instance-attribute
¶
prepare
instance-attribute
¶
render
instance-attribute
¶
render_node
instance-attribute
¶
render_stage
instance-attribute
¶
repair_patch
instance-attribute
¶
Methods:¶
__init__(name, render_node, critic_node, render_stage, critic_stage, prepare, render, criticise, collect_findings, repair_patch, critic_passes, patch_policy, acceptance_policy, critic_skip_reason)
¶
PatchOutcome
dataclass
¶
What one critic pass changed, and whether the loop should run another.
Source code in ontocast/stategraph/atomic.py
Attributes¶
applied = 0
class-attribute
instance-attribute
¶
converged
property
¶
True when another pass has nothing left to work with.
A pass that changed nothing -- every fix rolled back, or nothing to apply and nothing mandatory left -- counts as converged: the next pass would be handed the same graph and the same findings, so repeating it buys a second identical answer at full price.
mandatory_after = 0
class-attribute
instance-attribute
¶
noop = 0
class-attribute
instance-attribute
¶
residual = 0
class-attribute
instance-attribute
¶
rolled_back = 0
class-attribute
instance-attribute
¶
Methods:¶
__init__(applied=0, residual=0, noop=0, rolled_back=0, mandatory_after=0)
¶
Functions:¶
facts_loop(state, tools, document_context, max_visits_per_node=None, pre_resolved_context=None)
async
¶
Run the render/critic loop for one content unit's facts.
Source code in ontocast/stategraph/atomic.py
ontology_loop(state, tools, document_context, max_visits_per_node=None)
async
¶
Run the render/critic loop for one content unit's ontology delta.
Source code in ontocast/stategraph/atomic.py
run_unit_loop(state, tools, document_context, phase, max_visits_per_node=None, pre_resolved_context=None)
async
¶
Extract a unit once, then review and patch it a bounded number of times.
The two budgets mean different things and no longer trade against each
other. MAX_VISITS retries a render that failed; a render that
succeeded is never repeated, because re-extracting a whole unit is the
expensive answer to a local defect and reliably introduces new ones. The
critic passes then improve what came back, each one re-running the
deterministic checks for free before paying for the critique.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
UnitStateT
|
Unit state to run the loop over. |
required |
tools
|
ToolBox
|
Tool container. |
required |
document_context
|
UnitLoopContext
|
Document-level inputs, shared read-only. |
required |
phase
|
LoopPhase
|
Which of the two loops this is. |
required |
max_visits_per_node
|
int | None
|
Override for the render-failure bound. |
None
|
pre_resolved_context
|
UnitOntologyContext | None
|
Ontology context resolved once by the caller. The merged document ontology depends only on document-level state, so the fan-out builds it once and hands the same object to every unit; resolving it per unit cost a full rdflib merge and two graph copies each time. |
None
|
Source code in ontocast/stategraph/atomic.py
1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 | |