Spaces:
Sleeping
Sleeping
File size: 1,280 Bytes
ccf46df cb3c992 ccf46df 9f1614f ccf46df 9f1614f 81ead93 9f1614f 81ead93 ccf46df 81ead93 9f1614f 81ead93 ccf46df 81ead93 9f1614f 81ead93 9f1614f 81ead93 9f1614f 81ead93 9f1614f 81ead93 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | # Author: Liam Grinstead
# Multi-generation lineage tracking with mutation provenance
from typing import Dict, List
LINEAGE: Dict[str, List[dict]] = {}
PARENT_OF: Dict[str, str] = {}
def register_lineage(parent_id: str, child_id: str, mutation_profile: dict):
entry = {
"child_id": child_id,
"tier": mutation_profile.get("tier_drift"),
"overlay": mutation_profile.get("collapse_torque"),
"operators": mutation_profile.get("symbolic_operators", []),
}
LINEAGE.setdefault(parent_id, []).append(entry)
PARENT_OF[child_id] = parent_id
def get_ancestors(agent_id: str) -> List[str]:
chain = []
cur = agent_id
while cur in PARENT_OF:
p = PARENT_OF[cur]
chain.append(p)
cur = p
return chain[::-1]
def get_descendants(agent_id: str, depth: int = 6) -> Dict[int, List[dict]]:
levels: Dict[int, List[dict]] = {}
frontier = [agent_id]
for d in range(1, depth + 1):
nxt = []
for node in frontier:
children = LINEAGE.get(node, [])
if children:
levels.setdefault(d, []).extend(children)
nxt.extend([c["child_id"] for c in children])
frontier = nxt
if not frontier:
break
return levels
|