Tool catalog: live notebook cells

Copy this notebook before editing it. Run setup, then ask one AI question at a time. The read questions inspect this open notebook, including unsaved or offscreen cells; the edit questions each use a different scratch cell below so one demonstration does not invalidate another. Browser-backed functions are offered to the model through the declaration note, not called directly from Python. Review each changed cell and save the copy only if you want to keep it.

Tool catalog: live notebook cells

Copy this notebook before editing it. Run setup, then ask one AI question at a time. The read questions inspect this open notebook, including unsaved or offscreen cells; the edit questions each use a different scratch cell below so one demonstration does not invalidate another. Browser-backed functions are offered to the model through the declaration note, not called directly from Python. Review each changed cell and save the copy only if you want to keep it.

from nbinlineai.tools import tools_markdown
from nbinlineai.tools import list_cells, read_cell, find_cells, insert_markdown, insert_code, replace_cell, cell_str_replace, cell_insert_line, cell_replace_lines, delete_cell, move_cell, copy_cell, split_cell, merge_cells
print("Live notebook tools imported for AI questions below.")
Live notebook tools imported for AI questions below.
print(tools_markdown(["list_cells", "read_cell"]))
Available tools (delete any line you do not want to offer):
- &`list_cells` — List live notebook cells, including unsaved edits, by ID and position.
- &`read_cell` — Read live notebook cell source, including unsaved edits, by cell ID.

Compare each AI action with the JupyterLab editor

These browser-backed functions have no direct Python-call variant. For a manual comparison, use a second disposable copy of this notebook in JupyterLab. The AI questions below run against the open first copy; manual editor actions in the second copy must not alter their scratch cells.

Tool Ordinary JupyterLab action on the second copy
list_cells Scan the cell list and note the visible order.
read_cell Open one scratch cell and read its source.
find_cells Use notebook Find to locate catalog_marker.
insert_markdown Add a Markdown cell below the current cell.
insert_code Add a code cell and leave it unrun.
replace_cell Select all source in one scratch cell and replace it.
cell_str_replace Replace one word in a scratch cell.
cell_insert_line Insert a comment line in a scratch cell.
cell_replace_lines Replace only one selected source line.
delete_cell Delete a disposable scratch cell.
move_cell Move a scratch cell after another one.
copy_cell Copy a scratch cell to a new position.
split_cell Split a scratch cell at the cursor.
merge_cells Select two adjacent scratch cells and merge them.

The editor is the normal manual route; the & questions demonstrate the corresponding controlled AI tool route and report stable IDs or edit acknowledgements.

Observed in JupyterLab (list_cells): The visible list reaches the scratch heading, then catalog-scratch-read before catalog-scratch-replace.

Observed in JupyterLab (read_cell): The editor displays catalog_marker_read = “current”.

Observed in JupyterLab (find_cells): Notebook Find showed 6/17 matches for catalog_marker.

Observed in JupyterLab (insert_markdown): A new Markdown cell immediately below it displays Disposable manual note. (e8925436).

Observed in JupyterLab (insert_code): A new unrun code cell immediately below it contains manual_inserted_code = 1 (8bb1e5bc).

Observed in JupyterLab (replace_cell): The same cell ID now contains catalog_marker_replace = 9.

Observed in JupyterLab (cell_str_replace): The same cell now reads catalog_marker_literal = “green”.

Observed in JupyterLab (cell_insert_line): A new comment line was inserted between the original two code lines.

Observed in JupyterLab (cell_replace_lines): The first line remains = 3 and the second now reads catalog_marker_lines = 5.

Observed in JupyterLab (delete_cell): Delete Cell removed that disposable cell from the saved notebook.

Observed in JupyterLab (move_cell): Move Cell Up placed the same cell ID one position earlier.

Observed in JupyterLab (copy_cell): Paste Cell Below created a second code cell with the same source (96e2dd4c).

Observed in JupyterLab (split_cell): Split Cell created a first-line cell (c9f54630) and retained the second line in the original cell.

Observed in JupyterLab (merge_cells): Merge Cell Below retained both note paragraphs in one cell (2068532f) and removed the other cell ID.

list_cells

Use list_cells(start=0, limit=20) and report the stable IDs of the first two AI question cells in this notebook. Do not execute either question.

The first two AI question cell IDs are catalog-demo-list_cells and catalog-demo-read_cell.

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

Tool Result state Submitted arguments Observed result
list_cells completed {"start":0,"limit":20} 18 live cells returned; the first two AI question IDs were catalog-demo-list_cells and catalog-demo-read_cell.

read_cell

Use read_cell(cell_id="catalog-scratch-read") and quote its current source. Edit that cell by hand first if you want to see an unsaved read.

Current source of catalog-scratch-read:

catalog_marker_read = "current"

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

