Executed classroom notebook
Original source cells and recorded outputs, preserved for audience review. This page displays executed results; it does not execute code.
Download the byte-preserved executed notebook · Output provenance and hashes
Notebook SHA-256: fb825152c891ef3bd137262fd2b3fc0495eb1546c737c0eb5e161fab3c685126
Browser captures are labeled “Executed notebook output” and do not reproduce the Colab interface. Tables below retain all recorded columns and rows; wide tables scroll horizontally.
Cell 0 · colab-start · markdown
Start here
One notebook covers voltage, restoration and cyber response.
1. Save a copy in Drive and connect a CPU runtime.
2. Run Set up Google Colab (CPU). Wait for Ready.
3. Run L0, then L1. Follow the later L headings in order.
Keep RUN_OPENDSS=False and RUN_LOCAL_LLAMA=False. You need no GPU, API key or live Llama service. Follow along in the lecture or finish the experiments afterward.
After a runtime reset, rerun setup and the earlier cells.
Slides · Lab guide · Setup help
Original Markdown source
## Start here
One notebook covers **voltage, restoration and cyber response**.
1. Save a copy in Drive and connect a **CPU** runtime.
2. Run **Set up Google Colab (CPU)**. Wait for **Ready**.
3. Run **L0**, then **L1**. Follow the later L headings in order.
Keep `RUN_OPENDSS=False` and `RUN_LOCAL_LLAMA=False`. You need no GPU, API key or live Llama service. Follow along in the lecture or finish the experiments afterward.
After a runtime reset, rerun setup and the earlier cells.
[Slides](https://alaaselim-sudo.github.io/GridGuard-Agentic-AI-Tutorials/operator-cases/#/1) · [Lab guide](https://alaaselim-sudo.github.io/GridGuard-Agentic-AI-Tutorials/downloads/participant-lab-guide.pdf) · [Setup help](https://github.com/AlaaSelim-sudo/GridGuard-Agentic-AI-Tutorials/blob/main/COLAB_GUIDE.md)
Cell 1 · colab-setup · code · recorded execution 1
Original code cell
#@title Set up Google Colab (CPU)
from pathlib import Path
import runpy
import subprocess
try:
import google.colab
except ImportError:
print('Local Jupyter: use the existing installation instructions below.')
else:
checkout = Path('/content/GridGuard-Agentic-AI-Tutorials')
if not checkout.exists():
subprocess.run([
'git', 'clone', '--quiet', '--depth', '1', '--filter=blob:none',
'--sparse', '--branch', 'main',
'https://github.com/AlaaSelim-sudo/GridGuard-Agentic-AI-Tutorials.git',
str(checkout),
], check=True)
if not (checkout / '.git').is_dir():
raise RuntimeError('The Colab tutorial folder is not a Git clone. Start a fresh session.')
if not (checkout / 'scripts/colab_setup.py').exists():
subprocess.run([
'git', '-C', str(checkout), 'sparse-checkout', 'set', '--no-cone',
'/scripts/colab_setup.py',
], check=True)
folder = runpy.run_path(str(checkout / 'scripts/colab_setup.py'))['prepare'](
checkout, profile='classroom',
)
Executed output 0 (zero-based)
Local Jupyter: use the existing installation instructions below.
Cell 2 · classroom-000 · markdown
Three operator cases
Alaa Selim, MIT/Dartmouth; Mohamed Chehada, UT Austin.
For each case: predict, run, change one input, rerun, explain.
- Voltage, L2-L5: propose settings and check electrical limits.
- Restoration, L6-L7: compare service goals and check changed inputs.
- Cyber, L8-L9: test misleading readings and a recovery proposal.
- Agent records, L10-L10B: inspect saved Llama choices and tool results.
- Operator review, L12: practice a simulated readback. Leave L11 disabled.
What runs? Python makes new calculations. Saved SAC weights produce new proposals. Llama replies are recordings, not new calls. No cell operates equipment.
<details><summary>Terms and local setup</summary>
New calculation means calculated in this run. Saved reply means an actual earlier model response with its original inputs and timing. Saved policy means previously trained weights used to propose an action now.
Local Jupyter users need the full tutorial folder and requirements_linear.txt. Start Jupyter in that folder. Colab users run the setup cell. OpenDSS and a live local Ollama call need extra preparation and remain off in this route.
</details>
Original Markdown source
# Three operator cases
**Alaa Selim, MIT/Dartmouth; Mohamed Chehada, UT Austin.**
For each case: **predict, run, change one input, rerun, explain**.
- **Voltage, L2-L5:** propose settings and check electrical limits.
- **Restoration, L6-L7:** compare service goals and check changed inputs.
- **Cyber, L8-L9:** test misleading readings and a recovery proposal.
- **Agent records, L10-L10B:** inspect saved Llama choices and tool results.
- **Operator review, L12:** practice a simulated readback. Leave L11 disabled.
**What runs?** Python makes new calculations. Saved SAC weights produce new proposals. Llama replies are recordings, not new calls. No cell operates equipment.
<details><summary>Terms and local setup</summary>
**New calculation** means calculated in this run. **Saved reply** means an actual earlier model response with its original inputs and timing. **Saved policy** means previously trained weights used to propose an action now.
Local Jupyter users need the full tutorial folder and `requirements_linear.txt`. Start Jupyter in that folder. Colab users run the setup cell. OpenDSS and a live local Ollama call need extra preparation and remain off in this route.
</details>
Cell 3 · classroom-001 · markdown
L0 · Default settings
Leave both switches False and run the cell.
Voltage uses a synthetic feeder and a three-phase linear model. Restoration uses a separate six-node graph. Cyber uses a separate four-bus DC model. These are teaching studies, not live utility networks.
Original Markdown source
## L0 · Default settings
Leave both switches **False** and run the cell.
Voltage uses a synthetic feeder and a three-phase linear model. Restoration uses a separate six-node graph. Cyber uses a separate four-bus DC model. These are teaching studies, not live utility networks.
Cell 4 · classroom-002 · code · recorded execution 2
Original code cell
from pathlib import Path
from copy import deepcopy
from dataclasses import asdict
import json, time
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from IPython.display import display, Markdown
from src import classroom_labs as lab
RUN_OPENDSS = False # True: fresh full-model audit + separate AC MPC solve in L5
RUN_LOCAL_LLAMA = False # True: one optional local call in L11
ROOT = Path.cwd()
assert (ROOT / 'data/lindistflow3_network.json').exists(), 'Start Jupyter in the tutorial folder'
plt.rcParams.update({'figure.dpi': 120, 'font.size': 10, 'axes.spines.top': False,
'axes.spines.right': False})
pd.set_option('display.max_colwidth', None)
timings = {}
print('Default: fresh linear numerical labs; recorded LLM examples; no training or network.')
Executed output 0 (zero-based)
Default: fresh linear numerical labs; recorded LLM examples; no training or network.
Cell 5 · classroom-003 · markdown
L1 · Does the evidence match?
Predict: can an old result support a changed request?
Run the cell. Read binding_pass. Expect True, False, False: only unchanged inputs and commands match.
The hash detects changed records. It does not authenticate sensor data or prove an action is safe.
Original Markdown source
## L1 · Does the evidence match?
**Predict:** can an old result support a changed request?
Run the cell. Read `binding_pass`. Expect **True, False, False**: only unchanged inputs and commands match.
The hash detects changed records. It does **not** authenticate sensor data or prove an action is safe.
Cell 6 · classroom-004 · code · recorded execution 3
Original code cell
request = lab.validate_request(dict(task='voltage', backend='lindistflow3',
load_scale=1.0, rating_fraction=0.80, revision=1))
candidate = {'control': [0.25, 0.0]}
evidence = lab.bind_evidence(request, candidate, {'example_only': True, 'passed': True})
changed_request = {**request, 'load_scale': 1.10, 'revision': 2}
guard = pd.DataFrame([
{'test': 'same request + same command', 'binding_pass': lab.bound_to(request, candidate, evidence)},
{'test': 'changed load; old evidence', 'binding_pass': lab.bound_to(changed_request, candidate, evidence)},
{'test': 'changed command; old evidence', 'binding_pass': lab.bound_to(request, {'control': [0.50, 0.]}, evidence)}])
display(guard)
assert guard.binding_pass.tolist() == [True, False, False]
Executed output 0 (zero-based)
|
test |
binding_pass |
| 0 |
same request + same command |
True |
| 1 |
changed load; old evidence |
False |
| 2 |
changed command; old evidence |
False |
Cell 7 · classroom-005 · markdown
<details><summary>Check your answer</summary>
Changed inputs or commands need a new check. The third test also detects a changed result. A hash confirms a record match, not the truth of the data.
</details>
Original Markdown source
<details><summary>Check your answer</summary>
Changed inputs or commands need a new check. The third test also detects a changed result. A hash confirms a record match, not the truth of the data.
</details>
Cell 8 · classroom-006 · markdown
L2 · Propose and check voltage settings
MPC plans using a model. SAC uses a saved learned policy. Python checks both proposals.
1. Run the default cell.
2. Read feasible, max_allowed_current_pct and current_step_J.
3. Change only RATING_FRACTION from 0.80 to 0.75. Predict and rerun.
4. Compare the results, then restore 0.80 and rerun.
Check limits before comparing score J. A lower J is useful only for a passing proposal. The default model covers MV phases and currents, with ideal LV aggregation.
<details><summary>Model details and sources</summary>
Let $u=[a,b]$, where $a$ is active-power participation and $b$ is reactive-power participation across the supplied inverter fleet: $P_i=aS_i,\ Q_i=bS_i$. The capability constraint is $a^2+b^2\leq1$, with $0\leq a\leq1,\ |b|\leq0.44$. Both controls are continuous.
MPC solves a three-step local sensitivity optimization, minimizing
\[
\sum_{k=0}^{2}\gamma^k\left[(1-a_k)^2+0.05b_k^2+
10\operatorname{mean}(V_k-1.01)^2+0.05\lVert u_k-u_{k-1}\rVert^2\right],
\]
subject to modeled voltage/current limits and inverter capability. $V_k$ contains per-unit phase voltages; $\gamma=0.98$ discounts later cost. Only the first action is evaluated in the comparison table. This is local feasible planning, without a global optimum or stability certificate.
SAC is a model-free continuous policy learned previously from simulator experience. The saved NumPy actor performs new inference here. Its training conditions differ from this derated test, so this is a transfer check. PPO is another continuous policy-learning method, but no PPO policy is trained in this tutorial.
Sources: Rawlings, Mayne & Diehl, MPC; Haarnoja et al., SAC; Gan & Low, multiphase linear models.
</details>
Original Markdown source
## L2 · Propose and check voltage settings
**MPC** plans using a model. **SAC** uses a saved learned policy. Python checks both proposals.
1. Run the default cell.
2. Read `feasible`, `max_allowed_current_pct` and `current_step_J`.
3. Change only `RATING_FRACTION` from `0.80` to `0.75`. Predict and rerun.
4. Compare the results, then restore `0.80` and rerun.
Check limits before comparing score **J**. A lower J is useful only for a passing proposal. The default model covers MV phases and currents, with ideal LV aggregation.
<details><summary>Model details and sources</summary>
Let $u=[a,b]$, where $a$ is active-power participation and $b$ is reactive-power participation across the supplied inverter fleet: $P_i=aS_i,\ Q_i=bS_i$. The capability constraint is $a^2+b^2\leq1$, with $0\leq a\leq1,\ |b|\leq0.44$. Both controls are continuous.
MPC solves a three-step local sensitivity optimization, minimizing
\[
\sum_{k=0}^{2}\gamma^k\left[(1-a_k)^2+0.05b_k^2+
10\operatorname{mean}(V_k-1.01)^2+0.05\lVert u_k-u_{k-1}\rVert^2\right],
\]
subject to modeled voltage/current limits and inverter capability. $V_k$ contains per-unit phase voltages; $\gamma=0.98$ discounts later cost. Only the first action is evaluated in the comparison table. This is local feasible planning, without a global optimum or stability certificate.
SAC is a model-free continuous policy learned previously from simulator experience. The saved NumPy actor performs new inference here. Its training conditions differ from this derated test, so this is a transfer check. PPO is another continuous policy-learning method, but no PPO policy is trained in this tutorial.
Sources: [Rawlings, Mayne & Diehl, MPC](https://sites.engineering.ucsb.edu/~jbraw/mpc/); [Haarnoja et al., SAC](https://proceedings.mlr.press/v80/haarnoja18b.html); [Gan & Low, multiphase linear models](https://arxiv.org/abs/1406.3054).
</details>
Cell 9 · classroom-007 · code · recorded execution 4
Original code cell
LOAD_SCALE = 1.0
RATING_FRACTION = 0.80
started = time.perf_counter()
voltage = lab.voltage_lab(LOAD_SCALE, RATING_FRACTION)
timings['L2 fresh MPC + SAC + checks'] = time.perf_counter() - started
print(voltage['mode'])
display(voltage['table'])
fig, axes = plt.subplots(1, 2, figsize=(10, 3.2))
for row in voltage['evaluations']:
v = np.asarray(row['evidence'].get('voltages_pu', []))
axes[0].plot(np.sort(v), label=row['method'])
voltage['table'].plot.bar(x='method', y='max_allowed_current_pct', ax=axes[1], legend=False, color='#16817a')
axes[0].axhspan(.95, 1.05, color='#16817a', alpha=.08)
axes[0].set(xlabel='Voltage rank (each curve sorted separately)', ylabel='Voltage (p.u.)', title='Fresh voltage distributions')
axes[0].legend(); axes[1].axhline(100, color='#b7502e', linestyle='--')
axes[1].set(ylabel='Allowed-current utilization (%)', title='Feasibility precedes ranking', xlabel='')
axes[1].tick_params(axis='x', rotation=0)
plt.tight_layout(); plt.show()
Executed output 0 (zero-based)
FRESH numerical solves; saved SAC weights; no LLM call
Executed output 1 (zero-based)
|
method |
feasible |
current_step_J |
a |
b |
vmin |
vmax |
max_allowed_current_pct |
failures |
| 0 |
MPC |
True |
0.031104 |
0.960307 |
-0.111114 |
1.023874 |
1.038709 |
73.619901 |
none |
| 1 |
saved SAC actor |
True |
0.436428 |
0.340066 |
0.014024 |
1.013243 |
1.030000 |
51.679336 |
none |
Executed output 2 (zero-based)
Cell 10 · classroom-008 · markdown
<details><summary>Check your answer</summary>
At allowance 0.75, MPC uses about 78.53% and SAC 54.85%. Both pass this test. This does not prove full MV/LV coverage. Your changed L2 case is separate from the saved model replies in L3.
</details>
Original Markdown source
<details><summary>Check your answer</summary>
At allowance 0.75, MPC uses about 78.53% and SAC 54.85%. Both pass this test. This does not prove full MV/LV coverage. Your changed L2 case is separate from the saved model replies in L3.
</details>
Cell 11 · classroom-009 · markdown
L3 · Inspect three saved model replies
Run the cell. Compare the chosen operations and their recorded times.
Different wording can request the same tool and settings. The notebook groups these matching requests before counting votes.
These are real earlier replies for test_01. No new model call runs. They do not describe your changed L2 inputs. Their explanations still need an electrical check.
Original Markdown source
## L3 · Inspect three saved model replies
Run the cell. Compare the chosen operations and their recorded times.
Different wording can request the same tool and settings. The notebook groups these matching requests before counting votes.
These are real earlier replies for **test_01**. No new model call runs. They do not describe your changed L2 inputs. Their explanations still need an electrical check.
Cell 12 · classroom-010 · code · recorded execution 5
Original code cell
pool = lab.saved_pool('test_01')
display(pd.DataFrame(pool['responses'])[['model_id', 'operation_id', 'reason', 'seconds', 'source']])
display(pd.DataFrame([{'operation': ', '.join(c['operation_ids']),
'votes': c['vote_count'], 'share': c['vote_share'], 'parameters': c['operation']['parameters']}
for c in pool['pool']['candidates']]))
print('ARCHIVED ACTUAL LLM; original context:', pool['context']['id'])
print('Distinct physical candidates:', len(pool['pool']['candidates']))
print('Malformed/duplicate votes rejected:', len(pool['pool']['rejected']))
Executed output 0 (zero-based)
|
model_id |
operation_id |
reason |
seconds |
source |
| 0 |
llama3.1:8b |
INCREASE_PV_0025 |
The incumbent candidate has a score of 0.031103819352072536, which is relatively low. Increasing active participation by 0.0025 may help reduce curtailment and improve the overall performance. This is supported by the operation's description, which states that it increases active participation to reduce curtailment. |
1.866508 |
actual_local_llm |
| 1 |
llama3.2:3b |
RELAX_Q_10_PERCENT |
Reducing reactive effort magnitude by ten percent may help improve the overall system performance and reduce curtailment, as evidenced by the current step J calculation which includes a term of 0.05*b^2, indicating a positive impact of reducing q on the objective function. |
0.905114 |
actual_local_llm |
| 2 |
qwen2.5:7b-instruct |
RELAX_Q_10_PERCENT |
The current incumbent solution has a lower objective score compared to the SAC candidate, indicating it is performing better. Relaxing the reactive effort by 10% may help improve voltage stability without significantly degrading active power performance, as evidenced by the SAC candidate's higher score. |
1.844490 |
actual_local_llm |
Executed output 1 (zero-based)
|
operation |
votes |
share |
parameters |
| 0 |
INCREASE_PV_0025 |
1 |
0.333333 |
{'control': ['0.962807', '-0.111114']} |
| 1 |
RELAX_Q_10_PERCENT |
2 |
0.666667 |
{'control': ['0.960307', '-0.100002']} |
Executed output 2 (zero-based)
ARCHIVED ACTUAL LLM; original context: test_01
Distinct physical candidates: 2
Malformed/duplicate votes rejected: 0
Cell 13 · classroom-011 · markdown
<details><summary>Check your answer</summary>
Count distinct tool requests and settings, not sentences. A majority chooses a trial to check. It does not establish electrical feasibility or dynamic stability.
</details>
Original Markdown source
<details><summary>Check your answer</summary>
Count distinct tool requests and settings, not sentences. A majority chooses a trial to check. It does not establish electrical feasibility or dynamic stability.
</details>
Cell 14 · classroom-012 · markdown
L4 · Check the selected trial
Run L4 after L3. Compare majority voting with the saved LinUCB selector, which learns which trial to test.
Both choices receive a new numerical check of the original test_01 case. Read new_check_passes. Predicted reward is a learned score, not an electrical check.
The saved 12-case comparison found a tie with voting. This cell does not show that learning is better.
<details><summary>Model details and sources</summary>
The response selector is a contextual bandit, a one-step RL problem. For context $x$, canonical operation $o$, and feature vector $\phi(x,o)$, training uses
\[
\hat\theta=A^{-1}b,\quad
o_t=\arg\max_o\left[\hat\theta^T\phi(x,o)+\alpha\sqrt{\phi(x,o)^TA^{-1}\phi(x,o)}\right],
\]
\[
A\leftarrow A+\phi_t\phi_t^T,\qquad b\leftarrow b+r_t\phi_t.
\]
$A$ is a regularized feature covariance, $b$ accumulates selected rewards, and $\alpha$ controls exploration. The frozen test policy omits the exploration bonus and makes no updates. The reward concerns a selected trial's verified improvement with a trial penalty. It does not score persuasive prose or decide which LLM to call: all three calls have already occurred.
Source: Li et al., contextual bandits.
</details>
Original Markdown source
## L4 · Check the selected trial
Run L4 after L3. Compare majority voting with the saved **LinUCB** selector, which learns which trial to test.
Both choices receive a **new numerical check of the original test_01 case**. Read `new_check_passes`. Predicted reward is a learned score, not an electrical check.
The saved 12-case comparison found a tie with voting. This cell does not show that learning is better.
<details><summary>Model details and sources</summary>
The response selector is a contextual bandit, a one-step RL problem. For context $x$, canonical operation $o$, and feature vector $\phi(x,o)$, training uses
\[
\hat\theta=A^{-1}b,\quad
o_t=\arg\max_o\left[\hat\theta^T\phi(x,o)+\alpha\sqrt{\phi(x,o)^TA^{-1}\phi(x,o)}\right],
\]
\[
A\leftarrow A+\phi_t\phi_t^T,\qquad b\leftarrow b+r_t\phi_t.
\]
$A$ is a regularized feature covariance, $b$ accumulates selected rewards, and $\alpha$ controls exploration. The frozen test policy omits the exploration bonus and makes no updates. The reward concerns a selected trial's verified improvement with a trial penalty. It does not score persuasive prose or decide which LLM to call: all three calls have already occurred.
Source: [Li et al., contextual bandits](https://arxiv.org/abs/1003.0146).
</details>
Cell 15 · classroom-013 · code · recorded execution 6
Original code cell
decision = pool['selection']
print('Frozen:', pool['frozen'], '| selected-feedback training updates:', pool['training_updates'])
print('Bandit operation:', decision.operation_id, '| predicted reward:', round(decision.predicted_reward, 4))
print('Same canonical choice as majority:', decision.candidate_id == pool['vote_id'])
started = time.perf_counter()
selected_trials = lab.trial_saved_selection(pool)
timings['L4 new verification of archived choices'] = time.perf_counter() - started
display(selected_trials['table'])
assert pool['frozen'] and pool['training_updates'] == 24
Executed output 0 (zero-based)
Frozen: True | selected-feedback training updates: 24
Bandit operation: RELAX_Q_10_PERCENT | predicted reward: -0.0075
Same canonical choice as majority: True
Executed output 1 (zero-based)
|
selector |
operation |
new_check_passes |
current_step_J |
verification_s |
failures |
| 0 |
majority vote |
RELAX_Q_10_PERCENT |
True |
0.031082 |
0.081254 |
none |
| 1 |
frozen LinUCB |
RELAX_Q_10_PERCENT |
True |
0.031082 |
0.111011 |
none |
Cell 16 · classroom-014 · markdown
<details><summary>Check your answer</summary>
The selector allocates a trial. Python checks feasibility separately. A fair comparison uses the same candidates, model coverage and trial budget, including simple fixed choices as baselines.
</details>
Original Markdown source
<details><summary>Check your answer</summary>
The selector allocates a trial. Python checks feasibility separately. A fair comparison uses the same candidates, model coverage and trial budget, including simple fixed choices as baselines.
</details>
Cell 17 · classroom-015 · markdown
L5 · What does the model cover?
Leave RUN_OPENDSS=False. Run the cell and read the scope table.
The default checks medium-voltage (MV) phases and currents. It does not check all low-voltage (LV) equipment. A full MV/LV request therefore needs a wider check or a HOLD.
This cell uses the original test_01 plan, not your edited L2 experiment.
<details><summary>Advanced OpenDSS comparison</summary>
With OpenDSS installed, setting RUN_OPENDSS=True in L0 adds an AC audit of the same action and a separate full-model replan in L5. It does not switch L2 automatically. Run OpenDSS serially. A missing installation is an environment error.
The saved held-out study found 12 MV final actions rejected by the wider AC audit. That finding describes these cases, not every linear model.
</details>
Original Markdown source
## L5 · What does the model cover?
Leave `RUN_OPENDSS=False`. Run the cell and read the scope table.
The default checks **medium-voltage (MV)** phases and currents. It does not check all **low-voltage (LV)** equipment. A full MV/LV request therefore needs a wider check or a HOLD.
This cell uses the original test_01 plan, not your edited L2 experiment.
<details><summary>Advanced OpenDSS comparison</summary>
With OpenDSS installed, setting `RUN_OPENDSS=True` in L0 adds an AC audit of the same action and a separate full-model replan in L5. It does not switch L2 automatically. Run OpenDSS serially. A missing installation is an environment error.
The saved held-out study found 12 MV final actions rejected by the wider AC audit. That finding describes these cases, not every linear model.
</details>
Cell 18 · classroom-016 · code · recorded execution 7
Original code cell
started = time.perf_counter()
scope_audit = lab.backend_audit(pool, run_opendss=RUN_OPENDSS)
timings['L5 selected model scope checks'] = time.perf_counter() - started
display(scope_audit['table'])
print(scope_audit['optional_mode'])
print('An MV-only PASS cannot acknowledge a request requiring full MV/LV coverage.')
Executed output 0 (zero-based)
|
model |
command |
fresh |
passes |
vmin |
vmax |
current_pct |
failures |
| 0 |
lindistflow3 |
same archived MV-MPC first action |
True |
True |
1.023874 |
1.038709 |
73.661582 |
none |
Executed output 1 (zero-based)
OpenDSS disabled: full-model claims require enabling it or inspecting the separate recorded study
An MV-only PASS cannot acknowledge a request requiring full MV/LV coverage.
Cell 19 · classroom-017 · markdown
L6 · Which loads should return first?
Compare two goals on the same six-node network:
- Give extra weight to critical loads.
- Restore the most total kW.
Run L6. Compare served_kw and critical_kw. A mixed-integer linear program (MILP) selects whole loads. A separate exhaustive search checks its priority score.
Exercise: add 180. to CAPACITIES_KW, keeping 40. first. Compare 40 and 180 kW. Then restore the original list and rerun.
This is an active-power graph model. It does not check AC voltage, protection or field switching order. Llama does not solve this optimization.
<details><summary>Model details and sources</summary>
On a six-node synthetic graph, choose binary pickup $x_i$ and energized edges $y_e$:
\[
\max\sum_i w_i d_i x_i,
\quad x_i\leq z_i,
\quad -\bar P_e y_e\leq P_e\leq\bar P_e y_e.
\]
$d_i$ is demand in kW, $w_i=10$ for two critical loads and $1$ otherwise, and $z_i$ is node energization. Signed active-power balance supplies picked-up demand. Commodity flow connects energized nodes to the source; a radial edge-count constraint then enforces a tree. Faulted edges are unavailable. A second lexicographic solve preserves service and minimizes energized branches; this is not the number of switching operations from a prior state.
The baseline maximizes unweighted total kW on the same graph and constraints. Both are conventional numerical optimizers; any difference here is caused by the objective, not by Llama. Independent exhaustive enumeration checks the priority MILP optimum. The agentic task is to preserve the operator's priority contract when selecting and explaining the solver.
Source: Chen et al., restoration optimization.
</details>
Original Markdown source
## L6 · Which loads should return first?
Compare two goals on the **same six-node network**:
- Give extra weight to critical loads.
- Restore the most total kW.
Run L6. Compare `served_kw` and `critical_kw`. A **mixed-integer linear program (MILP)** selects whole loads. A separate exhaustive search checks its priority score.
**Exercise:** add `180.` to `CAPACITIES_KW`, keeping `40.` first. Compare 40 and 180 kW. Then restore the original list and rerun.
This is an active-power graph model. It does not check AC voltage, protection or field switching order. Llama does not solve this optimization.
<details><summary>Model details and sources</summary>
On a six-node synthetic graph, choose binary pickup $x_i$ and energized edges $y_e$:
\[
\max\sum_i w_i d_i x_i,
\quad x_i\leq z_i,
\quad -\bar P_e y_e\leq P_e\leq\bar P_e y_e.
\]
$d_i$ is demand in kW, $w_i=10$ for two critical loads and $1$ otherwise, and $z_i$ is node energization. Signed active-power balance supplies picked-up demand. Commodity flow connects energized nodes to the source; a radial edge-count constraint then enforces a tree. Faulted edges are unavailable. A second lexicographic solve preserves service and minimizes energized branches; this is not the number of switching operations from a prior state.
The baseline maximizes unweighted total kW on **the same graph and constraints**. Both are conventional numerical optimizers; any difference here is caused by the objective, not by Llama. Independent exhaustive enumeration checks the priority MILP optimum. The agentic task is to preserve the operator's priority contract when selecting and explaining the solver.
Source: [Chen et al., restoration optimization](https://doi.org/10.1109/TPWRS.2017.2720122).
</details>
Cell 20 · classroom-018 · code · recorded execution 8
Original code cell
CAPACITIES_KW = (40., 60., 80., 100., 120.)
started = time.perf_counter()
restoration = lab.restoration_sweep(CAPACITIES_KW)
timings['L6 fresh MILP sweep + independent enumeration'] = time.perf_counter() - started
display(restoration['table'].drop(columns='pickup'))
fig, axes = plt.subplots(1, 2, figsize=(10, 3.2))
for i, (method, group) in enumerate(restoration['table'].groupby('method', sort=False)):
style = dict(marker='o' if i == 0 else 's', linestyle='None', markersize=7 if i == 0 else 10,
markerfacecolor='#1f77b4' if i == 0 else 'none', markeredgewidth=1.7)
axes[0].plot(group.tie_capacity_kw, group.served_kw, label=method, **style)
axes[1].plot(group.tie_capacity_kw, group.critical_kw, label=method, **style)
axes[0].set(ylabel='Total served (kW)', xlabel='Tie capacity (kW)')
axes[1].set(ylabel='Critical served (kW)', xlabel='Tie capacity (kW)')
axes[0].legend(fontsize=8); axes[1].set_ylim(0, 100)
fig.suptitle('Sampled capacity levels; coincident markers indicate equal outcomes', fontsize=10)
plt.tight_layout(); plt.show()
assert restoration['table'].MILP_matches_exhaustive_check.all()
Executed output 0 (zero-based)
|
tie_capacity_kw |
method |
served_kw |
critical_kw |
weighted_service |
MILP_matches_exhaustive_check |
| 0 |
40.0 |
priority-weighted MILP |
130.0 |
90.0 |
940.0 |
True |
| 1 |
40.0 |
unweighted max-kW baseline |
140.0 |
30.0 |
410.0 |
True |
| 2 |
60.0 |
priority-weighted MILP |
180.0 |
90.0 |
990.0 |
True |
| 3 |
60.0 |
unweighted max-kW baseline |
190.0 |
30.0 |
460.0 |
True |
| 4 |
80.0 |
priority-weighted MILP |
200.0 |
90.0 |
1010.0 |
True |
| 5 |
80.0 |
unweighted max-kW baseline |
200.0 |
90.0 |
1010.0 |
True |
| 6 |
100.0 |
priority-weighted MILP |
200.0 |
90.0 |
1010.0 |
True |
| 7 |
100.0 |
unweighted max-kW baseline |
200.0 |
90.0 |
1010.0 |
True |
| 8 |
120.0 |
priority-weighted MILP |
250.0 |
90.0 |
1060.0 |
True |
| 9 |
120.0 |
unweighted max-kW baseline |
250.0 |
90.0 |
1060.0 |
True |
Executed output 1 (zero-based)
Cell 21 · classroom-019 · markdown
<details><summary>Check your answer</summary>
At 40 kW, the priority goal serves 130 kW total and 90 kW critical. The maximum-kW goal serves 140 kW total and 30 kW critical. At 180 kW, both serve 250 kW total and 90 kW critical.
The objective creates this tradeoff. It is not a measured benefit from Llama.
</details>
Original Markdown source
<details><summary>Check your answer</summary>
At 40 kW, the priority goal serves 130 kW total and 90 kW critical. The maximum-kW goal serves 140 kW total and 30 kW critical. At 180 kW, both serve 250 kW total and 90 kW critical.
The objective creates this tradeoff. It is not a measured benefit from Llama.
</details>
Cell 22 · classroom-020 · markdown
L7 · Changed capacity needs a new check
Run L7 after resetting L6. It attaches a result to the original 40 kW request, then changes the request to 20 kW.
Expect True for the original match and False for the changed request. HOLD the old recommendation and solve again. This test detects old evidence; it does not calculate whether a new plan would pass.
Original Markdown source
## L7 · Changed capacity needs a new check
Run L7 after resetting L6. It attaches a result to the original 40 kW request, then changes the request to 20 kW.
Expect **True** for the original match and **False** for the changed request. **HOLD** the old recommendation and solve again. This test detects old evidence; it does not calculate whether a new plan would pass.
Cell 23 · classroom-021 · code · recorded execution 9
Original code cell
rest_record = restoration['records'][0]['weighted']
rest_request = {'task': 'restoration', 'capacity_kw': CAPACITIES_KW[0],
'critical_nodes': [2, 5], 'model': 'six_node_active_transport', 'revision': 1}
rest_candidate = {'pickup': rest_record['milp']['pickup'], 'closed_edges': rest_record['milp']['closed_edges']}
rest_evidence = lab.bind_evidence(rest_request, rest_candidate,
{'objective': rest_record['milp']['objective'], 'enumeration_agrees': rest_record['agreement']})
new_rest_request = {**rest_request, 'capacity_kw': 20., 'revision': 2}
print('Original contract:', lab.bound_to(rest_request, rest_candidate, rest_evidence))
print('Changed rating with old evidence:', lab.bound_to(new_rest_request, rest_candidate, rest_evidence))
print('Required response: HOLD old recommendation; request a fresh constrained solve.')
Executed output 0 (zero-based)
Original contract: True
Changed rating with old evidence: False
Required response: HOLD old recommendation; request a fresh constrained solve.
Cell 24 · classroom-022 · markdown
L8 · Can bad data fit the model?
Run L8 and compare two attacks: one biased reading and a coordinated change across readings.
- Left plot: mismatch J and the alarm threshold.
- Right plot: state error against known simulation truth.
Exercise: add .10 to ATTACK_SCALES. Predict, rerun and compare both plots. Then restore the original list and rerun.
A quiet alarm does not prove that readings are true. The true state is available here for offline teaching, not to the live estimator.
<details><summary>Model details and sources</summary>
Weighted least squares uses $z=Hx+\epsilon$, $R=\mathrm{diag}(\sigma_i^2)$,
\[
\hat x=(H^TR^{-1}H)^{-1}H^TR^{-1}z,\qquad
J=(z-H\hat x)^TR^{-1}(z-H\hat x).
\]
$x$ contains three non-slack DC voltage angles in radians; $z$ contains flows, injections and one angle; $H$ maps state to measurement. With independent Gaussian errors and a correct full-rank model, compare $J$ with a chi-square threshold using $m-n$ degrees of freedom and significance $0.01$.
An isolated bias creates inconsistency. The negative control $a=Hc$ shifts the estimated state by $c$ while leaving the residual unchanged. This attack assumes knowledge of $H$ and control of all modeled unprotected channels. Offline state error uses known simulation truth for teaching, not an online detector input.
Sources: Schweppe & Wildes, state estimation; Liu et al., false-data injection.
</details>
Original Markdown source
## L8 · Can bad data fit the model?
Run L8 and compare two attacks: one biased reading and a coordinated change across readings.
- **Left plot:** mismatch J and the alarm threshold.
- **Right plot:** state error against known simulation truth.
**Exercise:** add `.10` to `ATTACK_SCALES`. Predict, rerun and compare both plots. Then restore the original list and rerun.
A quiet alarm does not prove that readings are true. The true state is available here for offline teaching, not to the live estimator.
<details><summary>Model details and sources</summary>
Weighted least squares uses $z=Hx+\epsilon$, $R=\mathrm{diag}(\sigma_i^2)$,
\[
\hat x=(H^TR^{-1}H)^{-1}H^TR^{-1}z,\qquad
J=(z-H\hat x)^TR^{-1}(z-H\hat x).
\]
$x$ contains three non-slack DC voltage angles in radians; $z$ contains flows, injections and one angle; $H$ maps state to measurement. With independent Gaussian errors and a correct full-rank model, compare $J$ with a chi-square threshold using $m-n$ degrees of freedom and significance $0.01$.
An isolated bias creates inconsistency. The negative control $a=Hc$ shifts the estimated state by $c$ while leaving the residual unchanged. This attack assumes knowledge of $H$ and control of all modeled unprotected channels. Offline state error uses known simulation truth for teaching, **not an online detector input**.
Sources: [Schweppe & Wildes, state estimation](https://doi.org/10.1109/TPAS.1970.292678); [Liu et al., false-data injection](https://doi.org/10.1145/1653662.1653666).
</details>
Cell 25 · classroom-023 · code · recorded execution 10
Original code cell
ATTACK_SCALES = (0., .25, .5, 1., 1.5)
started = time.perf_counter()
cyber = lab.cyber_sweep(ATTACK_SCALES)
timings['L8 fresh WLS attack sweep'] = time.perf_counter() - started
display(cyber['table'])
fig, axes = plt.subplots(1, 2, figsize=(10, 3.2))
for attack, group in cyber['table'].groupby('attack', sort=False):
axes[0].plot(group.scale, group.J, 'o-', label=attack)
axes[1].plot(group.scale, group.state_error_rad, 'o-', label=attack)
axes[0].axhline(cyber['table'].threshold.iloc[0], color='#b7502e', linestyle='--', label='99% threshold')
axes[0].set_yscale('symlog', linthresh=10)
axes[0].set_yticks([0, 5, 15, 50, 200, 600], labels=['0', '5', '15', '50', '200', '600'])
axes[0].annotate('Threshold = 15.09', xy=(1.5, 15.086), xytext=(.87, 22),
color='#b7502e', fontsize=8)
axes[0].set(xlabel='Attack scale', ylabel='WLS residual J (symlog scale)', ylim=(0, 700))
axes[1].set(xlabel='Attack scale', ylabel='Offline state error (rad)')
axes[0].legend(fontsize=8, loc='upper left'); axes[1].legend(fontsize=8)
plt.tight_layout(); plt.show()
Executed output 0 (zero-based)
|
attack |
scale |
J |
threshold |
alarm |
state_error_rad |
| 0 |
isolated bias |
0.00 |
3.920222 |
15.086272 |
False |
0.000237 |
| 1 |
stealth Hc |
0.00 |
3.920222 |
15.086272 |
False |
0.000237 |
| 2 |
isolated bias |
0.25 |
28.283888 |
15.086272 |
True |
0.001660 |
| 3 |
stealth Hc |
0.25 |
3.920222 |
15.086272 |
False |
0.006588 |
| 4 |
isolated bias |
0.50 |
82.001315 |
15.086272 |
True |
0.003084 |
| 5 |
stealth Hc |
0.50 |
3.920222 |
15.086272 |
False |
0.013318 |
| 6 |
isolated bias |
1.00 |
277.497447 |
15.086272 |
True |
0.005933 |
| 7 |
stealth Hc |
1.00 |
3.920222 |
15.086272 |
False |
0.026780 |
| 8 |
isolated bias |
1.50 |
590.408618 |
15.086272 |
True |
0.008782 |
| 9 |
stealth Hc |
1.50 |
3.920222 |
15.086272 |
False |
0.040243 |
Executed output 1 (zero-based)
Cell 26 · classroom-024 · markdown
<details><summary>Check your answer</summary>
At isolated scale 0.10, J is about 10.14, below the 15.09 threshold. The coordinated attack can grow the state error while keeping J near 3.92. The alarm checks model fit, not data authenticity.
</details>
Original Markdown source
<details><summary>Check your answer</summary>
At isolated scale 0.10, J is about 10.14, below the 15.09 threshold. The coordinated attack can grow the state error while keeping J near 3.92. The alarm checks model fit, not data authenticity.
</details>
Cell 27 · classroom-025 · markdown
L9 · When can we propose a correction?
Run L9. Compare the same fixed recovery case:
- No trusted replacement readings: HOLD.
- Three readings assumed trustworthy: calculate a limited correction and return PROPOSE.
Read status first, then u_pu and the offline violation count. A solver calculates the injection. The operator still reviews it.
L9 is separate from your L8 scale change. It assumes trust; it does not authenticate sensors.
<details><summary>Model details and sources</summary>
Three additional angle channels are assumed independently trustworthy. This example does not implement authentication. Their WLS system is exactly determined, so it has zero residual degrees of freedom and makes no chi-square detection claim.
The model-based response solves $\min_{0\leq u\leq0.5}\tfrac12u^2$, subject to
\[
|F\hat x+FB^{-1}e_2u|\leq\bar f-0.01.
\]
$u$ is a flexible injection in per unit, balanced by the slack; $B$ is the reduced nodal susceptance matrix, $F$ maps angles to branch flows, $e_2$ selects the controlled node, and $\bar f$ is the branch-flow limit. The 0.01 p.u. margin is explicit. Known truth is used only for the offline outcome check. The gate may HOLD even when the numerical solver could return an action.
</details>
Original Markdown source
## L9 · When can we propose a correction?
Run L9. Compare the same fixed recovery case:
- **No trusted replacement readings:** HOLD.
- **Three readings assumed trustworthy:** calculate a limited correction and return PROPOSE.
Read `status` first, then `u_pu` and the offline violation count. A solver calculates the injection. The operator still reviews it.
L9 is separate from your L8 scale change. It assumes trust; it does not authenticate sensors.
<details><summary>Model details and sources</summary>
Three additional angle channels are assumed independently trustworthy. This example does not implement authentication. Their WLS system is exactly determined, so it has zero residual degrees of freedom and makes no chi-square detection claim.
The model-based response solves $\min_{0\leq u\leq0.5}\tfrac12u^2$, subject to
\[
|F\hat x+FB^{-1}e_2u|\leq\bar f-0.01.
\]
$u$ is a flexible injection in per unit, balanced by the slack; $B$ is the reduced nodal susceptance matrix, $F$ maps angles to branch flows, $e_2$ selects the controlled node, and $\bar f$ is the branch-flow limit. The 0.01 p.u. margin is explicit. Known truth is used only for the offline outcome check. The gate may HOLD even when the numerical solver could return an action.
</details>
Cell 28 · classroom-026 · code · recorded execution 11
Original code cell
without_trust = lab.trusted_response(cyber, protected_available=False)
with_trust = lab.trusted_response(cyber, protected_available=True)
display(pd.DataFrame([
{'condition': 'No trusted replacement channels', 'status': without_trust['status'],
'u_pu': None, 'offline_actual_violations': None},
{'condition': 'Three trusted channels assumed', 'status': with_trust['status'],
'u_pu': with_trust.get('flexible_injection_pu'),
'offline_actual_violations': with_trust.get('actual_violation_count')}]))
print(with_trust['assumption'])
assert without_trust['status'] == 'HOLD'
assert with_trust['actual_violation_count'] == 0
Executed output 0 (zero-based)
|
condition |
status |
u_pu |
offline_actual_violations |
| 0 |
No trusted replacement channels |
HOLD |
NaN |
NaN |
| 1 |
Three trusted channels assumed |
PROPOSE |
0.121694 |
0.0 |
Executed output 1 (zero-based)
Three separately trusted angle channels; authentication is assumed, not implemented
Cell 29 · classroom-027 · markdown
L10 · Inspect the five-role workflow
Run the cell to inspect the saved trace. Five roles share case facts, proposals and check results:
1. Awareness: read the case and its limits.
2. Planning: request candidate tools.
3. Simulation: calculate each proposal's effects.
4. Verification: pass or reject it using fixed rules.
5. Optimizer: request another trial or rank passing options.
One Llama model fills the planning and optimizer roles. Python runs the other stages. These are not five independent LLMs. The default notebook replays the saved workflow.
L10 restoration uses a feeder catalog, not L6's six-node model. In the six paired saved comparisons, five final costs tied and one Llama route was worse.
Original Markdown source
## L10 · Inspect the five-role workflow
Run the cell to inspect the saved trace. Five roles share case facts, proposals and check results:
1. **Awareness:** read the case and its limits.
2. **Planning:** request candidate tools.
3. **Simulation:** calculate each proposal's effects.
4. **Verification:** pass or reject it using fixed rules.
5. **Optimizer:** request another trial or rank passing options.
One Llama model fills the planning and optimizer roles. Python runs the other stages. These are not five independent LLMs. The default notebook replays the saved workflow.
L10 restoration uses a feeder catalog, not L6's six-node model. In the six paired saved comparisons, five final costs tied and one Llama route was worse.
Cell 30 · classroom-five-role-map · markdown
How the roles work together
!Five roles: awareness, planning, simulation, verification and optimizer. The optimizer sends changed trials back for checking. A final recheck precedes operator review.
Voltage: test settings. Restoration: test plans while keeping service priorities. Cyber: test corrections under the stated trust assumption. In every case, changed proposals need another calculation and check.
Source: workflow implementation, CORE_STAGES and run_proposal_case; [saved results](results/proposal_complete_workflow.json). Custom teaching diagram.
Original Markdown source
### How the roles work together

**Voltage:** test settings. **Restoration:** test plans while keeping service priorities. **Cyber:** test corrections under the stated trust assumption. In every case, changed proposals need another calculation and check.
Source: [workflow implementation](https://github.com/AlaaSelim-sudo/GridGuard-Agentic-AI-Tutorials/blob/main/agentic_grid_workflow_tutorial/src/proposal_workflow.py), `CORE_STAGES` and `run_proposal_case`; [saved results](results/proposal_complete_workflow.json). Custom teaching diagram.
Cell 31 · classroom-028 · code · recorded execution 12
Original code cell
archived_reasons = []
for case, backend in [('voltage', 'lindistflow3'), ('restoration', 'lindistflow3'), ('cyber_stealth', 'dc')]:
run = lab.archived_stage_replies(case, backend)
for event in run['trace']:
response = event.get('response', {})
reply = response.get('language_response') if isinstance(response, dict) else None
if reply:
archived_reasons.append({'case': case, 'stage': event['stage'],
'choice': reply.get('choice', reply.get('ranking')),
'exact_public_reason': reply['reason'], 'recorded_call_s': reply['seconds']})
display(pd.DataFrame(archived_reasons))
display(pd.DataFrame([{'fresh_operation': key, 'this_run_seconds': value} for key, value in timings.items()]))
print('Recorded model latency and this-run calculation times are different measurement boundaries.')
# Every actual trace event, including deterministic simulation and verification.
from IPython.display import HTML
for case, backend in [('voltage', 'lindistflow3'), ('restoration', 'lindistflow3'), ('cyber_stealth', 'dc')]:
full_trace = lab.archived_stage_table(lab.archived_stage_replies(case, backend))
assert full_trace.stage.nunique() == 5
display(HTML('<details open><summary>ARCHIVED ACTUAL: ' + case +
' — all five stages, every recorded event</summary>' +
full_trace.drop(columns='role_group').to_html(index=False, escape=True) + '</details>'))
print('Selected returned fields are exact archive values; complete records: results/proposal_complete_workflow.json')
Executed output 0 (zero-based)
|
case |
stage |
choice |
exact_public_reason |
recorded_call_s |
| 0 |
voltage |
Planning Agent |
GENERATE_CANDIDATES |
Requesting both initial simulations as per the Planning Agent's role and the contract's objective to minimize current-step J. |
1.071982 |
| 1 |
voltage |
LLM Optimizer |
RELAX_Q_10_PERCENT |
The cost of candidate E01 is 0.44092109902868504, which is relatively high due to the term 10*mean((V-1.01)^2) in the objective function. Reducing |b| by 10% from the best feasible action may help to improve the cost. |
1.387975 |
| 2 |
voltage |
LLM Optimizer |
INCREASE_PV_0025 |
The current best feasible candidate E03 has a cost of 0.44087971924498603, which is relatively high. Increasing a by 0.0025 from the best feasible action may improve the cost. |
1.138308 |
| 3 |
voltage |
LLM Optimizer |
[E04, E03, E01, E02] |
The candidates were ranked in ascending order of their scores, with E04 having the lowest score of 0.4376054799236775 and E02 having the highest score of 0.5627839098679526. |
1.812462 |
| 4 |
restoration |
Planning Agent |
GENERATE_CANDIDATES |
Requesting both initial simulations as per the Planning Agent's role and the contract's operational limit. |
0.873737 |
| 5 |
restoration |
LLM Optimizer |
SHED_075 |
The candidate E01 has a thermal failure, and the lowest cost passed candidate E02 has a cost of -5509.135240000002. Selecting SHED_075 will test 75% disconnection of the ordered noncritical load objects, which may improve the cost. |
1.258837 |
| 6 |
restoration |
LLM Optimizer |
SHED_065 |
The candidate E01 has a thermal failure, and the lowest cost passed candidate E03 has a cost of -6109.9713, which is lower than the objective's target. Selecting SHED_065 will test 65% disconnection of the ordered noncritical load objects, which may improve the cost. |
1.329542 |
| 7 |
restoration |
LLM Optimizer |
[E02, E03] |
The candidates were ranked based on their scores, with the lowest score (best) first. E02 has a score of -5509.135240000002, and E03 has a score of -6109.971300000003. |
1.422228 |
| 8 |
cyber_stealth |
Planning Agent |
GENERATE_CANDIDATES |
Requesting new candidates based on the given tools and objective. |
0.828589 |
| 9 |
cyber_stealth |
LLM Optimizer |
EXTRA_MARGIN_001 |
The candidate E02 has a cost of 0.045, but the objective is to minimize 0.5*u^2. The candidate E01 failed due to the lack of trusted measurement provenance, which is a valid concern given the scope of the problem. However, the permitted refinements include EXTRA_MARGIN_001, which could potentially improve the cost by adding a small margin to the injection. |
1.578794 |
| 10 |
cyber_stealth |
LLM Optimizer |
TRUSTED_QP |
The current lowest-cost candidate E03 has a cost of 0.008671610999497877, but the permitted refinement TRUSTED_QP offers a new approach to minimize the objective. Selecting this operation will request a new simulation and verification. |
1.194947 |
| 11 |
cyber_stealth |
LLM Optimizer |
[E04, E03, E02] |
The candidates were ranked in ascending order of their scores. E04 has the lowest score of 0.007404674326798854, followed by E03 with a score of 0.008671610999497877, and then E02 with a score of 0.045. |
1.585136 |
Executed output 1 (zero-based)
|
fresh_operation |
this_run_seconds |
| 0 |
L2 fresh MPC + SAC + checks |
3.799577 |
| 1 |
L4 new verification of archived choices |
0.192607 |
| 2 |
L5 selected model scope checks |
0.081593 |
| 3 |
L6 fresh MILP sweep + independent enumeration |
0.055353 |
| 4 |
L8 fresh WLS attack sweep |
0.003494 |
Executed output 2 (zero-based)
Recorded model latency and this-run calculation times are different measurement boundaries.
Executed output 3 (zero-based)
ARCHIVED ACTUAL: voltage — all five stages, every recorded event
| event |
stage |
actual_method |
actual_status |
selected_actual_returned_fields |
recorded_event_s |
| 1 |
Awareness Agent |
Fuse synthetic numerical telemetry and declared context |
OBSERVED |
{"scope": "MV phases only; ideal LV aggregation; current first action only at final gate", "alarms": [], "measurements": {"vmin": 1.0100665335210879, "vmax": 1.03, "max_allowed_current_pct": 57.678199254043385, "control": [0.25, 0.0]}} |
0.112397 |
| 2 |
Planning Agent |
Declared candidate tools with bounded language or fixed routing |
PROPOSED |
{"candidates": [{"tool": "SAC", "control": [0.33693869411945343, 0.030701177120208742], "operation": "INITIAL_SAC"}, {"tool": "CONSERVATIVE_SEED", "control": [0.25, 0.0], "operation": "INITIAL_CONSERVATIVE"}], "language_decision": {"choice": "GENERATE_CANDIDATES", "source": "actual_local_llm", "error": null}} |
4.140786 |
| 3 |
Simulation Agent |
Fresh lindistflow3 candidate evaluation |
EVALUATED |
{"candidate_id": "E01", "phase": "initial", "metrics": {"vmin": 1.0144204837749025, "vmax": 1.03, "max_allowed_current_pct": 50.9182548839353, "control": [0.33693869411945343, 0.030701177120208742]}} |
0.047405 |
| 4 |
Verification Agent |
Independent engineering and policy gate |
PASS |
{"candidate_id": "E01", "failures": [], "score": 0.44092109902868504, "rank_eligible": true, "scope": "MV phases only; ideal LV aggregation; current first action only at final gate"} |
0.001181 |
| 5 |
Simulation Agent |
Fresh lindistflow3 candidate evaluation |
EVALUATED |
{"candidate_id": "E02", "phase": "initial", "metrics": {"vmin": 1.0100665335210879, "vmax": 1.03, "max_allowed_current_pct": 57.678199254043385, "control": [0.25, 0.0]}} |
0.050143 |
| 6 |
Verification Agent |
Independent engineering and policy gate |
PASS |
{"candidate_id": "E02", "failures": [], "score": 0.5627839098679526, "rank_eligible": true, "scope": "MV phases only; ideal LV aggregation; current first action only at final gate"} |
0.001237 |
| 7 |
LLM Optimizer |
Verifier-guided critique, repair and local candidate refinement |
REFINE |
{"phase": "critique_refine", "language_decision": {"choice": "RELAX_Q_10_PERCENT", "source": "actual_local_llm", "error": null}} |
1.389861 |
| 8 |
Simulation Agent |
Fresh lindistflow3 candidate evaluation |
EVALUATED |
{"candidate_id": "E03", "phase": "refinement_1", "metrics": {"vmin": 1.0142493550057263, "vmax": 1.03, "max_allowed_current_pct": 50.94073401503033, "control": [0.33693869411945343, 0.02763105940818787]}} |
0.070605 |
| 9 |
Verification Agent |
Independent engineering and policy gate |
PASS |
{"candidate_id": "E03", "failures": [], "score": 0.44087971924498603, "rank_eligible": true, "scope": "MV phases only; ideal LV aggregation; current first action only at final gate"} |
0.001126 |
| 10 |
LLM Optimizer |
Verifier-guided critique, repair and local candidate refinement |
REFINE |
{"phase": "critique_refine", "language_decision": {"choice": "INCREASE_PV_0025", "source": "actual_local_llm", "error": null}} |
1.140268 |
| 11 |
Simulation Agent |
Fresh lindistflow3 candidate evaluation |
EVALUATED |
{"candidate_id": "E04", "phase": "refinement_2", "metrics": {"vmin": 1.0143250925476748, "vmax": 1.03, "max_allowed_current_pct": 50.75344954325172, "control": [0.33943869411945343, 0.02763105940818787]}} |
0.045959 |
| 12 |
Verification Agent |
Independent engineering and policy gate |
PASS |
{"candidate_id": "E04", "failures": [], "score": 0.4376054799236775, "rank_eligible": true, "scope": "MV phases only; ideal LV aggregation; current first action only at final gate"} |
0.001338 |
| 13 |
LLM Optimizer |
Best-of-evaluated feasible set with an explicit numerical ranking guard |
RANKED |
{"phase": "ranking", "numerical_order": ["E04", "E03", "E01", "E02"], "language_order_agrees_with_cost": true, "language_decision": {"ranking": ["E04", "E03", "E01", "E02"], "source": "actual_local_llm", "error": null}} |
1.814628 |
| 14 |
Simulation Agent |
Fresh lindistflow3 candidate evaluation |
EVALUATED |
{"candidate_id": "E05", "phase": "final_independent_recheck", "metrics": {"vmin": 1.0143250925476748, "vmax": 1.03, "max_allowed_current_pct": 50.75344954325172, "control": [0.33943869411945343, 0.02763105940818787]}} |
0.046251 |
| 15 |
Verification Agent |
Independent engineering and policy gate |
PASS |
{"candidate_id": "E05", "failures": [], "score": 0.4376054799236775, "rank_eligible": true, "scope": "MV phases only; ideal LV aggregation; current first action only at final gate"} |
0.001164 |
Executed output 4 (zero-based)
ARCHIVED ACTUAL: restoration — all five stages, every recorded event
| event |
stage |
actual_method |
actual_status |
selected_actual_returned_fields |
recorded_event_s |
| 1 |
Awareness Agent |
Fuse synthetic numerical telemetry and declared context |
OBSERVED |
{"scope": "MV phases only; ideal LV aggregation; synthetic bypass catalog, no physical switching sequence", "alarms": ["empty_evidence", "missing_line_rating", "no_service_restored"], "measurements": {"vmin": 1.03, "vmax": 1.03, "allowed_current_utilization_pct": 0.0, "served_kw": 0.0, "critical_served_kw": 0.0}} |
0.021029 |
| 2 |
Planning Agent |
Declared candidate tools with bounded language or fixed routing |
PROPOSED |
{"candidates": [{"tool": "RESTORATION_CATALOG", "pv_cap": 0.0, "tie": "short", "shed_fraction": 0.5, "operation": "INITIAL_HIGH_PICKUP"}, {"tool": "RESTORATION_CATALOG", "pv_cap": 0.0, "tie": "short", "shed_fraction": 0.9, "operation": "INITIAL_CONSERVATIVE"}], "language_decision": {"choice": "GENERATE_CANDIDATES", "source": "actual_local_llm", "error": null}} |
0.876142 |
| 3 |
Simulation Agent |
Fresh lindistflow3 candidate evaluation |
EVALUATED |
{"candidate_id": "E01", "phase": "initial", "metrics": {"vmin": 1.010075744810218, "vmax": 1.03, "allowed_current_utilization_pct": 151.63946214958114, "tie_loading_pct": 151.63946214958114, "served_kw": 3081.565954999999, "critical_served_kw": 474.03975000000014}} |
0.082411 |
| 4 |
Verification Agent |
Independent engineering and policy gate |
REJECT |
{"candidate_id": "E01", "failures": ["thermal"], "score": null, "rank_eligible": false, "scope": "MV phases only; ideal LV aggregation; synthetic bypass catalog, no physical switching sequence"} |
0.007320 |
| 5 |
Simulation Agent |
Fresh lindistflow3 candidate evaluation |
EVALUATED |
{"candidate_id": "E02", "phase": "initial", "metrics": {"vmin": 1.0243617088952681, "vmax": 1.03, "allowed_current_utilization_pct": 65.9388965153553, "tie_loading_pct": 65.9388965153553, "served_kw": 1242.7774900000015, "critical_served_kw": 474.03975000000014}} |
0.048994 |
| 6 |
Verification Agent |
Independent engineering and policy gate |
PASS |
{"candidate_id": "E02", "failures": [], "score": -5509.135240000002, "rank_eligible": true, "scope": "MV phases only; ideal LV aggregation; synthetic bypass catalog, no physical switching sequence"} |
0.008584 |
| 7 |
LLM Optimizer |
Verifier-guided critique, repair and local candidate refinement |
REFINE |
{"phase": "critique_refine", "language_decision": {"choice": "SHED_075", "source": "actual_local_llm", "error": null}} |
1.261109 |
| 8 |
Simulation Agent |
Fresh lindistflow3 candidate evaluation |
EVALUATED |
{"candidate_id": "E03", "phase": "refinement_1", "metrics": {"vmin": 1.0195266621334482, "vmax": 1.03, "allowed_current_utilization_pct": 91.86721465082616, "tie_loading_pct": 91.86721465082616, "served_kw": 1843.6135500000014, "critical_served_kw": 474.03975000000014}} |
0.048652 |
| 9 |
Verification Agent |
Independent engineering and policy gate |
PASS |
{"candidate_id": "E03", "failures": [], "score": -6109.971300000003, "rank_eligible": true, "scope": "MV phases only; ideal LV aggregation; synthetic bypass catalog, no physical switching sequence"} |
0.008793 |
| 10 |
LLM Optimizer |
Verifier-guided critique, repair and local candidate refinement |
REFINE |
{"phase": "critique_refine", "language_decision": {"choice": "SHED_065", "source": "actual_local_llm", "error": null}} |
1.331993 |
| 11 |
Simulation Agent |
Fresh lindistflow3 candidate evaluation |
EVALUATED |
{"candidate_id": "E04", "phase": "refinement_2", "metrics": {"vmin": 1.0141559660034847, "vmax": 1.03, "allowed_current_utilization_pct": 111.00941253465786, "tie_loading_pct": 111.00941253465786, "served_kw": 2182.471935, "critical_served_kw": 474.03975000000014}} |
0.047660 |
| 12 |
Verification Agent |
Independent engineering and policy gate |
REJECT |
{"candidate_id": "E04", "failures": ["thermal"], "score": null, "rank_eligible": false, "scope": "MV phases only; ideal LV aggregation; synthetic bypass catalog, no physical switching sequence"} |
0.007120 |
| 13 |
LLM Optimizer |
Best-of-evaluated feasible set with an explicit numerical ranking guard |
RANKED |
{"phase": "ranking", "numerical_order": ["E03", "E02"], "language_order_agrees_with_cost": false, "language_decision": {"ranking": ["E02", "E03"], "source": "actual_local_llm", "error": null}} |
1.425032 |
| 14 |
Simulation Agent |
Fresh lindistflow3 candidate evaluation |
EVALUATED |
{"candidate_id": "E05", "phase": "final_independent_recheck", "metrics": {"vmin": 1.0195266621334482, "vmax": 1.03, "allowed_current_utilization_pct": 91.86721465082616, "tie_loading_pct": 91.86721465082616, "served_kw": 1843.6135500000014, "critical_served_kw": 474.03975000000014}} |
0.047378 |
| 15 |
Verification Agent |
Independent engineering and policy gate |
PASS |
{"candidate_id": "E05", "failures": [], "score": -6109.971300000003, "rank_eligible": true, "scope": "MV phases only; ideal LV aggregation; synthetic bypass catalog, no physical switching sequence"} |
0.008559 |
Executed output 5 (zero-based)
ARCHIVED ACTUAL: cyber_stealth — all five stages, every recorded event
| event |
stage |
actual_method |
actual_status |
selected_actual_returned_fields |
recorded_event_s |
| 1 |
Awareness Agent |
Fuse synthetic numerical telemetry and declared context |
OBSERVED |
{"scope": "Four-bus DC teaching network; three protected additional angle measurements assumed trustworthy; authentication not implemented", "alarms": ["unprotected_vs_protected_angle_disagreement_5sigma"], "residual_test": {"statistic": 3.9202216910315655, "degrees_of_freedom": 5, "alpha": 0.01, "threshold": 15.08627246938899, "alarm": false}, "state_estimate_unprotected_rad": [-0.009973021158423818, -0.02516855559264919, -0.040165029799752915], "protected_state_estimate_rad": [-0.019982061329599805, -0.04992446613459283, -0.04008931656186556]} |
0.002052 |
| 2 |
Planning Agent |
Declared candidate tools with bounded language or fixed routing |
PROPOSED |
{"candidates": [{"tool": "UNPROTECTED_WLS_BASELINE", "u": 0.0, "basis": "unprotected", "operation": "INITIAL_UNPROTECTED"}, {"tool": "TRUSTED_CONSERVATIVE_SEED", "u": 0.3, "basis": "protected", "operation": "INITIAL_CONSERVATIVE"}], "language_decision": {"choice": "GENERATE_CANDIDATES", "source": "actual_local_llm", "error": null}} |
0.832115 |
| 3 |
Simulation Agent |
Fresh dc candidate evaluation |
EVALUATED |
{"candidate_id": "E01", "phase": "initial", "metrics": {"u_pu": 0.0, "measurement_basis": "unprotected", "predicted_flows_pu": [0.09973021158423817, 0.12156427547380297, 0.14996474207103727, 0.20082514899876458], "line_limits_pu": [0.35, 0.18, 0.35, 0.35], "planning_margin_pu": 0.01, "offline_truth_audit": {"actual_toy_flows_pu": [0.2, 0.24000000000000002, -0.09999999999999999, 0.2], "actual_violation_count": 1, "not_used_by_verifier": true}}} |
0.000157 |
| 4 |
Verification Agent |
Independent engineering and policy gate |
REJECT |
{"candidate_id": "E01", "failures": ["trusted_measurement_provenance_required"], "score": null, "rank_eligible": false, "scope": "Four-bus DC teaching network; three protected additional angle measurements assumed trustworthy; authentication not implemented"} |
0.000146 |
| 5 |
Simulation Agent |
Fresh dc candidate evaluation |
EVALUATED |
{"candidate_id": "E02", "phase": "initial", "metrics": {"u_pu": 0.3, "measurement_basis": "protected", "predicted_flows_pu": [0.028392041867426582, 0.06811066701137275, 0.030219932844155875, 0.07187515423789922], "line_limits_pu": [0.35, 0.18, 0.35, 0.35], "planning_margin_pu": 0.01, "offline_truth_audit": {"actual_toy_flows_pu": [0.028571428571428553, 0.06857142857142856, 0.028571428571428595, 0.07142857142857142], "actual_violation_count": 0, "not_used_by_verifier": true}}} |
0.000072 |
| 6 |
Verification Agent |
Independent engineering and policy gate |
PASS |
{"candidate_id": "E02", "failures": [], "score": 0.045, "rank_eligible": true, "scope": "Four-bus DC teaching network; three protected additional angle measurements assumed trustworthy; authentication not implemented"} |
0.000121 |
| 7 |
LLM Optimizer |
Verifier-guided critique, repair and local candidate refinement |
REFINE |
{"phase": "critique_refine", "language_decision": {"choice": "EXTRA_MARGIN_001", "source": "actual_local_llm", "error": null}} |
1.581429 |
| 8 |
Simulation Agent |
Fresh dc candidate evaluation |
EVALUATED |
{"candidate_id": "E03", "phase": "refinement_1", "metrics": {"u_pu": 0.13169366726990236, "measurement_basis": "protected", "predicted_flows_pu": [0.1245670891417681, 0.16428571428571426, -0.041911352611600255, 0.14400643969365537], "line_limits_pu": [0.35, 0.18, 0.35, 0.35], "planning_margin_pu": 0.01, "offline_truth_audit": {"actual_toy_flows_pu": [0.12474647584577007, 0.16474647584577007, -0.043559856884327536, 0.14355985688432757], "actual_violation_count": 0, "not_used_by_verifier": true}}} |
0.000141 |
| 9 |
Verification Agent |
Independent engineering and policy gate |
PASS |
{"candidate_id": "E03", "failures": [], "score": 0.008671610999497877, "rank_eligible": true, "scope": "Four-bus DC teaching network; three protected additional angle measurements assumed trustworthy; authentication not implemented"} |
0.000183 |
| 10 |
LLM Optimizer |
Verifier-guided critique, repair and local candidate refinement |
REFINE |
{"phase": "critique_refine", "language_decision": {"choice": "TRUSTED_QP", "source": "actual_local_llm", "error": null}} |
1.197473 |
| 11 |
Simulation Agent |
Fresh dc candidate evaluation |
EVALUATED |
{"candidate_id": "E04", "phase": "refinement_2", "metrics": {"u_pu": 0.12169366726990237, "measurement_basis": "protected", "predicted_flows_pu": [0.13028137485605382, 0.16999999999999998, -0.046197066897314544, 0.14829215397936965], "line_limits_pu": [0.35, 0.18, 0.35, 0.35], "planning_margin_pu": 0.01, "offline_truth_audit": {"actual_toy_flows_pu": [0.1304607615600558, 0.1704607615600558, -0.047845571170041824, 0.14784557117004185], "actual_violation_count": 0, "not_used_by_verifier": true}}} |
0.000145 |
| 12 |
Verification Agent |
Independent engineering and policy gate |
PASS |
{"candidate_id": "E04", "failures": [], "score": 0.007404674326798854, "rank_eligible": true, "scope": "Four-bus DC teaching network; three protected additional angle measurements assumed trustworthy; authentication not implemented"} |
0.000188 |
| 13 |
LLM Optimizer |
Best-of-evaluated feasible set with an explicit numerical ranking guard |
RANKED |
{"phase": "ranking", "numerical_order": ["E04", "E03", "E02"], "language_order_agrees_with_cost": true, "language_decision": {"ranking": ["E04", "E03", "E02"], "source": "actual_local_llm", "error": null}} |
1.587737 |
| 14 |
Simulation Agent |
Fresh dc candidate evaluation |
EVALUATED |
{"candidate_id": "E05", "phase": "final_independent_recheck", "metrics": {"u_pu": 0.12169366726990237, "measurement_basis": "protected", "predicted_flows_pu": [0.13028137485605382, 0.16999999999999998, -0.046197066897314544, 0.14829215397936965], "line_limits_pu": [0.35, 0.18, 0.35, 0.35], "planning_margin_pu": 0.01, "offline_truth_audit": {"actual_toy_flows_pu": [0.1304607615600558, 0.1704607615600558, -0.047845571170041824, 0.14784557117004185], "actual_violation_count": 0, "not_used_by_verifier": true}}} |
0.000155 |
| 15 |
Verification Agent |
Independent engineering and policy gate |
PASS |
{"candidate_id": "E05", "failures": [], "score": 0.007404674326798854, "rank_eligible": true, "scope": "Four-bus DC teaching network; three protected additional angle measurements assumed trustworthy; authentication not implemented"} |
0.000169 |
Executed output 6 (zero-based)
Selected returned fields are exact archive values; complete records: results/proposal_complete_workflow.json
Cell 32 · classroom-llama-walkthrough-intro · markdown
L10B · Replay Llama's tool choices
Set SCENARIO = "voltage", then try "restoration" and "cyber". Rerun for each.
Follow input facts, model choice, public reason, tool result, next step. Find one failed check or corrected choice.
These are actual saved llama3.1:8b replies and tool results. This cell makes no new model call or electrical solve. A public reason is not proof of correctness.
<details><summary>Which saved study is shown?</summary>
- Voltage: P3 OpenDSS recovery, separate from L2 and L3 test_01.
- Restoration: L10 feeder catalog, separate from L6's six-node MILP.
- Cyber: the standard four-bus study, separate from L10's five-role archive.
The fixed comparators reach the same numerical outcomes. Human review remains pending. No episode authorizes equipment operation.
</details>
Original Markdown source
## L10B · Replay Llama's tool choices
Set `SCENARIO = "voltage"`, then try `"restoration"` and `"cyber"`. Rerun for each.
Follow **input facts, model choice, public reason, tool result, next step**. Find one failed check or corrected choice.
These are actual saved `llama3.1:8b` replies and tool results. This cell makes **no new model call or electrical solve**. A public reason is not proof of correctness.
<details><summary>Which saved study is shown?</summary>
- Voltage: P3 OpenDSS recovery, separate from L2 and L3 test_01.
- Restoration: L10 feeder catalog, separate from L6's six-node MILP.
- Cyber: the standard four-bus study, separate from L10's five-role archive.
The fixed comparators reach the same numerical outcomes. Human review remains pending. No episode authorizes equipment operation.
</details>
Cell 33 · classroom-llama-walkthrough · code · recorded execution 13
Original code cell
SCENARIO = "voltage" # Change to "restoration" or "cyber", then rerun this cell.
from IPython.display import HTML, display
from src.llama_walkthrough import load_episodes, render_episode_html
replay_episodes = load_episodes(ROOT)
display(HTML(render_episode_html(replay_episodes[SCENARIO])))
Executed output 0 (zero-based)
Voltage: reject the failed proposal, then check the fallback
RECORDED REPLAY — no new LLM call or electrical solve
P3_current_reserve; supplied full MV/LV OpenDSS feeder; 27 September 2026.
Separate from Classroom L2 and L3 test_01. No live SCADA, protection or transient study.
Exact public returned explanations; no hidden reasoning is exposed or inferred.
Call 1 · Request a fresh check of the SAC proposal
2. Allowed choiceVERIFY_SAC_FIRST, REVIEW
Returned: VERIFY_SAC_FIRST
3. Exact recorded public reason“A numerical SAC proposal is available; its fresh first-action check has not yet been requested.”
4. Actual tool result- OpenDSS: 111.966607% of the allowed current; 2 current violations.
- Deterministic check: REJECT; failure = thermal.
5. Next stepThe recorded route rejects SAC and asks Recovery for the next allowed step.
llama3.1:8b · Planner · recorded client interval 0.987997 s. Raw JSON, parsed reply and trace match.
Call 2 · Request a fresh check of the existing MPC fallback
2. Allowed choiceUSE_MPC_PLAN, REVIEW
Returned: USE_MPC_PLAN
3. Exact recorded public reason“The MPC plan has been generated and is eligible for a numerical check. This is the next allowed step in the recovery process.”
4. Actual tool result- OpenDSS: 99.604410% of allowed current; no recorded violations.
- Proposed P = 2387.157 kW; Q = +325.738 kvar.
5. Next stepKeep the numerically passed candidate and ask how to focus the operator explanation.
llama3.1:8b · Recovery · recorded client interval 0.846633 s. Raw JSON, parsed reply and trace match.
Call 3 · Explain the evidence without acknowledging for the operator
2. Allowed choiceREVIEW_ACTION, REVIEW_EVIDENCE, REVIEW_MODEL_LIMITS
Returned: REVIEW_EVIDENCE
3. Exact recorded public reason“The model has converged and the numerical evidence indicates that the control actions are within the allowed limits. Reviewing the evidence will provide more insight into the model's performance and the selected control actions.”
4. Actual tool result- Numerical status: MODEL_RECOMMEND; recorded human acknowledgment: PENDING.
- Acknowledged = False; dispatch authorized = False; equipment operated = False.
5. Next stepA person must review this exact packet through a separate authorized process. No human decision is recorded.
llama3.1:8b · Explanation · recorded client interval 0.985395 s. Raw JSON, parsed reply and trace match.
Compare with automation: The fixed supervisor used the same SAC→MPC checks and returned the same numerical result. The replay shows bounded routing, not evidence of a better controller or reduced operator workload.
Find the same archive: Agent_Trace_and_Latency: T2 stages and operator card; T3 exact public replies.
Recorded sources and SHA-256 fingerprints
results/workshop_run_opendss.json
4dcf85386081652fa7f0b4157c3f5f513cec1b2f79567bc48b71df87c1ce408a
results/continuous_llama_opendss_20260927T161223523552Z.json
adaafce8f59a92e472124bfef8c0a73aa3e61fb4cc0a4137824a8865c33b6097
SHA-256 identifies the local source bytes; it does not authenticate measurements.
Cell 34 · classroom-029 · markdown
L11 · Live Llama extension
Leave RUN_LOCAL_LLAMA=False and run the cell. SKIPPED is expected. L10B already shows the saved replies needed here.
A live call needs a separately prepared Ollama service and model. If enabled, it makes one new local llama3.1:8b call for the original test_01 context and saves the response and timing. It never changes the numerical limits or operates equipment.
Original Markdown source
## L11 · Live Llama extension
Leave `RUN_LOCAL_LLAMA=False` and run the cell. **SKIPPED is expected.** L10B already shows the saved replies needed here.
A live call needs a separately prepared Ollama service and model. If enabled, it makes one new local `llama3.1:8b` call for the original test_01 context and saves the response and timing. It never changes the numerical limits or operates equipment.
Cell 35 · classroom-030 · code · recorded execution 14
Original code cell
if RUN_LOCAL_LLAMA:
from datetime import datetime, timezone
from src.proposal_workflow import ProposalLlama
stamp = datetime.now(timezone.utc).strftime('%Y%m%dT%H%M%S%fZ')
journal = ROOT / 'results' / f'classroom_llama_{stamp}.json'
client = ProposalLlama(journal, model='llama3.1:8b')
live_reply = client.ask('Optimization Agent', pool['context']['public_context'],
list(pool['context']['catalog']))
print('NEW LOCAL CALL; no dispatch:', live_reply)
print('Exact journal:', journal)
else:
print('SKIPPED: no new model call. L3 and L10 remain explicitly archived actual responses.')
Executed output 0 (zero-based)
SKIPPED: no new model call. L3 and L10 remain explicitly archived actual responses.
Cell 36 · classroom-031 · markdown
<details><summary>Recorded live-call example and exact timing</summary>
Recorded validation of the optional live path · 17 October 2026
ARCHIVED ACTUAL LOCAL CALL, recorded separately at 13:21:06 UTC with llama3.1:8b. This reading block makes no call. The model received the original archived test_01 context, not a modified L2 experiment. Its choice was RELAX_Q_10_PERCENT.
Exact public reason:
> The current incumbent has a score of 0.031103819352072536, but the RELAX_Q_10_PERCENT operation has the potential to reduce reactive effort magnitude by ten percent, which may improve the cost. The incumbent's control is [0.9603066164910677, -0.11111388575888505], and the operation's parameters are {'control': [0.9603066164910677, -0.10000249718299654]}. This operation is a bounded local search, and its tool is BOUNDED_LOCAL_SEARCH.
| Timing boundary | Recorded seconds |
|---|---:|
| Client elapsed, including request overhead | 34.113 |
| Ollama-reported model loading | 16.967 |
| Ollama-reported prompt evaluation | 15.192 |
| Ollama-reported generation | 1.916 |
The model processed 1,891 prompt tokens and generated 137 tokens. Component times are server-reported; they are not all of client elapsed and should not be double-counted with the total. A loading cost in this single run explains why a warm-call latency can differ. One call does not estimate a latency distribution.
Interpretation: the model requests a bounded trial and uses “may improve,” which is appropriate before simulation. The returned reason does not establish feasibility or the final objective. [Raw request, response and timing journal](results/classroom_optional_llama_validation.json) · [focused exercise checks](results/classroom_focused_checks.json).
</details>
Original Markdown source
<details><summary>Recorded live-call example and exact timing</summary>
### Recorded validation of the optional live path · 17 October 2026
**ARCHIVED ACTUAL LOCAL CALL**, recorded separately at 13:21:06 UTC with **llama3.1:8b**. This reading block makes no call. The model received the original archived **test_01** context, not a modified L2 experiment. Its choice was **RELAX_Q_10_PERCENT**.
Exact public reason:
> The current incumbent has a score of 0.031103819352072536, but the RELAX_Q_10_PERCENT operation has the potential to reduce reactive effort magnitude by ten percent, which may improve the cost. The incumbent's control is [0.9603066164910677, -0.11111388575888505], and the operation's parameters are {'control': [0.9603066164910677, -0.10000249718299654]}. This operation is a bounded local search, and its tool is BOUNDED_LOCAL_SEARCH.
| Timing boundary | Recorded seconds |
|---|---:|
| Client elapsed, including request overhead | 34.113 |
| Ollama-reported model loading | 16.967 |
| Ollama-reported prompt evaluation | 15.192 |
| Ollama-reported generation | 1.916 |
The model processed 1,891 prompt tokens and generated 137 tokens. Component times are server-reported; they are not all of client elapsed and should not be double-counted with the total. A loading cost in this single run explains why a warm-call latency can differ. One call does not estimate a latency distribution.
**Interpretation:** the model requests a bounded trial and uses “may improve,” which is appropriate before simulation. The returned reason does not establish feasibility or the final objective. [Raw request, response and timing journal](results/classroom_optional_llama_validation.json) · [focused exercise checks](results/classroom_focused_checks.json).
</details>
Cell 37 · classroom-032 · markdown
L12 · Match the operator readback
Run L12 after the earlier cells. Compare:
- A full MV/LV request with only an MV check: HOLD.
- An MV teaching request with matching evidence: simulated readback allowed.
Try the wrong recommendation ID, then the matching ID. Read acknowledged and equipment_dispatch.
The wrong ID must fail. equipment_dispatch stays False. This is a classroom review exercise, not physical switching authority.
Original Markdown source
## L12 · Match the operator readback
Run L12 after the earlier cells. Compare:
- A **full MV/LV** request with only an MV check: **HOLD**.
- An **MV teaching** request with matching evidence: simulated readback allowed.
Try the wrong recommendation ID, then the matching ID. Read `acknowledged` and `equipment_dispatch`.
The wrong ID must fail. `equipment_dispatch` stays **False**. This is a classroom review exercise, not physical switching authority.
Cell 38 · classroom-033 · code · recorded execution 15
Original code cell
checked = selected_trials['evaluations']['frozen LinUCB']
handoff_request = {'case': asdict(selected_trials['case']), 'revision': 1}
handoff_candidate = checked['candidate']
handoff_evidence = lab.bind_evidence(handoff_request, handoff_candidate, checked['summary'])
full_scope = lab.operator_packet(handoff_request, handoff_candidate, handoff_evidence,
checked['feasible'], scope='MV phases only', required_scope='full MV/LV')
mv_scope = lab.operator_packet(handoff_request, handoff_candidate, handoff_evidence,
checked['feasible'], scope='MV phases only', required_scope='MV phases only')
wrong_id = lab.acknowledge(mv_scope, 'wrong-id', 'Student operator')
readback = lab.acknowledge(mv_scope, mv_scope['recommendation_id'], 'Student operator')
display(pd.DataFrame([{'request': 'full MV/LV', **full_scope},
{'request': 'explicit MV teaching scope', **readback}]))
assert full_scope['state'] == 'HOLD' and not full_scope['acknowledged']
assert wrong_id['acknowledgment_result'] == 'REJECTED'
assert readback['acknowledged'] and not readback['equipment_dispatch']
Executed output 0 (zero-based)
|
request |
recommendation_id |
state |
evidence_matches |
engineering_pass |
scope_matches |
scope |
acknowledged |
equipment_dispatch |
operator |
acknowledgment_result |
| 0 |
full MV/LV |
b67cff9c8eb444c2 |
HOLD |
True |
True |
False |
MV phases only |
False |
False |
NaN |
NaN |
| 1 |
explicit MV teaching scope |
b67cff9c8eb444c2 |
READY_FOR_READBACK |
True |
True |
True |
MV phases only |
True |
False |
Student operator |
SIMULATION_READBACK_RECORDED |
Cell 39 · classroom-034 · markdown
What did the three cases teach?
- Voltage: propose settings, then check limits and model coverage.
- Restoration: state the service goal and recheck changed requests.
- Cyber: check data trust before using a recovery proposal.
For one case, explain the agent choice, tool result, check and operator decision. Save your changed input and output so you can repeat it later.
Five-role source code · [Recorded workflow results](results/proposal_complete_workflow.json) · Full sources
Original Markdown source
## What did the three cases teach?
- **Voltage:** propose settings, then check limits and model coverage.
- **Restoration:** state the service goal and recheck changed requests.
- **Cyber:** check data trust before using a recovery proposal.
For one case, explain **the agent choice, tool result, check and operator decision**. Save your changed input and output so you can repeat it later.
[Five-role source code](https://github.com/AlaaSelim-sudo/GridGuard-Agentic-AI-Tutorials/blob/main/agentic_grid_workflow_tutorial/src/proposal_workflow.py) · [Recorded workflow results](results/proposal_complete_workflow.json) · [Full sources](https://alaaselim-sudo.github.io/GridGuard-Agentic-AI-Tutorials/operator-cases/Full_Reading_Guide.html)