Work through a small shade study using three invented bench readings. Read the observations, create and revise a report, check a saved field log against a live note, and add a notebook summary. Each AI question requests a tool action you can inspect.
A shade walk with the starter tools
Work through a small shade study using three invented bench readings. Read the observations, create and revise a report, check a saved field log against a live note, and add a notebook summary. Each AI question requests a tool action you can inspect.
The five saved answers came from a real ChatGPT run. The nearby tool tables record its actual calls. The sample field note and final summary are saved examples. The code draft remains unexecuted for your review. Long tool results in the saved tables are shortened for display.
To make a fresh run:
Copy this notebook into a fresh folder and open it with a Python kernel that has nbinlineai installed.
Choose your connection and model in the notebook’s AI defaults row. If needed, set up the connection in Configure AI first.
Turn off the Keep answer checkbox beside each question’s Run button before requesting new answers.
Delete the saved summary and code draft below the last answer. If you already ran the insertion helper, delete its earlier Markdown cell headed Available tools (delete any line you do not want to offer) too.
Run Python cells with Shift+Enter and AI questions with their Run buttons, following the unsaved-edit instructions before the live-cell question.
The setup creates starter_field_study/ in the Python kernel’s current working directory. It stops if that folder already exists. The final cleanup cell removes it after you review your work.
from pathlib import Path
import json
root = Path("starter_field_study")
root.mkdir() # Stop if this name is already in use; choose another copy or clean up first.
source = root /"observations.csv"
source.write_text(
"bench,shade_minutes,temperature_c\nA,10,31\nB,35,28\nC,50,27\n",
encoding="utf-8",
)
saved_book = root /"field_log.ipynb"
saved_book.write_text(json.dumps({
"cells": [{
"cell_type": "markdown", "id": "field-log-observation", "metadata": {},
"source": [
"# Field log\n",
"STUDY_ANCHOR_SHADE: At bench B, tree shade reached the seat by 14:00; the thermometer read 28 C.\n",
],
}],
"metadata": {}, "nbformat": 4, "nbformat_minor": 5,
}, indent=2) +"\n", encoding="utf-8")
field_study = {
"root": str(root),
"source": str(source),
"report": str(root /"report.md"),
"saved_book": str(saved_book),
"saved_marker": "STUDY_ANCHOR_SHADE",
"live_cell_id": "starter-live-scratch",
}
print("Prepared", field_study["root"], "with three invented observations and one saved field log.")
Prepared starter_field_study with three invented observations and one saved field log.
Put the starter tools in the notebook
The next code cell imports the tool functions into this kernel and asks JupyterLab to insert one editable Markdown declaration beneath it. The helper returns a receipt at once. Wait until you can see the inserted note, then run the inspection cell. If the receipt reports an error, read it before you retry. A printed catalog or code output does not declare tools.
from nbinlineai.tools import*
catalog_receipt = insert_tool_catalog()
catalog_receipt
print(catalog_receipt.status, catalog_receipt.cell_id, catalog_receipt.error)
assert catalog_receipt.status =="inserted", "Wait for the note, then rerun this cell."assert catalog_receipt.cell_id
The inserted note has 19 starter declarations. Its Tools checkbox controls whether later questions can call them. Its Context checkbox controls whether its prose appears in the prompt. The two choices are independent. Even Current question only can use enabled declarations above it.
Each question includes $`field_study` to read the dictionary of file paths from this Python kernel. The reference substitutes its current value before the question reaches the model. The 19 tool names and one variable fit the limit of 20 distinct names per request.
Turn the readings into a report
The first question lists the disposable folder, reads the CSV, and creates a new report. The second question checks the report before changing one sentence. Review each answer and run the nearby Python check after the answer finishes.
Use the starter tools to begin the shade walk report. The live task is $field_study. Call list_files on its root, then view_file on its source. Confirm the three CSV rows before calling create_file at its new report path. Write this exact Markdown report from those rows:
# Shade walk: three benches
## Observations
Bench A: 10 min shade, 31 C.
Bench B: 35 min shade, 28 C.
Bench C: 50 min shade, 27 C.
## Takeaway
The shaded benches were cooler in this small sample.
## Next check
Repeat at the same hour on another day.
Say which files you saw and whether creation succeeded. If the report already exists, inspect it or clean up the earlier run before you retry.
Saw field_log.ipynb and observations.csv. Confirmed CSV rows A (10 min, 31 C), B (35 min, 28 C), and C (50 min, 27 C). Created starter_field_study/report.md successfully.
Observed live tool calls for the answer above (recorded from this worked run; long results shortened for display).
{“path”:“starter_field_study/report.md”,“contents”:“# Shade walk: three benches\n\n## Observations\nBench A: 10 min shade, 31 C.\nBench B: 35 min shade, 28 C.\nBench C: 50 min shade, 27 C.\n\n## Takeaway\nThe shaded benches were cooler in this small sample.\n\n## Next check\nRepeat at the same hour on another day.\n”}
‘Created: [local path] (253 bytes)’
report_path = Path(field_study["report"])
assert report_path.is_file(), "Run the create-report question and check its answer first."
report_text = report_path.read_text(encoding="utf-8")
assert"Bench A: 10 min shade, 31 C."in report_text
assert"Bench B: 35 min shade, 28 C."in report_text
assert"Bench C: 50 min shade, 27 C."in report_text
assert report_text.count("The shaded benches were cooler in this small sample.") ==1print(report_text)
# Shade walk: three benches
## Observations
Bench A: 10 min shade, 31 C.
Bench B: 35 min shade, 28 C.
Bench C: 50 min shade, 27 C.
## Takeaway
The shaded benches were cooler in this small sample.
## Next check
Repeat at the same hour on another day.
The first takeaway sounds too certain for three readings. The live task is $field_study. Call view_file on its report, then call file_str_replace on that path with expected_matches=1. Replace exactly The shaded benches were cooler in this small sample. with In these three observations, more shade coincided with lower temperature; this does not show cause. Read the changed file with view_file and tell me what changed.
Updated starter_field_study/report.md: the takeaway now says that more shade coincided with lower temperature in these three observations, without claiming causation. The other lines are unchanged.
Observed live tool calls for the answer above (recorded from this worked run; long results shortened for display).
‘File: [local path] # Shade walk: three benches\n2: \n3: ## Observations\n4: Bench A: 10 min shade, 31 C.\n5: Bench B: 35 min shade, 28 C.\n6: Bench C: 50 min shade, 27 C.\n7: \n8: ## Takeaway\n9: The shaded benches were cooler in this small sample.\n10: \n11: ## Next check\n12: Repeat at the same hour on another day.’
{“path”:“starter_field_study/report.md”,“old_str”:“The shaded benches were cooler in this small sample.”,“new_str”:“In these three observations, more shade coincided with lower temperature; this does not show cause.”,“expected_matches”:1}
'Updated: [local path] -8,3 +8,3 @@\n ## Takeaway\n-The shaded benches were cooler in this small sample.\n+In these three observations, more shade coincided with lower temperature; this does not show cause.\n ’
‘File: [local path] # Shade walk: three benches\n2: \n3: ## Observations\n4: Bench A: 10 min shade, 31 C.\n5: Bench B: 35 min shade, 28 C.\n6: Bench C: 50 min shade, 27 C.\n7: \n8: ## Takeaway\n9: In these three observations, more shade coincided with lower temperature; this does not show cause.\n10: \n11: ## Next check\n12: Repeat at the same hour on another day.’
report_text = Path(field_study["report"]).read_text(encoding="utf-8")
assert"In these three observations, more shade coincided with lower temperature; this does not show cause."in report_text
assert"The shaded benches were cooler in this small sample."notin report_text
print("Checked report:", field_study["report"])
Checked report: starter_field_study/report.md
Saved log and unsaved notebook note
The setup wrote the field log as a real .ipynb file. The next question searches that file on disk and reads a cell by the stable ID returned by search. The later live-cell question reads the open notebook model, including an edit you have not saved.
The live task is $field_study. Call list_notebooks under its root. On its saved_book, call find_notebook_cells for its saved_marker. Take the stable cell ID from that result and pass it to read_notebook_cell. Quote the bench B note and report the ID. Read the saved source, not a guess from this question.
Saved cell ID: field-log-observation. “At bench B, tree shade reached the seat by 14:00; the thermometer read 28 C.”
Observed live tool calls for the answer above (recorded from this worked run; long results shortened for display).
‘Saved source matches in starter_field_study/field_log.ipynb:\n- index:0 id:field-log-observation (markdown): # Field log STUDY_ANCHOR_SHADE: At bench B, tree shade reached the seat by 14:00; the thermometer read 28 C.’
‘Saved source from starter_field_study/field_log.ipynb, index:0 id:field-log-observation (markdown):\n1: # Field log\n2: STUDY_ANCHOR_SHADE: At bench B, tree shade reached the seat by 14:00; the thermometer read 28 C.’
Field note to edit in place
UNSAVED_SHADE_NOTE: At bench C, a cloud passed during the reading; revisit it.
Save this notebook. Change the sample paragraph in the Field note to edit in place cell above by adding your own observation. Leave the edit unsaved and run the next question. It uses list_cells to find the stable ID for read_cell. If autosave runs before the question, make another small edit before you run it. After the question, save the notebook to keep your note.
The live task is $field_study. Call list_cells on this open notebook and locate the ordinary Markdown cell whose stable ID is its live_cell_id. Then call read_cell with that returned ID. Quote the note’s current text, including UNSAVED_SHADE_NOTE if I added it. Do not substitute the saved .ipynb file or infer the text from this question.
Live cell starter-live-scratch currently reads:
Field note to edit in place
UNSAVED_SHADE_NOTE: At bench C, a cloud passed during the reading; revisit it.
Observed live tool calls for the answer above (recorded from this worked run; long results shortened for display).
{“cells”:[{“index”:0,“cell_id”:“starter-intro”,“cell_type”:“markdown”,“source_preview”:"# A shade walk with the starter tools\n\nWork through a small shade study using three invented bench readings. Read the observations, create and revise a report, “},{“index”:1,“cell_id”:“starter-setup”,“cell_type”:“code”,“source_preview”:“from pathlib import Path\nimport json\n\nroot = Path("starter_field_study")\nroot.mkdir() # Stop if this name is already in use; choose another copy or clean up fi”},{“index”:2,“cell_id”:“starter-catalog-guide”,“cell_type”:“markdown”,“source_preview”:”## Put the starter tools in the notebook\n\nThe next code cell imports the tool functions into this kernel and asks Ju
{“cells”:[{“index”:14,“cell_id”:“worked-trace-starter-ai-files-edit”,“cell_type”:“markdown”,“source_preview”:“Observed live tool calls for the answer above (recorded from this worked run; long results shortened for display).\n\n| Tool | Result state | Submitted arguments | Observe”},{“index”:15,“cell_id”:“starter-files-edit-check”,“cell_type”:“code”,“source_preview”:“report_text = Path(field_study["report"]).read_text(encoding="utf-8")\nassert "In these three observations, more shade coincided with lower temperature; this doe”},{“index”:16,“cell_id”:“starter-saved-guide”,“cell_type”:“markdown”,“source_preview”:"## Saved log and unsaved notebook note\n\nThe setup wrote the field log as a real `.i
1: ### Field note to edit in place 2: 3: UNSAVED_SHADE_NOTE: At bench C, a cloud passed during the reading; revisit it. 4:
Add the notebook handoff
The final question reads the checked report, inserts a short Markdown summary, and inserts a code draft that tabulates the CSV. Both new cells appear in this live notebook. The code draft has no output until you inspect and run it yourself.
The live task is $field_study. Call view_file on its report and use the revised takeaway. Call insert_markdown to add a concise ### Shade walk summary note with the three bench temperatures and the caution that three readings do not establish cause.
Then call insert_code with a Python draft. Have it read the CSV at its source path with csv.DictReader and print each bench, shade time, and temperature. Leave the code unexecuted, and tell me the two returned stable cell IDs so I can inspect both insertions.
Inserted the summary (cell f69fca89-e3b6-43f7-81dd-b5d666db2fa0) and the unexecuted CSV code draft (cell 0a795d02-2898-4528-99b9-cca82ff07989). Both are in the live notebook and have not been saved to disk.
Observed live tool calls for the answer above (recorded from this worked run; long results shortened for display).
‘File: [local path] # Shade walk: three benches\n2: \n3: ## Observations\n4: Bench A: 10 min shade, 31 C.\n5: Bench B: 35 min shade, 28 C.\n6: Bench C: 50 min shade, 27 C.\n7: \n8: ## Takeaway\n9: In these three observations, more shade coincided with lower temperature; this does not show cause.\n10: \n11: ## Next check\n12: Repeat at the same hour on another day.’
{“content”:“### Shade walk summary\n\nBench A: 31 C (10 min shade); bench B: 28 C (35 min); bench C: 27 C (50 min). In these three observations, more shade coincided with lower temperature; three readings do not establish cause.”}
Inserted Markdown cell f69fca89-e3b6-43f7-81dd-b5d666db2fa0 in the live notebook model (not saved to disk).
{“after_cell_id”:“f69fca89-e3b6-43f7-81dd-b5d666db2fa0”,“content”:“import csv\n\nwith open(‘starter_field_study/observations.csv’, newline=‘’, encoding=‘utf-8’) as file:\n for row in csv.DictReader(file):\n print(f"Bench {row[‘bench’]}: {row[‘shade_minutes’]} min shade, {row[‘temperature_c’]} C")”}
Inserted unexecuted code cell 0a795d02-2898-4528-99b9-cca82ff07989 in the live notebook model (not saved to disk).
Shade walk summary
Bench A: 31 C (10 min shade); bench B: 28 C (35 min); bench C: 27 C (50 min). In these three observations, more shade coincided with lower temperature; three readings do not establish cause.
import csv
withopen('starter_field_study/observations.csv', newline='', encoding='utf-8') as file:
for row in csv.DictReader(file):
print(f"Bench {row['bench']}: {row['shade_minutes']} min shade, {row['temperature_c']} C")
Check that the summary and code draft appeared below the last answer. The insertion receipts confirm changes to the open notebook, not a saved file. Read the draft before you run it. Use normal JupyterLab execution and check the three printed rows. Save the notebook to keep the new cells. Insertion leaves the generated code cell unexecuted.
Once an answer is complete, Keep answer makes later Run All skip that question and its tool effects. If you run a question again, inspect the report and inserted cells first. A repeat can fail or add a duplicate.
Clean up the disposable study
Copy any files you want to keep out of starter_field_study/ before cleanup. Save the notebook to keep its notes and displayed outputs. Then run the final cell to remove the setup folder and its files. It checks the expected fixture files before deletion. Leave the cell unrun if you want the CSV, field log, or report on disk.