from nbinlineai.tools import insert_markdown, list_cells, read_cell, tools_markdown
lesson_topic: str = "field observations"
print("Tools imported for this notebook.")Tools imported for this notebook.
url_to_note, is covered in the Python and web lesson. Import them in the Python kernel, then put the & references you want to offer in ordinary Markdown above the AI questions. Lower questions inherit those declarations. A direct Python call to these imported stubs raises a helpful error because JupyterLab handles their real operations.This lesson uses three browser-backed tools for the current open notebook, including unsaved edits. A fourth, url_to_note, is covered in the Python and web lesson. Import them in the Python kernel, then put the & references you want to offer in ordinary Markdown above the AI questions. Lower questions inherit those declarations. A direct Python call to these imported stubs raises a helpful error because JupyterLab handles their real operations.
from nbinlineai.tools import insert_markdown, list_cells, read_cell, tools_markdown
lesson_topic: str = "field observations"
print("Tools imported for this notebook.")Tools imported for this notebook.
print(tools_markdown(["list_cells", "read_cell", "insert_markdown"]))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.
- &`insert_markdown` — Insert a Markdown note into the current live notebook after a cell.
Run the next AI Prompt before executing the code cell below it. The list tool should still see that later, unexecuted source. It also sees unsaved source edits, unlike find_notebook_cells which reads a saved file.
list_cells: list cells in this open notebook.read_cell: read current unsaved source of one cell.insert_markdown: add an editable Markdown note.Call &list_cells with start=0 and limit=20. Tell me the ID of the code cell below this prompt and whether its source is visible even before I run it.
The code cell is future-unexecuted-cell. Yes—its source is visible before you run it.
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} | {“cells”:[{“index”:0,“cell_id”:“live-tools-intro”,“cell_type”:“markdown”,“source_preview”:“# Live notebook cells and notes\n\nThis lesson uses three browser-backed tools for the current open notebook, including unsaved edits. A fourth, url_to_note”},{“index”:1,“cell_id”:“live-tool-setup”,“cell_type”:“code”,“source_preview”:“from nbinlineai.tools import insert_markdown, list_cells, read_cell, tools_markdown\n\nlesson_topic: str = "field observations"\nprint("Tools imported for this not”},{“index”:2,“cell_id”:“live-tool-references”,“cell_type”:“code”,“source_preview”:“print(tools_markdown(["list_cells", "read_cell", "insert_markdown"]))”},{“index”:3,“cell_id”:“live-list-guide”," |
future_observation: str = "This source is below the first AI prompt and has not been run yet."This note was inserted into the live notebook; review it before saving.
Edit the source of the code cell with ID future-unexecuted-cell above, but do not run or save it yet. Add a short phrase of your own. Then run the next AI Prompt. The browser-backed reader should quote the changed live source. The Python kernel variable will still have its old value until you execute the edited code.
Call &read_cell with cell_id="future-unexecuted-cell", start_line=1, and end_line=10. Quote the numbered live source you see, including my unsaved edit if I made one.
1: future_observation: str = "This source is below the first AI prompt and has not been run yet."No unsaved edit appears in the live source.
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”:“future-unexecuted-cell”,“start_line”:1,“end_line”:10} | 1: future_observation: str = “This source is below the first AI prompt and has not been run yet.” |
The next tool changes the open notebook by adding a Markdown cell. You can inspect or edit that note before saving the notebook. A tool result is not a file save. Use JupyterLab Save to persist the new note.
Call &insert_markdown with content="### Field note\nThis note was inserted into the live notebook; review it before saving." and after_cell_id="future-unexecuted-cell". Then tell me where the new note appeared.
The note appeared immediately after future-unexecuted-cell as Markdown cell fe627d9a-35c2-4a92-8aca-488446c710ff. It’s in the live notebook but hasn’t been saved to disk.
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”:“### Field note\nThis note was inserted into the live notebook; review it before saving.”,“after_cell_id”:“future-unexecuted-cell”} | Inserted Markdown cell fe627d9a-35c2-4a92-8aca-488446c710ff in the live notebook model (not saved to disk). |
Edit or remove one & line from the ordinary Markdown declaration above, then ask a new question below it. An import alone does not register a tool. Earlier AI questions can also declare tools for lower questions; code cells and AI answers cannot.