{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "# EPI NEXUA VENTURES\n\nAn investor-grade Google Colab demo for **Nexua Ventures**.\n\nThis notebook is designed to show the strongest current EPI product story in a live setting:\n\n- a workflow is recorded as a portable `.epi` case file\n- the active rulebook is embedded into the artifact\n- EPI explains what violated policy\n- a human review is added without rewriting the original evidence\n- a forged copy later becomes visibly untrustworthy\n\n## What to look for\n\n1. **Signed evidence**: the artifact is not just a log file.\n2. **Policy and control outcomes**: the artifact explains what failed.\n3. **Human review**: the case file can carry accountable review.\n4. **Trust break**: tampering is visible.\n\n## Presentation note\n\nUse the blue form buttons to run the demo.\nThe heavy implementation is intentionally tucked away so the notebook reads like a product walkthrough, not a raw engineering notebook.\n"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "cellView": "form"
   },
   "outputs": [],
   "source": "# @title 1. Install EPI Recorder { display-mode: \"form\" }\nimport subprocess\nimport sys\n\nPACKAGE_VERSION = '2.8.10'\n\nsubprocess.run(\n    [sys.executable, '-m', 'pip', 'install', '-q', f'epi-recorder=={PACKAGE_VERSION}'],\n    check=True,\n)\n\nimport epi_core\nprint('Installed epi-recorder', epi_core.__version__)\n"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "## Live Demo Flow\n\nThe notebook is intentionally short:\n\n- initialize a signed workspace\n- define the rulebook\n- create a clean artifact and a faulty artifact\n- attach human review to the faulty case\n- show the real embedded `.epi` viewer inside Colab\n- compare trusted evidence vs tampered evidence\n"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "cellView": "form"
   },
   "outputs": [],
   "source": "# @title 2. Initialize Signed Demo Workspace { display-mode: \"form\" }\nimport html\nimport json\nimport os\nimport shutil\nimport subprocess\nimport sys\nimport zipfile\nfrom pathlib import Path\n\nfrom IPython.display import HTML, display\n\nfrom epi_cli.keys import KeyManager, generate_default_keypair_if_missing\nfrom epi_core.container import EPIContainer\nfrom epi_core.review import ReviewRecord, add_review_to_artifact, make_review_entry\nfrom epi_core.trust import create_verification_report, verify_embedded_manifest_signature\nfrom epi_recorder import record\nfrom epi_recorder.integrations import OpenAIAgentsRecorder\n\nWORKSPACE = Path('/content/epi_nexua_ventures')\nif WORKSPACE.exists():\n    shutil.rmtree(WORKSPACE)\nWORKSPACE.mkdir(parents=True, exist_ok=True)\nos.chdir(WORKSPACE)\n\nARTIFACTS = WORKSPACE / 'artifacts'\nARTIFACTS.mkdir(exist_ok=True)\n\ngenerate_default_keypair_if_missing(console_output=False)\nkey_manager = KeyManager()\nprivate_key = key_manager.load_private_key('default')\n\n\ndef run_cli(*args: str) -> str:\n    result = subprocess.run(\n        [sys.executable, '-m', 'epi_cli.main', *args],\n        capture_output=True,\n        text=True,\n    )\n    text = (result.stdout or '') + ('\\n' + result.stderr if result.stderr else '')\n    return text.strip()\n\n\ndef load_artifact(epi_path: Path) -> dict:\n    with zipfile.ZipFile(epi_path, 'r') as zf:\n        names = set(zf.namelist())\n        return {\n            'manifest': json.loads(zf.read('manifest.json').decode('utf-8')),\n            'steps': [\n                json.loads(line)\n                for line in zf.read('steps.jsonl').decode('utf-8').splitlines()\n                if line.strip()\n            ],\n            'analysis': json.loads(zf.read('analysis.json').decode('utf-8')) if 'analysis.json' in names else None,\n            'policy': json.loads(zf.read('policy.json').decode('utf-8')) if 'policy.json' in names else None,\n            'policy_evaluation': json.loads(zf.read('policy_evaluation.json').decode('utf-8')) if 'policy_evaluation.json' in names else None,\n            'review': json.loads(zf.read('review.json').decode('utf-8')) if 'review.json' in names else None,\n            'files': sorted(names),\n        }\n\n\ndef build_trust_report(epi_path: Path) -> dict:\n    manifest = EPIContainer.read_manifest(epi_path)\n    integrity_ok, mismatches = EPIContainer.verify_integrity(epi_path)\n    signature_valid, signer_name, _ = verify_embedded_manifest_signature(manifest)\n    return create_verification_report(\n        integrity_ok=integrity_ok,\n        signature_valid=signature_valid,\n        signer_name=signer_name,\n        mismatches=mismatches,\n        manifest=manifest,\n    )\n\n\ndef trust_label(report: dict) -> str:\n    if not report['integrity_ok']:\n        return 'Tampered'\n    if report['signature_valid']:\n        return 'Signed'\n    return 'Unsigned'\n\n\ndef compact_json(value) -> str:\n    try:\n        return json.dumps(value, ensure_ascii=False)\n    except Exception:\n        return str(value)\n\n\ndef render_case_view(epi_path: Path, label: str) -> str:\n    artifact = load_artifact(epi_path)\n    report = build_trust_report(epi_path)\n    status = trust_label(report)\n    color = '#0f766e' if status == 'Signed' else ('#b45309' if status == 'Unsigned' else '#b91c1c')\n\n    analysis = artifact['analysis'] or {}\n    summary = analysis.get('summary') or {}\n    primary = analysis.get('primary_fault') or {}\n    why = primary.get('why_it_matters') or summary.get('headline') or 'No analysis available.'\n    headline = summary.get('headline') or primary.get('plain_english') or 'No primary finding'\n\n    review = artifact['review'] or {}\n    review_entry = (review.get('reviews') or [{}])[0]\n    review_outcome = review_entry.get('outcome', 'No review')\n    review_notes = review_entry.get('notes', 'No reviewer notes')\n\n    evaluation = artifact['policy_evaluation'] or {}\n    controls = evaluation.get('results') or []\n    controls_html = ''.join(\n        f\"<li style='margin:6px 0;'><strong>{html.escape(item.get('rule_id', '?'))}</strong> - {html.escape(item.get('status', 'unknown'))}</li>\"\n        for item in controls[:4]\n    ) or \"<li>No control evaluation embedded</li>\"\n\n    steps_html = ''.join(\n        f\"<div style='padding:8px 0;border-top:1px solid #e5e7eb;'><strong>#{idx}</strong> {html.escape(step.get('kind', 'unknown'))}<div style='font-size:12px;color:#6b7280;margin-top:4px;'>{html.escape(compact_json(step.get('content', {}))[:220])}</div></div>\"\n        for idx, step in enumerate(artifact['steps'][:6], start=1)\n    )\n\n    files_html = ''.join(\n        f\"<li style='margin:4px 0;font-family:ui-monospace,monospace;font-size:12px;'>{html.escape(name)}</li>\"\n        for name in artifact['files']\n    )\n\n    return f'''\n    <div style=\"font-family:system-ui,-apple-system,sans-serif;background:white;border:1px solid #d1d5db;border-radius:18px;overflow:hidden;box-shadow:0 10px 30px rgba(0,0,0,0.06);\">\n      <div style=\"background:{color};color:white;padding:18px 20px;\">\n        <div style=\"font-size:12px;font-weight:700;letter-spacing:0.06em;text-transform:uppercase;opacity:0.95;\">{html.escape(label)}</div>\n        <div style=\"font-size:30px;font-weight:800;margin-top:6px;\">{html.escape(status)}</div>\n        <div style=\"margin-top:8px;font-size:14px;opacity:0.95;\">{html.escape(report['trust_message'])}</div>\n      </div>\n      <div style=\"padding:18px 20px;display:grid;grid-template-columns:1.1fr 0.9fr;gap:18px;\">\n        <div>\n          <div style=\"background:#f8fafc;border:1px solid #e5e7eb;border-radius:14px;padding:14px;margin-bottom:14px;\">\n            <div style=\"font-size:12px;font-weight:700;text-transform:uppercase;color:#6b7280;\">Workflow Goal</div>\n            <div style=\"font-size:20px;font-weight:800;margin-top:6px;color:#111827;\">{html.escape(artifact['manifest'].get('goal', 'Execution evidence'))}</div>\n          </div>\n          <div style=\"background:#f8fafc;border:1px solid #e5e7eb;border-radius:14px;padding:14px;margin-bottom:14px;\">\n            <div style=\"font-size:12px;font-weight:700;text-transform:uppercase;color:#6b7280;\">Primary Finding</div>\n            <div style=\"font-size:18px;font-weight:800;margin-top:6px;color:#111827;\">{html.escape(headline)}</div>\n            <div style=\"margin-top:8px;color:#475569;\">{html.escape(why)}</div>\n          </div>\n          <div style=\"background:#f8fafc;border:1px solid #e5e7eb;border-radius:14px;padding:14px;\">\n            <div style=\"font-size:12px;font-weight:700;text-transform:uppercase;color:#6b7280;\">Timeline Snapshot</div>\n            <div style=\"margin-top:8px;color:#475569;\">{steps_html}</div>\n          </div>\n        </div>\n        <div>\n          <div style=\"background:#f8fafc;border:1px solid #e5e7eb;border-radius:14px;padding:14px;margin-bottom:14px;\">\n            <div style=\"font-size:12px;font-weight:700;text-transform:uppercase;color:#6b7280;\">Trust Facts</div>\n            <div style=\"margin-top:8px;\">Integrity: <strong>{'Intact' if report['integrity_ok'] else 'Compromised'}</strong></div>\n            <div style=\"margin-top:6px;\">Signature: <strong>{'Valid' if report['signature_valid'] else ('Missing' if report['signature_valid'] is None else 'Invalid')}</strong></div>\n            <div style=\"margin-top:6px;\">Trust level: <strong>{html.escape(report['trust_level'])}</strong></div>\n          </div>\n          <div style=\"background:#f8fafc;border:1px solid #e5e7eb;border-radius:14px;padding:14px;margin-bottom:14px;\">\n            <div style=\"font-size:12px;font-weight:700;text-transform:uppercase;color:#6b7280;\">Control Outcomes</div>\n            <ul style=\"margin:10px 0 0 18px;padding:0;color:#334155;\">{controls_html}</ul>\n          </div>\n          <div style=\"background:#f8fafc;border:1px solid #e5e7eb;border-radius:14px;padding:14px;margin-bottom:14px;\">\n            <div style=\"font-size:12px;font-weight:700;text-transform:uppercase;color:#6b7280;\">Human Review</div>\n            <div style=\"margin-top:8px;\">Outcome: <strong>{html.escape(review_outcome)}</strong></div>\n            <div style=\"margin-top:6px;color:#475569;\">{html.escape(review_notes)}</div>\n          </div>\n          <div style=\"background:#f8fafc;border:1px solid #e5e7eb;border-radius:14px;padding:14px;\">\n            <div style=\"font-size:12px;font-weight:700;text-transform:uppercase;color:#6b7280;\">Files Inside Artifact</div>\n            <ul style=\"margin:10px 0 0 18px;padding:0;color:#334155;\">{files_html}</ul>\n          </div>\n        </div>\n      </div>\n    </div>\n    '''\n\n\ndef render_side_by_side(cases):\n    cards = ''.join(\n        f\"<div style='flex:1 1 0;min-width:320px;'>{render_case_view(path, label)}</div>\"\n        for path, label in cases\n    )\n    return f\"<div style='display:flex;flex-wrap:wrap;gap:18px;align-items:stretch;margin:18px 0;'>{cards}</div>\"\n\n\ndef render_command_output(title: str, output: str) -> str:\n    return f\"<div style='background:#0f172a;color:#e2e8f0;border-radius:16px;padding:16px 18px;margin:14px 0;'><div style='font-size:12px;font-weight:700;letter-spacing:0.06em;text-transform:uppercase;color:#93c5fd;'>{html.escape(title)}</div><pre style='white-space:pre-wrap;margin-top:10px;font-family:ui-monospace,monospace;font-size:12px;line-height:1.5;'>{html.escape(output)}</pre></div>\"\n\n\ndef render_real_epi_viewer(epi_path: Path, extract_dir_name: str, title: str, height: int = 980):\n    viewer_dir = WORKSPACE / extract_dir_name\n    if viewer_dir.exists():\n        shutil.rmtree(viewer_dir)\n\n    result = subprocess.run(\n        [sys.executable, '-m', 'epi_cli.main', 'view', str(epi_path), '--extract', str(viewer_dir)],\n        capture_output=True,\n        text=True,\n        check=True,\n    )\n    viewer_html = (viewer_dir / 'viewer.html').read_text(encoding='utf-8')\n    iframe_srcdoc = html.escape(viewer_html, quote=True)\n\n    header = f'''\n    <div style=\"background:linear-gradient(135deg,#eff6ff,#f8fafc);border:1px solid #bfdbfe;border-radius:18px;padding:20px 22px;margin:14px 0;\">\n      <div style=\"font-size:12px;font-weight:700;letter-spacing:0.06em;text-transform:uppercase;color:#1d4ed8;\">Real Embedded Viewer</div>\n      <div style=\"font-size:24px;font-weight:800;color:#0f172a;margin-top:6px;\">{html.escape(title)}</div>\n      <div style=\"margin-top:10px;color:#334155;\">This is the actual <code>viewer.html</code> regenerated from the <code>.epi</code> artifact and rendered inside an iframe so Colab will execute the viewer's bundled scripts correctly.</div>\n    </div>\n    '''\n\n    iframe = f'<iframe srcdoc=\"{iframe_srcdoc}\" style=\"width:100%;height:{height}px;border:1px solid #d1d5db;border-radius:18px;background:white;box-shadow:0 10px 30px rgba(0,0,0,0.06);\"></iframe>'\n    display(HTML(header + iframe))\n    output = ((result.stdout or '').strip() + ('\\n' + result.stderr.strip() if result.stderr else '')).strip()\n    if output:\n        display(HTML(render_command_output('Viewer Extraction Output', output)))\n\n\nprint('Workspace ready:', WORKSPACE)\nprint('Artifacts directory:', ARTIFACTS)\nprint('Default signing keypair ready')\n"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "cellView": "form"
   },
   "outputs": [],
   "source": "# @title 3. Define The Rulebook { display-mode: \"form\" }\npolicy = {\n    'policy_format_version': '2.0',\n    'policy_id': 'nexua-ventures-refund-demo-v2',\n    'system_name': 'nexua-ventures-refund-agent-demo',\n    'system_version': '2.8.10',\n    'policy_version': '2026-03-24',\n    'scope': {\n        'environment': 'nexua-demo',\n        'workflow': 'nexua_customer_refund',\n        'team': 'nexua-ventures-demo',\n    },\n    'approval_policies': [\n        {\n            'approval_id': 'manager-refund-approval',\n            'required_roles': ['manager'],\n            'minimum_approvers': 1,\n            'reason_required': True,\n        }\n    ],\n    'rules': [\n        {\n            'id': 'R005',\n            'name': 'Manager Approval Before Refund',\n            'severity': 'critical',\n            'description': 'Refund approval requires an approved manager response.',\n            'type': 'approval_guard',\n            'mode': 'require_approval',\n            'applies_at': ['decision'],\n            'approval_action': 'approve_refund',\n            'approval_policy_ref': 'manager-refund-approval',\n        },\n        {\n            'id': 'R006',\n            'name': 'Only Approved Refund Tools',\n            'severity': 'high',\n            'description': 'Only allowlisted tools may be called in this workflow.',\n            'type': 'tool_permission_guard',\n            'mode': 'detect',\n            'applies_at': ['tool_call'],\n            'allowed_tools': ['lookup_order', 'verify_identity', 'issue_refund', 'send_email'],\n        },\n    ],\n}\n\npolicy_path = WORKSPACE / 'epi_policy.json'\npolicy_path.write_text(json.dumps(policy, indent=2), encoding='utf-8')\nvalidate_output = run_cli('policy', 'validate', str(policy_path))\n\nsummary_html = f'''\n<div style=\"background:linear-gradient(135deg,#eff6ff,#f8fafc);border:1px solid #bfdbfe;border-radius:18px;padding:20px 22px;margin:14px 0;\">\n  <div style=\"font-size:12px;font-weight:700;letter-spacing:0.06em;text-transform:uppercase;color:#1d4ed8;\">Policy Ready</div>\n  <div style=\"font-size:24px;font-weight:800;color:#0f172a;margin-top:6px;\">Nexua Ventures Refund Control Rulebook</div>\n  <div style=\"margin-top:10px;color:#334155;\">This rulebook requires manager approval before refund approval and restricts the workflow to approved tools.</div>\n  <ul style=\"margin:14px 0 0 18px;color:#334155;\">\n    <li>R005 - manager approval before refund decision</li>\n    <li>R006 - only approved tools may run</li>\n  </ul>\n</div>\n'''\n\ndisplay(HTML(summary_html))\ndisplay(HTML(render_command_output('Policy Validation Output', validate_output)))\n"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "cellView": "form"
   },
   "outputs": [],
   "source": "# @title 4. Create Signed Evidence And Human Review { display-mode: \"form\" }\ndef make_good_run(path: Path):\n    with record(path, workflow_name='EPI NEXUA VENTURES Demo', goal='Resolve a customer refund safely') as epi:\n        with epi.agent_run(\n            'nexua-refund-agent',\n            user_input='Refund order ORD-1001',\n            session_id='sess-good-001',\n            task_id='refund-ORD-1001',\n            attempt=1,\n        ) as agent:\n            agent.plan('Look up the order, verify identity, request approval, then decide.')\n            agent.message('user', 'Refund order ORD-1001')\n            agent.memory_read('refund_history', query='ORD-1001', result_count=1)\n            agent.tool_call('lookup_order', {'order_id': 'ORD-1001'})\n            agent.tool_result('lookup_order', {'status': 'paid', 'amount': 120, 'customer_id': 'CUST-42'})\n            agent.tool_call('verify_identity', {'customer_id': 'CUST-42'})\n            agent.tool_result('verify_identity', {'verified': True})\n            agent.approval_request('approve_refund', reason='Manual approval required for refund action')\n            agent.approval_response('approve_refund', approved=True, reviewer='manager', notes='Approved after identity verification')\n            agent.decision('approve_refund', confidence=0.94)\n            agent.tool_call('issue_refund', {'order_id': 'ORD-1001', 'amount': 120})\n            agent.tool_result('issue_refund', {'success': True, 'refund_id': 'RF-1001'})\n\n\ndef make_bad_run(path: Path):\n    with record(path, workflow_name='EPI NEXUA VENTURES Demo', goal='Resolve a customer refund safely') as epi:\n        with epi.agent_run(\n            'nexua-refund-agent',\n            user_input='Refund order ORD-2002',\n            session_id='sess-bad-001',\n            task_id='refund-ORD-2002',\n            attempt=1,\n        ) as agent:\n            agent.plan('Move quickly and use the override if needed.')\n            agent.message('user', 'Refund order ORD-2002')\n            agent.tool_call('lookup_order', {'order_id': 'ORD-2002'})\n            agent.tool_result('lookup_order', {'status': 'paid', 'amount': 500, 'customer_id': 'CUST-77'})\n            agent.tool_call('admin_override', {'order_id': 'ORD-2002'})\n            agent.tool_result('admin_override', {'status': 'override used'})\n            agent.decision('approve_refund', confidence=0.62)\n            agent.tool_call('issue_refund', {'order_id': 'ORD-2002', 'amount': 500})\n            agent.tool_result('issue_refund', {'success': True, 'refund_id': 'RF-2002'})\n\n\ngood_artifact = ARTIFACTS / 'nexua_refund_agent_ok.epi'\nbad_artifact = ARTIFACTS / 'nexua_refund_agent_missing_approval.epi'\nreviewed_artifact = ARTIFACTS / 'nexua_refund_agent_reviewed.epi'\n\nmake_good_run(good_artifact)\nmake_bad_run(bad_artifact)\nshutil.copy2(bad_artifact, reviewed_artifact)\n\nanalysis = load_artifact(reviewed_artifact)['analysis'] or {}\nfault = analysis.get('primary_fault') or (analysis.get('secondary_flags') or [{}])[0]\nreview = ReviewRecord(\n    reviewed_by='nexua-reviewer@epilabs.org',\n    reviews=[\n        make_review_entry(\n            fault,\n            'confirmed_fault',\n            'Manager approval is missing and an unapproved tool was used. This workflow should have been escalated.',\n            'nexua-reviewer@epilabs.org',\n        )\n    ],\n)\nreview.sign(private_key)\nadd_review_to_artifact(reviewed_artifact, review)\n\nsummary_html = f'''\n<div style=\"background:linear-gradient(135deg,#f8fafc,#ecfeff);border:1px solid #cbd5e1;border-radius:18px;padding:20px 22px;margin:14px 0;\">\n  <div style=\"font-size:12px;font-weight:700;letter-spacing:0.06em;text-transform:uppercase;color:#0f766e;\">Artifacts Created</div>\n  <div style=\"font-size:24px;font-weight:800;color:#0f172a;margin-top:6px;\">One healthy case and one reviewed failing case</div>\n  <ul style=\"margin:14px 0 0 18px;color:#334155;\">\n    <li><strong>{good_artifact.name}</strong> - expected to remain signed and clean</li>\n    <li><strong>{reviewed_artifact.name}</strong> - expected to remain signed but contain a confirmed policy fault</li>\n  </ul>\n</div>\n'''\n\ndisplay(HTML(summary_html))\n"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "cellView": "form"
   },
   "outputs": [],
   "source": "# @title 5. Render The Investor Case View { display-mode: \"form\" }\ngood_verify = run_cli('verify', str(good_artifact))\nreviewed_analyze = run_cli('analyze', str(reviewed_artifact))\nreviewed_verify = run_cli('verify', str(reviewed_artifact))\n\ndisplay(HTML(render_side_by_side([\n    (good_artifact, 'Healthy Workflow'),\n    (reviewed_artifact, 'Policy Failure With Human Review'),\n])))\n\ndisplay(HTML(render_command_output('Healthy Artifact Verification', good_verify)))\ndisplay(HTML(render_command_output('Reviewed Artifact Analysis', reviewed_analyze)))\ndisplay(HTML(render_command_output('Reviewed Artifact Verification', reviewed_verify)))\n"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "cellView": "form",
    "id": "real-viewer-demo"
   },
   "outputs": [],
   "source": "# @title 6. Show The Real Embedded .EPI Viewer { display-mode: \"form\" }\nrender_real_epi_viewer(\n    reviewed_artifact,\n    extract_dir_name='reviewed_artifact_viewer',\n    title='Actual Viewer Bundled Inside The Reviewed Artifact',\n)\n"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "cellView": "form"
   },
   "outputs": [],
   "source": "# @title 7. Tamper With The Reviewed Artifact { display-mode: \"form\" }\ntampered_artifact = ARTIFACTS / 'nexua_refund_agent_tampered.epi'\nshutil.copy2(reviewed_artifact, tampered_artifact)\n\nwith zipfile.ZipFile(tampered_artifact, 'a') as zf:\n    analysis = json.loads(zf.read('analysis.json').decode('utf-8'))\n    analysis['summary']['headline'] = 'FORGED ANALYSIS - DO NOT TRUST'\n    zf.writestr('analysis.json', json.dumps(analysis, indent=2))\n\ntampered_verify = run_cli('verify', str(tampered_artifact))\n\ndisplay(HTML(render_side_by_side([\n    (reviewed_artifact, 'Reviewed Trusted Artifact'),\n    (tampered_artifact, 'Forged Copy'),\n])))\n\ndisplay(HTML(render_command_output('Tampered Artifact Verification', tampered_verify)))\n"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "cellView": "form"
   },
   "outputs": [],
   "source": "# @title 8. Optional OpenAI Agents Bridge Demo { display-mode: \"form\" }\nbridge_artifact = ARTIFACTS / 'nexua_openai_agents_bridge_demo.epi'\nsynthetic_events = [\n    {'type': 'run_item_stream_event', 'item': {'type': 'message', 'role': 'assistant', 'content': 'I will reset the password safely.'}},\n    {'type': 'run_item_stream_event', 'item': {'type': 'tool_call', 'tool_name': 'lookup_user', 'arguments': {'email': 'customer@example.com'}, 'call_id': 'call-1'}},\n    {'type': 'run_item_stream_event', 'item': {'type': 'tool_result', 'tool_name': 'lookup_user', 'result': {'user_id': 'user-123'}, 'call_id': 'call-1'}},\n    {'type': 'run_item_stream_event', 'item': {'type': 'approval_request', 'action': 'reset_password', 'reason': 'High-risk account action'}},\n    {'type': 'run_item_stream_event', 'item': {'type': 'approval_response', 'action': 'reset_password', 'approved': True, 'reviewer': 'manager', 'notes': 'Approved'}},\n    {'type': 'run_item_stream_event', 'item': {'type': 'final_output', 'output': 'Password reset completed successfully.'}},\n]\n\nwith record(bridge_artifact, workflow_name='EPI NEXUA VENTURES OpenAI Agents Bridge Demo') as epi:\n    with OpenAIAgentsRecorder(epi, agent_name='nexua-support-agent', user_input='Reset customer password') as recorder:\n        for event in synthetic_events:\n            recorder.consume(event)\n\ndisplay(HTML(render_side_by_side([\n    (bridge_artifact, 'OpenAI Agents-Style Event Bridge'),\n])))\n"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "cellView": "form"
   },
   "outputs": [],
   "source": "# @title 9. Download The Artifacts { display-mode: \"form\" }\nfrom google.colab import files\n\nprint('Available artifacts:')\nfor path in sorted(ARTIFACTS.glob('*.epi')):\n    print(' -', path.name)\n\n# Uncomment any line below to download a file from Colab:\n# files.download(str(good_artifact))\n# files.download(str(reviewed_artifact))\n# files.download(str(tampered_artifact))\n# files.download(str(bridge_artifact))\n"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "## Final Takeaway\n\nFor a trust-sensitive AI workflow, EPI gives one portable artifact that can answer three questions:\n\n- **What happened?**\n- **What violated policy?**\n- **Can this evidence still be trusted?**\n\nThat is the product story this notebook is built to show.\n"
  }
 ],
 "metadata": {
  "colab": {
   "provenance": [],
   "name": "EPI NEXUA VENTURES.ipynb",
   "include_colab_link": true
  },
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3"
  },
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
