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¶
DETACHED_TRIGGER_MIN = 2
module-attribute
¶
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
1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 | |