{
  "nbformat": 4,
  "nbformat_minor": 5,
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "name": "python",
      "version": "3.13.0"
    },
    "blog_metadata": {
      "topic": "Foundry Routines could be the missing layer between clever demos and repeatable enterprise agents",
      "slug": "foundry-routines-could-be-the-missing-layer-between-clever-d",
      "generated_by": "LinkedIn Post Generator + Azure OpenAI",
      "generated_at": "2026-09-23T00:42:08.097Z"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# Foundry Routines could be the missing layer between clever demos and repeatable enterprise agents\n",
        "\n",
        "This notebook turns the blog post into a hands-on validation workbook. It focuses on the core claim: enterprise agents need an explicit governance and orchestration layer for approvals, exceptions, auditability, and controlled change.\n",
        "\n",
        "The examples below are conceptual and intentionally safe to run locally. They simulate routine behavior, policy checks, audit envelopes, and least-privilege review patterns without requiring live Azure resources."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": [
        "%pip install -q pandas networkx matplotlib"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": [
        "from dataclasses import dataclass\n",
        "from typing import Dict, Any, List, Optional\n",
        "from datetime import datetime, timezone\n",
        "import json\n",
        "import hashlib\n",
        "import textwrap\n",
        "\n",
        "import pandas as pd\n",
        "import networkx as nx\n",
        "import matplotlib.pyplot as plt"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Production gap: clever demo vs routinized execution\n",
        "\n",
        "The blog argues that the real production gap is not model quality first, but behavioral variance. A demo can jump directly from request to agent to tool use, while a routinized path makes policy, review, and audit explicit.\n",
        "\n",
        "This Python example recreates the blog's flowchart as a directed graph so you can inspect the execution shape."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": [
        "import networkx as nx\n",
        "import matplotlib.pyplot as plt\n",
        "\n",
        "G = nx.DiGraph()\n",
        "\n",
        "main_edges = [\n",
        "    (\"Business Trigger\", \"Routine\"),\n",
        "    (\"Routine\", \"Policy + Context\"),\n",
        "    (\"Policy + Context\", \"Agent\"),\n",
        "    (\"Agent\", \"Tools / APIs\"),\n",
        "    (\"Tools / APIs\", \"Result\"),\n",
        "    (\"Result\", \"Human Review or Automation\"),\n",
        "    (\"Human Review or Automation\", \"Audit Trail + Repeatability\"),\n",
        "]\n",
        "\n",
        "demo_edges = [\n",
        "    (\"Clever Demo\", \"Agent\"),\n",
        "    (\"Clever Demo\", \"Tools / APIs\"),\n",
        "]\n",
        "\n",
        "G.add_edges_from(main_edges + demo_edges)\n",
        "\n",
        "pos = {\n",
        "    \"Business Trigger\": (0, 0),\n",
        "    \"Routine\": (1.5, 0),\n",
        "    \"Policy + Context\": (3, 0),\n",
        "    \"Agent\": (4.5, 0),\n",
        "    \"Tools / APIs\": (6, 0),\n",
        "    \"Result\": (7.5, 0),\n",
        "    \"Human Review or Automation\": (9.5, 0),\n",
        "    \"Audit Trail + Repeatability\": (12, 0),\n",
        "    \"Clever Demo\": (4.5, -1.5),\n",
        "}\n",
        "\n",
        "plt.figure(figsize=(14, 4))\n",
        "nx.draw_networkx_nodes(G, pos, node_size=2600, node_color=\"#DCEBFA\", edgecolors=\"#4A6FA5\")\n",
        "nx.draw_networkx_labels(G, pos, font_size=9)\n",
        "\n",
        "nx.draw_networkx_edges(G, pos, edgelist=main_edges, width=2, arrows=True, arrowstyle=\"-|>\", arrowsize=18)\n",
        "nx.draw_networkx_edges(\n",
        "    G,\n",
        "    pos,\n",
        "    edgelist=demo_edges,\n",
        "    width=2,\n",
        "    style=\"dashed\",\n",
        "    edge_color=\"crimson\",\n",
        "    arrows=True,\n",
        "    arrowstyle=\"-|>\",\n",
        "    arrowsize=18,\n",
        ")\n",
        "\n",
        "plt.title(\"Clever Demo vs Routinized Execution\")\n",
        "plt.axis(\"off\")\n",
        "plt.show()\n",
        "\n",
        "print(\"Observation: the routinized path inserts policy, review, and audit as first-class execution steps.\")"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Foundry resource as a unified integration point\n",
        "\n",
        "The blog uses a simple conceptual class to show a single integration point for models, agents, and tools. The point is not the exact API shape, but the architectural posture: explicit references and a deliberate control plane.\n",
        "\n",
        "Run this example to validate the object model and inspect the generated resource paths."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": [
        "from dataclasses import dataclass\n",
        "\n",
        "@dataclass\n",
        "class FoundryResource:\n",
        "    endpoint: str\n",
        "    project: str\n",
        "\n",
        "    def model(self, name: str) -> str:\n",
        "        return f\"{self.endpoint}/projects/{self.project}/models/{name}\"\n",
        "\n",
        "    def agent(self, name: str) -> str:\n",
        "        return f\"{self.endpoint}/projects/{self.project}/agents/{name}\"\n",
        "\n",
        "    def tool(self, name: str) -> str:\n",
        "        return f\"{self.endpoint}/projects/{self.project}/tools/{name}\"\n",
        "\n",
        "foundry = FoundryResource(\"https://foundry.contoso.example\", \"ops\")\n",
        "print(foundry.model(\"gpt-4.1\"))\n",
        "print(foundry.agent(\"incident-triage\"))\n",
        "print(foundry.tool(\"ticketing-search\"))\n",
        "print(\"Preview note: routine-specific SDK/REST names are illustrative; verify current docs before implementation.\")"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Prompt chain vs routine sequence\n",
        "\n",
        "The blog contrasts a prompt-chain prototype with a routinized execution path that clearly shows where policy is applied, where tools are constrained, and where approval happens.\n",
        "\n",
        "This code prints the sequence as ordered steps and renders it as a table for review."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": [
        "import pandas as pd\n",
        "\n",
        "sequence_steps = [\n",
        "    (1, \"User/App\", \"Routine\", \"Submit business task\"),\n",
        "    (2, \"Routine\", \"Routine\", \"Apply policy, context, and limits\"),\n",
        "    (3, \"Routine\", \"Agent\", \"Invoke agent with scoped instructions\"),\n",
        "    (4, \"Agent\", \"Tool\", \"Call approved tool\"),\n",
        "    (5, \"Tool\", \"Agent\", \"Return data\"),\n",
        "    (6, \"Agent\", \"Routine\", \"Proposed action\"),\n",
        "    (7, \"Routine\", \"Human Approver\", \"Request approval if needed\"),\n",
        "    (8, \"Human Approver\", \"Routine\", \"Approve or reject\"),\n",
        "    (9, \"Routine\", \"User/App\", \"Final result + audit metadata\"),\n",
        "]\n",
        "\n",
        "sequence_df = pd.DataFrame(sequence_steps, columns=[\"step\", \"from\", \"to\", \"message\"])\n",
        "print(sequence_df.to_string(index=False))\n",
        "\n",
        "print(\"\\nKey validation question:\")\n",
        "print(\"Can you point to where policy is applied, where tool access is constrained, and where approval occurs?\")"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Conceptual routine orchestration wrapper\n",
        "\n",
        "This example wraps an agent call with policy and tool access. It is intentionally simulated, because the blog's point is to make the routine boundary explicit before anyone worries about autonomy.\n",
        "\n",
        "Use it to validate that a routine request can carry policy, tool, and task metadata in one place."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": [
        "from typing import Dict, Any\n",
        "\n",
        "def run_routine(foundry_endpoint: str, agent_name: str, tool_name: str, task: str) -> Dict[str, Any]:\n",
        "    request = {\n",
        "        \"foundry_endpoint\": foundry_endpoint,\n",
        "        \"agent\": agent_name,\n",
        "        \"tool\": tool_name,\n",
        "        \"task\": task,\n",
        "        \"policy\": {\"approval\": \"required-for-high-impact\", \"max_tool_calls\": 3},\n",
        "    }\n",
        "    response = {\n",
        "        \"status\": \"simulated\",\n",
        "        \"agent\": request[\"agent\"],\n",
        "        \"tool_used\": request[\"tool\"],\n",
        "        \"decision\": \"draft remediation plan\",\n",
        "    }\n",
        "    return response\n",
        "\n",
        "result = run_routine(\n",
        "    \"https://foundry.contoso.example\",\n",
        "    \"incident-triage\",\n",
        "    \"cmdb-lookup\",\n",
        "    \"Assess failed deployment\",\n",
        ")\n",
        "print(json.dumps(result, indent=2))"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Minimal audit envelope\n",
        "\n",
        "The blog emphasizes that observability must explain the path, not just the answer. A minimal audit envelope should preserve what ran, under what guardrails, and what happened.\n",
        "\n",
        "This example creates a simple audit record you can extend for your own workflow."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": [
        "import json\n",
        "from datetime import datetime, timezone\n",
        "\n",
        "audit_record = {\n",
        "    \"timestamp\": datetime.now(timezone.utc).isoformat(),\n",
        "    \"routine\": \"incident-remediation-preview\",\n",
        "    \"agent\": \"incident-triage\",\n",
        "    \"inputs_hash\": \"sha256:demo\",\n",
        "    \"tools_allowed\": [\"cmdb-lookup\", \"ticketing-search\"],\n",
        "    \"approval_required\": True,\n",
        "    \"outcome\": \"draft-only\",\n",
        "    \"preview_api_notice\": \"Routine API shape is conceptual; verify current Foundry docs.\",\n",
        "}\n",
        "\n",
        "print(json.dumps(audit_record, indent=2))"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Python validation: hidden workflow vs explicit routine contract\n",
        "\n",
        "A major theme in the post is that hidden workflow creates operational debt. This example compares a scattered prompt-chain design with an explicit routine contract so you can see the difference in reviewability."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": [
        "hidden_workflow = {\n",
        "    \"high_risk_country_check\": \"app_code\",\n",
        "    \"missing_soc2_rule\": \"prompt\",\n",
        "    \"legal_approval_if_data_residency_unclear\": \"confluence_page\",\n",
        "    \"audit_evidence\": \"whatever_got_logged\",\n",
        "}\n",
        "\n",
        "explicit_routine_contract = {\n",
        "    \"entry_conditions\": [\"vendor questionnaire present\", \"region identified\"],\n",
        "    \"ordered_work\": [\n",
        "        \"validate required inputs\",\n",
        "        \"run policy checks\",\n",
        "        \"call approved tools\",\n",
        "        \"stop if evidence missing\",\n",
        "        \"route for approval if needed\",\n",
        "        \"return decision packet + audit metadata\",\n",
        "    ],\n",
        "    \"policy_checks\": [\"high-risk country\", \"missing SOC 2\", \"data residency clarity\"],\n",
        "    \"approval_gates\": [\"legal approval required when residency unclear\"],\n",
        "    \"exception_paths\": [\"missing evidence\", \"unauthorized request\", \"tool unavailable\"],\n",
        "    \"output_contract\": [\"decision\", \"evidence\", \"audit metadata\"],\n",
        "}\n",
        "\n",
        "print(\"Hidden workflow locations:\")\n",
        "print(json.dumps(hidden_workflow, indent=2))\n",
        "print(\"\\nExplicit routine contract:\")\n",
        "print(json.dumps(explicit_routine_contract, indent=2))"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Python validation: approvals and exceptions as first-class behavior\n",
        "\n",
        "The blog says production readiness is tested by approvals, stop conditions, and exception ownership. This example simulates a vendor-risk routine that can proceed, stop, or escalate based on policy and evidence."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": [
        "from typing import Dict, Any\n",
        "\n",
        "def evaluate_vendor_risk(case: Dict[str, Any]) -> Dict[str, Any]:\n",
        "    exceptions = []\n",
        "    approval_required = False\n",
        "\n",
        "    if not case.get(\"authorized\", False):\n",
        "        exceptions.append(\"unauthorized_request\")\n",
        "    if not case.get(\"soc2_present\", False):\n",
        "        exceptions.append(\"missing_required_evidence\")\n",
        "    if case.get(\"tool_status\") != \"available\":\n",
        "        exceptions.append(\"tool_unavailable\")\n",
        "    if case.get(\"data_residency\") == \"unclear\":\n",
        "        approval_required = True\n",
        "    if case.get(\"country_risk\") == \"high\":\n",
        "        approval_required = True\n",
        "\n",
        "    if exceptions:\n",
        "        status = \"stop\"\n",
        "        decision = \"no_action\"\n",
        "    elif approval_required:\n",
        "        status = \"approval_required\"\n",
        "        decision = \"escalate\"\n",
        "    else:\n",
        "        status = \"straight_through\"\n",
        "        decision = \"approve\"\n",
        "\n",
        "    return {\n",
        "        \"vendor\": case.get(\"vendor\"),\n",
        "        \"status\": status,\n",
        "        \"decision\": decision,\n",
        "        \"approval_required\": approval_required,\n",
        "        \"exceptions\": exceptions,\n",
        "        \"owner_for_exception_queue\": \"vendor-risk-ops\",\n",
        "    }\n",
        "\n",
        "cases = [\n",
        "    {\n",
        "        \"vendor\": \"Contoso Payments\",\n",
        "        \"authorized\": True,\n",
        "        \"soc2_present\": True,\n",
        "        \"tool_status\": \"available\",\n",
        "        \"data_residency\": \"clear\",\n",
        "        \"country_risk\": \"low\",\n",
        "    },\n",
        "    {\n",
        "        \"vendor\": \"Fabrikam Analytics\",\n",
        "        \"authorized\": True,\n",
        "        \"soc2_present\": False,\n",
        "        \"tool_status\": \"available\",\n",
        "        \"data_residency\": \"clear\",\n",
        "        \"country_risk\": \"low\",\n",
        "    },\n",
        "    {\n",
        "        \"vendor\": \"Northwind Global\",\n",
        "        \"authorized\": True,\n",
        "        \"soc2_present\": True,\n",
        "        \"tool_status\": \"available\",\n",
        "        \"data_residency\": \"unclear\",\n",
        "        \"country_risk\": \"high\",\n",
        "    },\n",
        "]\n",
        "\n",
        "results = [evaluate_vendor_risk(c) for c in cases]\n",
        "print(pd.DataFrame(results).to_string(index=False))"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Python validation: observability should explain the path\n",
        "\n",
        "The post argues that final answers are not enough. You need to reconstruct context, tools, policy checks, divergence points, approval requests, and supporting evidence.\n",
        "\n",
        "This example generates a richer execution trace for a simulated routine run."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": [
        "from datetime import datetime, timezone\n",
        "import hashlib\n",
        "import json\n",
        "\n",
        "def hash_inputs(payload: Dict[str, Any]) -> str:\n",
        "    normalized = json.dumps(payload, sort_keys=True).encode(\"utf-8\")\n",
        "    return \"sha256:\" + hashlib.sha256(normalized).hexdigest()\n",
        "\n",
        "def simulate_execution_trace(task_payload: Dict[str, Any]) -> Dict[str, Any]:\n",
        "    trace = {\n",
        "        \"timestamp\": datetime.now(timezone.utc).isoformat(),\n",
        "        \"context_used\": {\n",
        "            \"region\": task_payload.get(\"region\"),\n",
        "            \"request_type\": task_payload.get(\"request_type\"),\n",
        "        },\n",
        "        \"tools_invoked\": [\"cmdb-lookup\", \"ticketing-search\"],\n",
        "        \"policy_checks_fired\": [],\n",
        "        \"execution_diverged\": False,\n",
        "        \"approval_requested\": False,\n",
        "        \"evidence\": [],\n",
        "        \"inputs_hash\": hash_inputs(task_payload),\n",
        "    }\n",
        "\n",
        "    if task_payload.get(\"region\") in {\"EU\", \"UK\"}:\n",
        "        trace[\"policy_checks_fired\"].append(\"regional_review\")\n",
        "    if not task_payload.get(\"evidence_complete\", False):\n",
        "        trace[\"policy_checks_fired\"].append(\"missing_evidence_stop\")\n",
        "        trace[\"execution_diverged\"] = True\n",
        "    if task_payload.get(\"impact\") == \"high\":\n",
        "        trace[\"approval_requested\"] = True\n",
        "        trace[\"policy_checks_fired\"].append(\"high_impact_approval\")\n",
        "\n",
        "    trace[\"evidence\"] = [\n",
        "        {\"source\": \"cmdb\", \"status\": \"ok\"},\n",
        "        {\"source\": \"ticketing\", \"status\": \"ok\"},\n",
        "    ]\n",
        "    return trace\n",
        "\n",
        "payload = {\n",
        "    \"request_type\": \"incident_remediation\",\n",
        "    \"region\": \"EU\",\n",
        "    \"impact\": \"high\",\n",
        "    \"evidence_complete\": False,\n",
        "}\n",
        "\n",
        "trace = simulate_execution_trace(payload)\n",
        "print(json.dumps(trace, indent=2))"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Python version of least-privilege RBAC review\n",
        "\n",
        "The blog includes PowerShell for role review, but this notebook uses Python. The goal is the same: compare current roles to a minimal allow-list and flag anything that should be reviewed or removed."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": [
        "import pandas as pd\n",
        "\n",
        "def review_roles(current_roles, allowed_roles):\n",
        "    rows = []\n",
        "    for role in current_roles:\n",
        "        approved = role in allowed_roles\n",
        "        rows.append(\n",
        "            {\n",
        "                \"Role\": role,\n",
        "                \"IsApproved\": approved,\n",
        "                \"Action\": \"Keep\" if approved else \"Review/Remove\",\n",
        "            }\n",
        "        )\n",
        "    return pd.DataFrame(rows)\n",
        "\n",
        "current_roles = [\"Reader\", \"Cognitive Services OpenAI User\", \"Contributor\"]\n",
        "allowed_roles = [\"Reader\", \"Cognitive Services OpenAI User\"]\n",
        "\n",
        "rbac_review_df = review_roles(current_roles, allowed_roles)\n",
        "print(rbac_review_df.to_string(index=False))"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Python validation: export an RBAC review report\n",
        "\n",
        "The blog also shows exporting a review report. This Python version creates a CSV file you can inspect locally."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": [
        "import pandas as pd\n",
        "\n",
        "rows = [\n",
        "    {\n",
        "        \"Principal\": \"spn-agent-ops\",\n",
        "        \"Scope\": \"/subscriptions/0000/resourceGroups/rg-ai\",\n",
        "        \"Role\": \"Reader\",\n",
        "        \"Recommendation\": \"Keep\",\n",
        "    },\n",
        "    {\n",
        "        \"Principal\": \"spn-agent-ops\",\n",
        "        \"Scope\": \"/subscriptions/0000/resourceGroups/rg-ai\",\n",
        "        \"Role\": \"Cognitive Services OpenAI User\",\n",
        "        \"Recommendation\": \"Keep\",\n",
        "    },\n",
        "    {\n",
        "        \"Principal\": \"spn-agent-ops\",\n",
        "        \"Scope\": \"/subscriptions/0000/resourceGroups/rg-ai\",\n",
        "        \"Role\": \"Contributor\",\n",
        "        \"Recommendation\": \"Remove if not required\",\n",
        "    },\n",
        "]\n",
        "\n",
        "report_df = pd.DataFrame(rows)\n",
        "output_path = \"rbac-review.csv\"\n",
        "report_df.to_csv(output_path, index=False)\n",
        "print(f\"RBAC review exported to {output_path}\")\n",
        "print(report_df.to_string(index=False))"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Python visualization: least-privilege review workflow\n",
        "\n",
        "The original post includes a flowchart for RBAC review. This Python version renders the same review sequence as a graph so you can validate the control flow."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": [
        "import networkx as nx\n",
        "import matplotlib.pyplot as plt\n",
        "\n",
        "steps = [\n",
        "    \"Identify operator or service principal\",\n",
        "    \"Collect current role assignments\",\n",
        "    \"Map required actions\",\n",
        "    \"Define minimal roles\",\n",
        "    \"Remove excess permissions\",\n",
        "    \"Test agent workflow\",\n",
        "    \"Document approved access\",\n",
        "    \"Re-review on change\",\n",
        "]\n",
        "\n",
        "G = nx.DiGraph()\n",
        "for i in range(len(steps) - 1):\n",
        "    G.add_edge(steps[i], steps[i + 1])\n",
        "\n",
        "pos = {step: (i, 0) for i, step in enumerate(steps)}\n",
        "\n",
        "plt.figure(figsize=(18, 3))\n",
        "nx.draw_networkx_nodes(G, pos, node_size=2600, node_color=\"#E8F5E9\", edgecolors=\"#2E7D32\")\n",
        "nx.draw_networkx_labels(G, pos, font_size=8)\n",
        "nx.draw_networkx_edges(G, pos, width=2, arrows=True, arrowstyle=\"-|>\", arrowsize=18)\n",
        "plt.title(\"Least-Privilege Review Workflow\")\n",
        "plt.axis(\"off\")\n",
        "plt.show()"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Practical evaluation plan\n",
        "\n",
        "The blog recommends evaluating one bounded, high-friction workflow instead of launching a vague agent transformation program. This code turns that advice into a reusable checklist and scorecard."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": [
        "evaluation_plan = {\n",
        "    \"workflow_candidates\": [\n",
        "        \"vendor-risk decision packets\",\n",
        "        \"finance exception recommendations\",\n",
        "        \"incident remediation drafts\",\n",
        "        \"access review preparation\",\n",
        "    ],\n",
        "    \"document_current_hidden_workflow\": [\n",
        "        \"prompts\",\n",
        "        \"tool permissions\",\n",
        "        \"retrieval sources\",\n",
        "        \"human approvals\",\n",
        "        \"known exception cases\",\n",
        "        \"failure ownership\",\n",
        "    ],\n",
        "    \"measure_operational_outcomes\": [\n",
        "        \"path consistency\",\n",
        "        \"exception visibility\",\n",
        "        \"reviewer effort\",\n",
        "        \"time to diagnose failures\",\n",
        "        \"ease of controlled change\",\n",
        "        \"percentage of cases that stop correctly\",\n",
        "    ],\n",
        "}\n",
        "\n",
        "print(json.dumps(evaluation_plan, indent=2))\n",
        "\n",
        "scorecard = pd.DataFrame(\n",
        "    [\n",
        "        [\"Approval path is explicit\", 1],\n",
        "        [\"Exception path is explicit\", 1],\n",
        "        [\"Audit evidence is reconstructable\", 2],\n",
        "        [\"Least privilege is reviewed\", 2],\n",
        "        [\"Change control exists for routine definitions\", 1],\n",
        "    ],\n",
        "    columns=[\"criterion\", \"score_out_of_5\"],\n",
        ")\n",
        "\n",
        "print(\"\\nSample maturity scorecard:\")\n",
        "print(scorecard.to_string(index=False))\n",
        "print(f\"\\nAverage score: {scorecard['score_out_of_5'].mean():.2f} / 5\")"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Summary\n",
        "\n",
        "This notebook validated the blog's central idea with runnable Python examples: explicit routine boundaries improve reviewability, approvals, exception handling, observability, and least-privilege control. The examples also show why a polished agent demo is not the same thing as a repeatable enterprise operating model.\n",
        "\n",
        "## Next Steps\n",
        "\n",
        "1. Pick one consequential workflow with real operational pain.\n",
        "2. Document the hidden workflow across prompts, tools, approvals, and exception ownership.\n",
        "3. Define an explicit routine contract with entry conditions, policy checks, stop conditions, and output metadata.\n",
        "4. Add an audit envelope that explains the path, not just the answer.\n",
        "5. Review runtime identities and remove any permissions that are not required.\n",
        "6. Re-score your team from 1 to 5 on approval path, exception path, and audit evidence before production."
      ]
    }
  ]
}