Tool catalog: saved notebooks

Run setup to write a tiny notebook to a temporary directory. Find the notebook, search its source, and read its real stable cell ID catalog-note. These tools inspect the saved file, so an unsaved edit in an open JupyterLab tab will not appear here. The temporary file disappears when this kernel exits.

Tool catalog: saved notebooks

Run setup to write a tiny notebook to a temporary directory. Find the notebook, search its source, and read its real stable cell ID catalog-note. These tools inspect the saved file, so an unsaved edit in an open JupyterLab tab will not appear here. The temporary file disappears when this kernel exits.

from pathlib import Path
from tempfile import TemporaryDirectory
import json
from nbinlineai.tools import list_notebooks, find_notebook_cells, read_notebook_cell, search_notebooks, notebook_outline

catalog_temp = TemporaryDirectory(prefix="nbinlineai-saved-")
catalog_root = Path(catalog_temp.name)
catalog_book = catalog_root / "lesson.ipynb"
catalog_book.write_text(json.dumps({"cells": [{"cell_type": "markdown", "id": "catalog-note", "metadata": {}, "source": ["# Observation\n", "Three visits."]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}), encoding="utf-8")
print("Saved notebook:", catalog_book)
Saved notebook: [temporary local path]

list_notebooks

print(list_notebooks(str(catalog_root)))
[temporary local path]

find_notebook_cells

print(find_notebook_cells(str(catalog_book), "visits"))
Saved source matches in [temporary local path]
- index:0 id:catalog-note (markdown): # Observation Three visits.

read_notebook_cell

print(read_notebook_cell(str(catalog_book), "catalog-note"))
Saved source from [temporary local path] index:0 id:catalog-note (markdown):
1: # Observation
2: Three visits.

search_notebooks

print(search_notebooks("visits", path=str(catalog_root)))
Saved notebook matches under [temporary local path]
[temporary local path] Three visits.

notebook_outline

print(notebook_outline(str(catalog_book)))
[temporary local path] 1 cells
0: markdown id=catalog-note # Observation Three visits.

Ask AI to inspect the saved lesson

These questions read the small notebook file created by setup. The live tab is not the source for these saved-file tools.

Use &list_notebooks under $catalog_root, then &search_notebooks for visits there. Name the saved notebook and the matching cell ID from the returned results.

Saved notebook: lesson.ipynb. Matching cell ID: catalog-note.

Observed live tool calls for the answer above (actual subscription events; private fields shortened).

Tool Submitted arguments Observed result
list_notebooks {“path”:“[temporary local path]”} ‘[temporary local path]’
search_notebooks {“path”:“[temporary local path]”,“query”:“visits”} ‘Saved notebook matches under [temporary local path] Three visits.’

Use &find_notebook_cells on $catalog_book for visits, then &read_notebook_cell with its returned stable cell ID. Quote the observation from the saved source.

“Three visits.”

Observed live tool calls for the answer above (actual subscription events; private fields shortened).

Tool Submitted arguments Observed result
find_notebook_cells {“path”:“[temporary local path]”,“query”:“visits”} ‘Saved source matches in [temporary local path] index:0 id:catalog-note (markdown): # Observation Three visits.’
read_notebook_cell {“path”:“[temporary local path]”,“cell_id”:“catalog-note”} ‘Saved source from [temporary local path] index:0 id:catalog-note (markdown):\n1: # Observation\n2: Three visits.’

Use &notebook_outline on $catalog_book. Report the Markdown heading and cell ID it returns, without treating an unsaved tab edit as saved content.

Saved Markdown heading: # Observation (cell ID: catalog-note).

Observed live tool calls for the answer above (actual subscription events; private fields shortened).

Tool Submitted arguments Observed result
notebook_outline {“path”:“[temporary local path]”} ‘[temporary local path] 1 cells\n0: markdown id=catalog-note # Observation Three visits.’

← Examples guide · Download this notebook