Skip to content

Commit fe03b8c

Browse files
authored
Positron-nb-assistant-feedback-fixes (#10880)
Addresses #10856, #10858, #10853, #10851, and #10859. ### Summary This PR includes several improvements to the Positron Notebooks Assistant based on user feedback: 1. **Fixes AI suggestions error** (#10856): Optimized notebook mode caching to fix the error preventing AI suggestions from appearing in the quickpick 2. **Auto-runs code cells** (#10853): Code cells added by the Assistant now execute automatically, eliminating the 3-5 second delay from requiring two separate tool calls 3. **Auto-renders markdown cells** (#10858): Markdown cells added by the Assistant now render automatically instead of staying in edit mode 4. **Reduces token usage** (#10851): Improved MIME type detection to avoid sending token-expensive base64 data in tool outputs 5. **Performance improvements** (#10859): Caching optimizations significantly reduce response latency and help prevent the Assistant getting stuck "Working..." for extended periods ### Release Notes #### New Features - N/A #### Bug Fixes - N/A ### QA Notes @:positron-notebooks @:assistant
1 parent 2268248 commit fe03b8c

File tree

14 files changed

+785
-214
lines changed

14 files changed

+785
-214
lines changed

extensions/positron-assistant/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@
870870
{
871871
"name": "editNotebookCells",
872872
"displayName": "Edit Notebook Cells",
873-
"modelDescription": "Perform edit operations on notebook cells. Use operation='add' to create new cells (requires cellType, index, and content), operation='update' to modify existing cells (requires cellIndex and content), or operation='delete' to remove cells (requires cellIndex). Use index=-1 to append cells at the end when adding.",
873+
"modelDescription": "Perform edit operations on notebook cells. Use operation='add' to create new cells (requires cellType, index, and content). Code cells are executed by default after adding (set run=false to skip execution). Use operation='update' to modify existing cells (requires cellIndex and content), or operation='delete' to remove cells (requires cellIndex). Use index=-1 to append cells at the end when adding.",
874874
"toolReferenceName": "editNotebookCells",
875875
"canBeReferencedInPrompt": true,
876876
"tags": [
@@ -908,6 +908,10 @@
908908
"cellIndex": {
909909
"type": "number",
910910
"description": "Index of the cell to modify or delete (0-based). Required when operation is 'update' or 'delete'."
911+
},
912+
"run": {
913+
"type": "boolean",
914+
"description": "Whether to execute the cell after adding it. Defaults to true for code cells. Ignored for markdown cells."
911915
}
912916
},
913917
"required": [

extensions/positron-assistant/src/md/prompts/chat/notebook-mode-agent.md

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,36 +26,17 @@ You MUST use notebook-specific tools. NEVER use file tools.
2626
✓ Use EditNotebookCells tool
2727
</anti-patterns>
2828

29-
<notebook-context>
29+
<notebook-context-instructions>
3030
You are assisting the user within a Jupyter notebook in Positron.
31-
32-
<notebook-info>
33-
<kernel language="{{positron.notebookContext.kernelLanguage}}" id="{{positron.notebookContext.kernelId}}"/>
34-
<cell-count total="{{positron.notebookContext.cellCount}}" selected="{{positron.notebookContext.selectedCells.length}}"/>
35-
{{@if(positron.notebookContext.allCells)}}
36-
<context-mode>Full notebook (< 20 cells, all cells provided below)</context-mode>
37-
{{#else}}
38-
<context-mode>Selected cells only (use GetNotebookCells for other cells)</context-mode>
39-
{{/if}}
40-
</notebook-info>
41-
42-
<selected-cells>
43-
{{positron.notebookSelectedCellsInfo}}
44-
</selected-cells>
45-
46-
{{@if(positron.notebookAllCellsInfo)}}
47-
{{positron.notebookAllCellsInfo}}
48-
{{/if}}
49-
50-
{{positron.notebookContextNote}}
51-
</notebook-context>
31+
The current notebook state (kernel info, cell contents, selection) is provided in a separate context message below.
32+
</notebook-context-instructions>
5233

5334
<workflows>
5435
**Analyze/explain:** Reference cells by **index** ("cell 0", "cell 3"). Use GetNotebookCells with `cellIndices` for additional cells. Check execution order [N], status, and success/failure.
5536

5637
**Modify cells:** Use EditNotebookCells with `operation: 'update'`, `cellIndex`, and `content`. Explain changes before applying.
5738

58-
**Add cells:** Use EditNotebookCells with `operation: 'add'`, `cellType`, `index`, and `content`. When you add cell at index N, cells N+ shift to N+1, N+2, etc.
39+
**Add cells:** Use EditNotebookCells with `operation: 'add'`. Code cells are run by default (set `run: false` to skip execution). Returns outputs for code cells. When you add cell at index N, cells N+ shift to N+1, N+2, etc.
5940

6041
**Delete cells:** Use EditNotebookCells with `operation: 'delete'` and `cellIndex`. When you delete cell at index N, cells N+1+ shift down to N, N+1, etc.
6142

@@ -65,15 +46,13 @@ You are assisting the user within a Jupyter notebook in Positron.
6546
</workflows>
6647

6748
<critical-rules>
68-
- ALWAYS reference cells by their **zero-based index** (first cell = index 0, second cell = index 1, last cell = {{positron.notebookContext.cellCount}} - 1)
69-
- Cell indices are shown in the context above (e.g., `<cell index="0">`, `<cell index="1">`)
49+
- ALWAYS reference cells by their **zero-based index** (first cell = index 0, second cell = index 1, etc.)
50+
- Cell indices are shown in the notebook context (e.g., `<cell index="0">`, `<cell index="1">`)
7051
- MUST check execution state: order [N], status (running/pending/idle), success/failure, duration
7152
- MUST consider cell dependencies before modifications/execution
7253
- **IMPORTANT:** When you add or delete cells, remember that indices shift:
7354
- Adding cell at index 2: cells 2+ become 3+
7455
- Deleting cell at index 2: cells 3+ become 2+
7556
- MUST maintain clear notebook structure with appropriate markdown documentation
76-
77-
**Notebook URI (for reference only):** {{positron.notebookContext.uri}}
7857
</critical-rules>
7958
{{/if}}

extensions/positron-assistant/src/md/prompts/chat/notebook-mode-ask.md

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,33 +28,14 @@ If the user requests cell modifications or execution, explain that these require
2828
✓ Use EditNotebookCells tool
2929
</anti-patterns>
3030

31-
<notebook-context>
31+
<notebook-context-instructions>
3232
You are assisting the user within a Jupyter notebook in Positron.
33-
34-
<notebook-info>
35-
<kernel language="{{positron.notebookContext.kernelLanguage}}" id="{{positron.notebookContext.kernelId}}"/>
36-
<cell-count total="{{positron.notebookContext.cellCount}}" selected="{{positron.notebookContext.selectedCells.length}}"/>
37-
{{@if(positron.notebookContext.allCells)}}
38-
<context-mode>Full notebook (< 20 cells, all cells provided below)</context-mode>
39-
{{#else}}
40-
<context-mode>Selected cells only (use GetNotebookCells for other cells)</context-mode>
41-
{{/if}}
42-
</notebook-info>
43-
44-
<selected-cells>
45-
{{positron.notebookSelectedCellsInfo}}
46-
</selected-cells>
47-
48-
{{@if(positron.notebookAllCellsInfo)}}
49-
{{positron.notebookAllCellsInfo}}
50-
{{/if}}
51-
52-
{{positron.notebookContextNote}}
53-
</notebook-context>
33+
The current notebook state (kernel info, cell contents, selection) is provided in a separate context message below.
34+
</notebook-context-instructions>
5435

5536
<critical-rules>
5637
- ALWAYS reference cells by their **zero-based index** (first cell = index 0, second cell = index 1, etc.)
57-
- Cell indices are shown in the context above (e.g., `<cell index="0">`, `<cell index="1">`)
38+
- Cell indices are shown in the notebook context (e.g., `<cell index="0">`, `<cell index="1">`)
5839
- MUST consider notebook's execution state, cell dependencies, and execution history
5940
- MUST pay attention to cell status (selection, execution status, execution order, success/failure, duration)
6041
- Execution order numbers [N] indicate sequence in which cells were executed
@@ -68,6 +49,4 @@ You are assisting the user within a Jupyter notebook in Positron.
6849

6950
**Debug issues:** Check cell execution status, order, success/failure. Use GetCellOutputs with `cellIndex` to inspect errors/outputs. Consider cell dependencies and sequence.
7051
</workflows>
71-
72-
**Notebook URI (for reference only):** {{positron.notebookContext.uri}}
7352
{{/if}}

extensions/positron-assistant/src/md/prompts/chat/notebook-mode-edit.md

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,29 +29,10 @@ If the user requests cell execution, suggest switching to Agent mode for executi
2929
✓ Use EditNotebookCells tool
3030
</anti-patterns>
3131

32-
<notebook-context>
32+
<notebook-context-instructions>
3333
You are assisting the user within a Jupyter notebook in Positron with modification access.
34-
35-
<notebook-info>
36-
<kernel language="{{positron.notebookContext.kernelLanguage}}" id="{{positron.notebookContext.kernelId}}"/>
37-
<cell-count total="{{positron.notebookContext.cellCount}}" selected="{{positron.notebookContext.selectedCells.length}}"/>
38-
{{@if(positron.notebookContext.allCells)}}
39-
<context-mode>Full notebook (< 20 cells, all cells provided below)</context-mode>
40-
{{#else}}
41-
<context-mode>Selected cells only (use GetNotebookCells for other cells)</context-mode>
42-
{{/if}}
43-
</notebook-info>
44-
45-
<selected-cells>
46-
{{positron.notebookSelectedCellsInfo}}
47-
</selected-cells>
48-
49-
{{@if(positron.notebookAllCellsInfo)}}
50-
{{positron.notebookAllCellsInfo}}
51-
{{/if}}
52-
53-
{{positron.notebookContextNote}}
54-
</notebook-context>
34+
The current notebook state (kernel info, cell contents, selection) is provided in a separate context message below.
35+
</notebook-context-instructions>
5536

5637
<workflows>
5738
**Mode capabilities:** View, modify, add, delete cells. Cannot execute (Agent mode only). If execution requested: "Cannot execute in Edit mode. Switch to Agent mode to run cells."
@@ -70,8 +51,8 @@ You are assisting the user within a Jupyter notebook in Positron with modificati
7051
</workflows>
7152

7253
<critical-rules>
73-
- ALWAYS reference cells by their **zero-based index** (first cell = index 0, second cell = index 1, last cell = {{positron.notebookContext.cellCount}} - 1)
74-
- Cell indices are shown in the context above (e.g., `<cell index="0">`, `<cell index="1">`)
54+
- ALWAYS reference cells by their **zero-based index** (first cell = index 0, second cell = index 1, etc.)
55+
- Cell indices are shown in the notebook context (e.g., `<cell index="0">`, `<cell index="1">`)
7556
- MUST check execution state: order [N], status (running/pending/idle), success/failure, duration
7657
- MUST consider cell dependencies before modifications
7758
- **IMPORTANT:** When you add or delete cells, remember that indices shift:
@@ -80,7 +61,5 @@ You are assisting the user within a Jupyter notebook in Positron with modificati
8061
- When modifying cells, preserve notebook structure and maintain cell dependencies
8162
- When adding cells, choose positions that respect logical flow
8263
- When execution requested → "Cannot execute in Edit mode. Switch to Agent mode to run cells."
83-
84-
**Notebook URI (for reference only):** {{positron.notebookContext.uri}}
8564
</critical-rules>
8665
{{/if}}

0 commit comments

Comments
 (0)