Tool Result state Submitted arguments Observed result
read_cell completed {"cell_id":"catalog-scratch-read"} Read the current source of catalog-scratch-read; the saved answer quotes it.

find_cells

Use find_cells(query="catalog_marker", cell_type="code") and report the matching stable cell IDs.

Matching code cell IDs: catalog-scratch-read, catalog-scratch-replace, catalog-scratch-literal, catalog-scratch-insert, catalog-scratch-lines, catalog-scratch-delete, catalog-scratch-anchor, catalog-scratch-move, catalog-scratch-copy, catalog-scratch-split.

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

Tool Result state Submitted arguments Observed result
find_cells completed {"query":"catalog_marker","cell_type":"code"} Returned the ten matching scratch code-cell IDs listed in the answer.

insert_markdown

Use insert_markdown(content="Catalog note: inspect before saving.") to add an ordinary note after your answer. This changes the live notebook; save only if you want it.

Inserted the Markdown note after this answer in the live notebook (cell 057bc5f0-f40e-4727-a5eb-f80de2aab559). It has not been saved to disk.

Catalog note: inspect before saving.

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

Tool Result state Submitted arguments Observed result
insert_markdown completed {"content":"Catalog note: inspect before saving."} Inserted one ordinary Markdown cell after the answer; its ID matches the answer. The worked copy was saved afterward.

insert_code

Use insert_code(content="print(2 + 3)") below your answer. Show me its ID and leave it unexecuted.

Inserted unexecuted code cell 992d0183-5127-4322-b5ba-55b9002bf6f1 containing print(2 + 3). The notebook change is not saved to disk.

print(2 + 3)

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

Tool Result state Submitted arguments Observed result
insert_code completed {"content":"print(2 + 3)"} Inserted one ordinary code cell after the answer, with no execution count or outputs. The worked copy was saved afterward.

replace_cell

Use read_cell to get the complete current source of catalog-scratch-replace, including its trailing newline. Then use replace_cell with that exact expected_source and new_source catalog_marker_replace = 2\n.

Replaced catalog-scratch-replace with catalog_marker_replace = 2\n after confirming its complete source, including the trailing newline. The live notebook change is not saved to disk.

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

Tool Result state Submitted arguments Observed result
read_cell completed {"cell_id":"catalog-scratch-replace"} Read the complete current source, including its trailing newline.
replace_cell completed {"cell_id":"catalog-scratch-replace","expected_source":"catalog_marker_replace = 1\n","new_source":"catalog_marker_replace = 2\n"} Updated only the named scratch cell; the source ends in a newline. The worked copy was saved afterward.
The scratch source below was restored afterward for replay.

cell_str_replace

Use cell_str_replace on catalog-scratch-literal: replace its one occurrence of blue with green.

Replaced the single blue with green in catalog-scratch-literal. The live notebook change is not saved to disk.

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

Tool Result state Submitted arguments Observed result
cell_str_replace completed {"cell_id":"catalog-scratch-literal","old_str":"blue","new_str":"green","expected_matches":1} Changed the one occurrence of blue to green in the live scratch cell.

The worked copy was saved afterward. This scratch source is restored below for replay.

cell_insert_line

Use cell_insert_line on catalog-scratch-insert before line 2, with content # Count carefully and the complete expected_source read from that cell.

Inserted # Count carefully before line 2 of catalog-scratch-insert. The live notebook change is not saved to disk.

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

Tool Result state Submitted arguments Observed result
read_cell completed {"cell_id":"catalog-scratch-insert"} Read the complete original source, including its trailing newline.
cell_insert_line completed {"cell_id":"catalog-scratch-insert","line":2,"content":"# Count carefully","expected_source":"catalog_marker_insert = 1\ncatalog_marker_insert += 1\n"} Inserted the comment before line 2 of the live scratch cell.

The worked copy was saved afterward. This scratch source is restored below for replay.

cell_replace_lines

Use cell_replace_lines on catalog-scratch-lines to change line 2 to catalog_marker_lines = 5, with the complete expected_source read from that cell.

Changed line 2 of catalog-scratch-lines to catalog_marker_lines = 5. The live notebook change is not saved to disk.

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

Tool Result state Submitted arguments Observed result
read_cell completed {"cell_id":"catalog-scratch-lines"} Read the complete original source, including its trailing newline.
cell_replace_lines completed {"cell_id":"catalog-scratch-lines","start_line":2,"end_line":2,"content":"catalog_marker_lines = 5","expected_source":"catalog_marker_lines = 3\ncatalog_marker_lines = 4\n"} Changed only line 2 of the live scratch cell.

The worked copy was saved afterward. This scratch source is restored below for replay.

delete_cell

Use delete_cell on catalog-scratch-delete, passing its complete current source as expected_source. Report the result.

Deleted catalog-scratch-delete from the live notebook after its source matched catalog_marker_delete = 1\n. The change is not saved to disk.

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

