CoolFace
Apppublic

GestaltView-AI/recursive_observatory

sourceHugging Faceupdated 23h agoView on Hugging Face
0likes
app.py253 linesDownload Raw Back to root
1import gradio as gr2import json3import uuid4from datetime import datetime, timezone5 6APP_TITLE = "Recursive Engine Observatory"7 8def now():9    return datetime.now(timezone.utc).isoformat()10 11def make_event(iteration, prior_state, trigger, observation, interpretation,12               action, artifact, verification, new_information,13               subsequent_influence=None, correction=None, next_iteration_input=None,14               prior_event_id=None):15    return {16        "eventId": f"evt_{uuid.uuid4().hex[:10]}",17        "eventType": "recursive.cycle.completed",18        "actorType": "billy",19        "iteration": iteration,20        "createdAt": now(),21        "priorEventId": prior_event_id,22        "recursive": {23            "priorState": prior_state,24            "trigger": trigger,25            "observation": observation,26            "interpretation": interpretation,27            "action": action,28            "artifact": artifact,29            "verification": verification,30            "newInformation": new_information,31            "subsequentInfluence": subsequent_influence,32            "correction": correction,33            "nextIterationInput": next_iteration_input,34        },35    }36 37def iteration_one(task, evidence, environment):38    task = task.strip() or "Determine whether Feature X should be inspected next."39    evidence = evidence.strip() or "The feature has recent activity, but the available evidence is incomplete."40    environment = environment.strip() or "The inspection reveals a contradiction: the recent activity came from a test path, not the production path."41 42    observation = f"Initial evidence: {evidence}"43    interpretation = (44        "Working hypothesis: the available evidence is sufficient to justify a targeted inspection, "45        "but not sufficient to conclude that the feature is behaving as expected."46    )47    action = "Inspect Feature X and compare the observed path against the expected production path."48    artifact = "inspection_request.json"49    verification = "Inspection requested; result intentionally left open so the environment can provide new information."50    new_information = environment51 52    event = make_event(53        1, "initial_state", task, observation, interpretation, action, artifact,54        verification, new_information,55        next_iteration_input="Use the inspection result as a constraint on the next hypothesis."56    )57    state = {58        "task": task,59        "evidence": evidence,60        "environment": environment,61        "events": [event],62    }63    return state64 65def inspect(state):66    if not state or not state.get("events"):67        return {"status": "NO EVIDENCE", "checks": [], "explanation": "Run iteration 1 first."}68 69    events = state["events"]70    checks = []71 72    if len(events) < 2:73        checks.append(("Source event exists", True))74        checks.append(("Persistence represented", True))75        checks.append(("Subsequent influence observed", False))76        checks.append(("Correction represented", False))77        return {78            "status": "INCOMPLETE",79            "checks": checks,80            "explanation": "One cycle is evidence of an event, not yet evidence of recursion. Run the next iteration."81        }82 83    e1, e2 = events[-2], events[-1]84    r1, r2 = e1["recursive"], e2["recursive"]85 86    checks.append(("Iteration 1 is preserved", bool(e1.get("eventId"))))87    checks.append(("Iteration 2 explicitly references Iteration 1", e2.get("priorEventId") == e1.get("eventId")))88    checks.append(("Iteration 2 uses new information", r2["priorState"] == e1["recursive"]["newInformation"]))89    checks.append(("Action changes after feedback", r2["action"] != r1["action"]))90    checks.append(("Interpretation changes after feedback", r2["interpretation"] != r1["interpretation"]))91    checks.append(("Correction is represented", bool(r2["correction"])))92    checks.append(("Provenance is traceable", bool(e1.get("eventId") and e2.get("eventId"))))93 94    passed = sum(ok for _, ok in checks)95    status = "INSPECTION PASSED" if passed == len(checks) else "INSPECTION PARTIAL"96    return {97        "status": status,98        "checks": checks,99        "explanation": (100            f"{passed}/{len(checks)} inspection checks passed. "101            "This demonstrates a traceable state transition, not proof of consciousness, autonomy, "102            "or a novel intelligence mechanism."103        )104    }105 106def render_state(state):107    if not state:108        return "No cycle yet."109    return json.dumps(state, indent=2)110 111def run_first(task, evidence, environment):112    state = iteration_one(task, evidence, environment)113    return state, render_state(state), inspect(state)114 115def run_next(state):116    if not state or not state.get("events"):117        return state, render_state(state), inspect(state)118 119    e1 = state["events"][-1]120    r1 = e1["recursive"]121    new_info = r1["newInformation"]122 123    # Deterministic correction: the contradiction changes both interpretation and action.124    interpretation = (125        "Correction: the first hypothesis was too broad. The new observation indicates that "126        "the apparent signal may be generated by a test path, so the production path must be "127        "verified before treating the signal as evidence of production behavior."128    )129    action = "Trace the production path, reproduce the signal there, and compare it with the test-path result."130    artifact = "production_path_comparison.json"131    verification = "Second inspection is scoped to the production path and explicitly tests the contradiction."132    subsequent = (133        "Iteration 2 narrows the investigation because Iteration 1's environmental observation "134        "changed the next action."135    )136 137    e2 = make_event(138        2,139        new_info,140        "Prior cycle produced contradictory environmental evidence.",141        f"Carried forward from Iteration 1: {new_info}",142        interpretation,143        action,144        artifact,145        verification,146        "The next observable should distinguish test-path behavior from production-path behavior.",147        subsequent_influence=subsequent,148        correction="The initial interpretation was narrowed in response to contradictory evidence.",149        next_iteration_input="If reproduction succeeds in production, reassess the original hypothesis with the new trace.",150        prior_event_id=e1["eventId"],151    )152 153    state = dict(state)154    state["events"] = state["events"] + [e2]155    return state, render_state(state), inspect(state)156 157def reset():158    return None, "", {"status": "READY", "checks": [], "explanation": "Start with iteration 1."}159 160def format_inspection(result):161    if not result:162        return "READY"163    lines = [f"### {result['status']}", "", result["explanation"], ""]164    for label, ok in result["checks"]:165        lines.append(f"- {'✅' if ok else '⬜'} {label}")166    return "\n".join(lines)167 168with gr.Blocks(title=APP_TITLE) as demo:169    gr.Markdown(170        """# 🌀 Recursive Engine Observatory171 172A tiny, deterministic instrument for inspecting whether **one cycle actually changes the conditions of the next**.173 174This is deliberately not an autonomous agent. There is no hidden model, no training loop, and no claim of consciousness. The point is to make the recursion **visible, inspectable, and falsifiable**.175"""176    )177 178    with gr.Row():179        with gr.Column(scale=1):180            task = gr.Textbox(181                label="Task",182                value="Determine whether Feature X should be inspected next.",183                lines=2,184            )185            evidence = gr.Textbox(186                label="Initial evidence",187                value="Feature X has recent activity, but the available evidence is incomplete.",188                lines=3,189            )190            environment = gr.Textbox(191                label="Environmental response / contradiction",192                value="The inspection reveals a contradiction: the recent activity came from a test path, not the production path.",193                lines=4,194            )195            with gr.Row():196                first = gr.Button("▶ Run Iteration 1", variant="primary")197                nxt = gr.Button("↻ Run Next Iteration")198                clear = gr.Button("Reset")199 200        with gr.Column(scale=1):201            inspection = gr.Markdown(202                "### READY\nRun Iteration 1 to create the first inspectable event.",203                label="Independent inspection",204            )205 206    gr.Markdown("## Event stream")207    event_json = gr.Code(208        label="Persisted recursive state (session-local in this prototype)",209        language="json",210        lines=24,211    )212 213    state = gr.State(None)214 215    # Use a wrapper because the inspection output is structured while Markdown needs text.216    def first_display(task, evidence, environment):217        s = iteration_one(task, evidence, environment)218        return s, render_state(s), format_inspection(inspect(s))219 220    def next_display(s):221        s2, rendered, result = run_next(s)222        return s2, rendered, format_inspection(result)223 224    first.click(225        first_display,226        inputs=[task, evidence, environment],227        outputs=[state, event_json, inspection],228        queue=True,229    )230    nxt.click(231        next_display,232        inputs=state,233        outputs=[state, event_json, inspection],234        queue=True,235    )236    clear.click(237        reset,238        outputs=[state, event_json, inspection],239        queue=False,240    )241 242    gr.Markdown(243        """### What the inspector is looking for244 245**Source → event → interpretation → implementation/action → observation → correction → subsequent use**246 247A pattern is interesting only when the chain is traceable. The app intentionally exposes the event IDs and carried-forward state so another person can inspect the transition without relying on the system's own story about itself.248"""249    )250 251if __name__ == "__main__":252    demo.launch()253