Tool Result state Submitted arguments Observed result
read_cell completed {"cell_id":"catalog-scratch-delete"} Read the complete original source, including its trailing newline.
delete_cell completed {"cell_id":"catalog-scratch-delete","expected_source":"catalog_marker_delete = 1\n"} Deleted the named cell from the live notebook.

The worked copy was saved afterward. The deleted scratch cell is restored below for replay.

move_cell

Use move_cell(cell_id="catalog-scratch-move", after_cell_id="catalog-scratch-copy") to move the ordinary scratch cell. Then use list_cells(start=55, limit=20) to verify and report the resulting order without executing cells.

Moved catalog-scratch-move after catalog-scratch-copy. The live cell order is now catalog-scratch-copy (61) → catalog-scratch-move (62) → catalog-scratch-split (63). No cells were executed; the change is not saved to disk.

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

Tool Result state Submitted arguments Observed result
move_cell completed {"cell_id":"catalog-scratch-move","after_cell_id":"catalog-scratch-copy"} Moved the named live scratch cell after the named anchor.
list_cells completed {"start":55,"limit":20} Verified the live order after the move.

The worked copy was saved afterward. The original scratch order is restored below for replay.

copy_cell

Use copy_cell to copy catalog-scratch-copy after catalog-scratch-anchor; report the new ID and leave the copy unexecuted.

Copied catalog-scratch-copy after catalog-scratch-anchor as unexecuted cell 57435006-7e6b-414a-b3dd-3d36af557235. The change is not saved to disk.

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

Tool Result state Submitted arguments Observed result
copy_cell completed {"cell_id":"catalog-scratch-copy","after_cell_id":"catalog-scratch-anchor"} Created unexecuted code cell 57435006-7e6b-414a-b3dd-3d36af557235 directly after the anchor.

The worked copy was saved afterward. The new unexecuted copy remains below.

split_cell

Use split_cell on catalog-scratch-split before line 2, passing its complete current source as expected_source. Report both resulting IDs.

Split before line 2. The resulting cell IDs are catalog-scratch-split and d7d916b9-f8f8-4689-af6e-8895a9824ff2. The live notebook change is not saved to disk.

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

Tool Result state Submitted arguments Observed result
read_cell completed {"cell_id":"catalog-scratch-split"} Read the complete original two-line source.
split_cell completed {"cell_id":"catalog-scratch-split","line":2,"expected_source":"catalog_marker_split = 1\ncatalog_marker_split += 1\n"} Split the live source into the retained ID and new unexecuted cell d7d916b9-f8f8-4689-af6e-8895a9824ff2.

The worked copy was saved afterward. The original two-line scratch source is restored below for replay; the new unexecuted cell remains visible.

merge_cells

Use read_cell(cell_id="catalog-scratch-merge-first") and read_cell(cell_id="catalog-scratch-merge-second") to get both complete current sources. Then use merge_cells on these adjacent Markdown cells with those exact sources. After merging, call read_cell(cell_id="catalog-scratch-merge-first") once on the retained cell and report its exact merged source. End after that read.

The retained cell catalog-scratch-merge-first now contains exactly:

First disposable note.

Second disposable note.

The source ends with a newline. The change is not saved to disk.

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

Tool Result state Submitted arguments Observed result
read_cell completed {"cell_id":"catalog-scratch-merge-first"} Read the complete first Markdown source.
read_cell completed {"cell_id":"catalog-scratch-merge-second"} Read the complete second Markdown source.
merge_cells completed {"first_cell_id":"catalog-scratch-merge-first","second_cell_id":"catalog-scratch-merge-second","expected_first":"First disposable note.\n","expected_second":"Second disposable note.\n"} Merged both adjacent Markdown cells into the retained first ID.
read_cell completed {"cell_id":"catalog-scratch-merge-first"} Verified the merged source and final newline.

The worked copy was saved afterward. Both original Markdown scratch cells are restored below for replay.

Disposable scratch cells

These cells supply stable IDs and complete, short source for the edit questions. The questions may act on cells below them because live tools use the notebook model.

In the worked copy, each AI edit is observed with its before-and-after result. The disposable scratch cells are then restored to the original IDs, source, and order so you can replay the examples. Verified notes and code inserted by insert_markdown or insert_code remain visible; the inserted code is not run automatically.

catalog_marker_read = "current"
catalog_marker_replace = 1
catalog_marker_literal = "blue"
catalog_marker_insert = 1
catalog_marker_insert += 1
catalog_marker_lines = 3
catalog_marker_lines = 4
catalog_marker_delete = 1
catalog_marker_anchor = 1
catalog_marker_copy = 1
catalog_marker_move = 1
catalog_marker_copy = 1
catalog_marker_split = 1
catalog_marker_split += 1
catalog_marker_split += 1

First disposable note.

Second disposable note.

← Examples guide · Download this notebook