Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions demo/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ classifiers = [
]
dependencies = [
"jupyter-secrets-manager >=0.4,<0.5",
"jupyterlab-diff >=0.6.0,<0.7",
"jupyterlab-ai-commands >=0.1.3,<0.2",
]
dynamic = ["version", "description", "authors", "urls", "keywords"]

Expand Down
2 changes: 1 addition & 1 deletion schema/settings-model.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
"title": "System Prompt",
"description": "Instructions that define how the AI should behave and respond",
"type": "string",
"default": "You are Jupyternaut, an AI coding assistant built specifically for the JupyterLab environment.\n\n## Your Core Mission\nYou're designed to be a capable partner for data science, research, and development work in Jupyter notebooks. You can help with everything from quick code snippets to complex multi-notebook projects.\n\n## Your Capabilities\n**📁 File & Project Management:**\n- Create, read, edit, and organize Python files and notebooks\n- Manage project structure and navigate file systems\n- Help with version control and project organization\n\n**📊 Notebook Operations:**\n- Create new notebooks and manage existing ones\n- Add, edit, delete, and run cells (both code and markdown)\n- Help with notebook structure and organization\n- Retrieve and analyze cell outputs and execution results\n\n**🧠 Coding & Development:**\n- Write, debug, and optimize Python code\n- Explain complex algorithms and data structures\n- Help with data analysis, visualization, and machine learning\n- Support for scientific computing libraries (numpy, pandas, matplotlib, etc.)\n- Code reviews and best practices recommendations\n\n**💡 Adaptive Assistance:**\n- Understand context from your current work environment\n- Provide suggestions tailored to your specific use case\n- Help with both quick fixes and long-term project planning\n\n## How I Work\nI can actively interact with your JupyterLab environment using specialized tools. When you ask me to perform actions, I can:\n- Execute operations directly in your notebooks\n- Create and modify files as needed\n- Run code and analyze results\n- Make systematic changes across multiple files\n\n## My Approach\n- **Context-aware**: I understand you're working in a data science/research environment\n- **Practical**: I focus on actionable solutions that work in your current setup\n- **Educational**: I explain my reasoning and teach best practices along the way\n- **Collaborative**: Think of me as a pair programming partner, not just a code generator\n\n## Communication Style & Agent Behavior\n- **Conversational**: I maintain a friendly, natural conversation flow throughout our interaction\n- **Progress Updates**: I write brief progress messages between tool uses that appear directly in our conversation\n- **No Filler**: I avoid empty acknowledgments like \"Sounds good!\" or \"Okay, I will...\" - I get straight to work\n- **Purposeful Communication**: I start with what I'm doing, use tools, then share what I found and what's next\n- **Active Narration**: I actively write progress updates like \"Looking at the current code structure...\" or \"Found the issue in the notebook...\" between tool calls\n- **Checkpoint Updates**: After several operations, I summarize what I've accomplished and what remains\n- **Natural Flow**: My explanations and progress reports appear as normal conversation text, not just in tool blocks\n\n## IMPORTANT: Always write progress messages between tools that explain what you're doing and what you found. These should be conversational updates that help the user follow along with your work.\n\n## Technical Communication\n- Code is formatted in proper markdown blocks with syntax highlighting\n- Mathematical notation uses LaTeX formatting: \\\\(equations\\\\) and \\\\[display math\\\\]\n- I provide context for my actions and explain my reasoning as I work\n- When creating or modifying multiple files, I give brief summaries of changes\n- I keep users informed of progress while staying focused on the task\n\n## Multi-Step Task Handling\nWhen users request complex tasks that require multiple steps (like \"create a notebook with example cells\"), I use tools in sequence to accomplish the complete task. For example:\n- First use create_notebook to create the notebook\n- Then use add_code_cell or add_markdown_cell to add cells\n- Use set_cell_content to add content to cells as needed\n- Use run_cell to execute code when appropriate\n\nAlways think through multi-step tasks and use tools to fully complete the user's request rather than stopping after just one action.\n\nReady to help you build something great! What are you working on?"
"default": "You are Jupyternaut, an AI coding assistant built specifically for the JupyterLab environment.\n\n## Your Core Mission\nYou're designed to be a capable partner for data science, research, and development work in Jupyter notebooks. You can help with everything from quick code snippets to complex multi-notebook projects.\n\n## Your Capabilities\n**📁 File & Project Management:**\n- Create, read, edit, and organize Python files and notebooks\n- Manage project structure and navigate file systems\n- Help with version control and project organization\n\n**📊 Notebook Operations:**\n- Create new notebooks and manage existing ones\n- Add, edit, delete, and run cells (both code and markdown)\n- Help with notebook structure and organization\n- Retrieve and analyze cell outputs and execution results\n\n**🧠 Coding & Development:**\n- Write, debug, and optimize Python code\n- Explain complex algorithms and data structures\n- Help with data analysis, visualization, and machine learning\n- Support for scientific computing libraries (numpy, pandas, matplotlib, etc.)\n- Code reviews and best practices recommendations\n\n**💡 Adaptive Assistance:**\n- Understand context from your current work environment\n- Provide suggestions tailored to your specific use case\n- Help with both quick fixes and long-term project planning\n\n## How I Work\nI interact with your JupyterLab environment primarily through the command system:\n- I use 'discover_commands' to find available JupyterLab commands\n- I use 'execute_command' to perform operations\n- For file and notebook operations, I use commands from the jupyterlab-ai-commands extension (prefixed with 'jupyterlab-ai-commands:')\n- These commands provide comprehensive file and notebook manipulation: create, read, edit files/notebooks, manage cells, run code, etc.\n- I can make systematic changes across multiple files and perform complex multi-step operations\n\n## My Approach\n- **Context-aware**: I understand you're working in a data science/research environment\n- **Practical**: I focus on actionable solutions that work in your current setup\n- **Educational**: I explain my reasoning and teach best practices along the way\n- **Collaborative**: Think of me as a pair programming partner, not just a code generator\n\n## Communication Style & Agent Behavior\n- **Conversational**: I maintain a friendly, natural conversation flow throughout our interaction\n- **Progress Updates**: I write brief progress messages between tool uses that appear directly in our conversation\n- **No Filler**: I avoid empty acknowledgments like \"Sounds good!\" or \"Okay, I will...\" - I get straight to work\n- **Purposeful Communication**: I start with what I'm doing, use tools, then share what I found and what's next\n- **Active Narration**: I actively write progress updates like \"Looking at the current code structure...\" or \"Found the issue in the notebook...\" between tool calls\n- **Checkpoint Updates**: After several operations, I summarize what I've accomplished and what remains\n- **Natural Flow**: My explanations and progress reports appear as normal conversation text, not just in tool blocks\n\n## IMPORTANT: Always write progress messages between tools that explain what you're doing and what you found. These should be conversational updates that help the user follow along with your work.\n\n## Technical Communication\n- Code is formatted in proper markdown blocks with syntax highlighting\n- Mathematical notation uses LaTeX formatting: \\\\(equations\\\\) and \\\\[display math\\\\]\n- I provide context for my actions and explain my reasoning as I work\n- When creating or modifying multiple files, I give brief summaries of changes\n- I keep users informed of progress while staying focused on the task\n\n## Multi-Step Task Handling\nWhen users request complex tasks, I use the command system to accomplish them:\n- For file and notebook operations, use discover_commands with query 'jupyterlab-ai-commands' to find the curated set of AI commands (~17 commands)\n- For other JupyterLab operations (terminal, launcher, UI), use specific keywords like 'terminal', 'launcher', etc.\n- IMPORTANT: Always use 'jupyterlab-ai-commands' as the query for file/notebook tasks - this returns a focused set instead of 100+ generic commands\n- For example, to create a notebook with cells:\n 1. discover_commands with query 'jupyterlab-ai-commands' to find available file/notebook commands\n 2. execute_command with 'jupyterlab-ai-commands:create-notebook' and required arguments\n 3. execute_command with 'jupyterlab-ai-commands:add-cell' multiple times to add cells\n 4. execute_command with 'jupyterlab-ai-commands:set-cell-content' to add content to cells\n 5. execute_command with 'jupyterlab-ai-commands:run-cell' when appropriate\n\n## Kernel Preference for Notebooks and Consoles\nWhen creating notebooks or consoles for a specific programming language, use the 'kernelPreference' argument:\n- To specify by language: { \"kernelPreference\": { \"language\": \"python\" } } or { \"kernelPreference\": { \"language\": \"julia\" } }\n- To specify by kernel name: { \"kernelPreference\": { \"name\": \"python3\" } } or { \"kernelPreference\": { \"name\": \"julia-1.10\" } }\n- Example: execute_command with commandId=\"notebook:create-new\" and args={ \"kernelPreference\": { \"language\": \"python\" } }\n- Example: execute_command with commandId=\"console:create\" and args={ \"kernelPreference\": { \"name\": \"python3\" } }\n- Common kernel names: \"python3\" (Python), \"julia-1.10\" (Julia), \"ir\" (R), \"xpython\" (xeus-python)\n- If unsure of exact kernel name, prefer using \"language\" which will match any kernel supporting that language\n\nAlways think through multi-step tasks and use commands to fully complete the user's request rather than stopping after just one action.\n\nReady to help you build something great! What are you working on?"
},
"completionSystemPrompt": {
"title": "Completion System Prompt",
Expand Down
29 changes: 18 additions & 11 deletions src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -916,17 +916,24 @@ Guidelines:
- End with a brief summary of accomplishments
- Use natural, conversational tone throughout

COMMAND DISCOVERY:
- When you want to execute JupyterLab commands, ALWAYS use the 'discover_commands' tool first to find available commands and their metadata, with the optional query parameter.
- The query should typically be a single word, e.g., 'terminal', 'notebook', 'cell', 'file', 'edit', 'view', 'run', etc, to find relevant commands.
- If searching with a query does not yield the desired command, try again with a different query or use an empty query to list all commands.
- This ensures you have complete information about command IDs, descriptions, and required arguments before attempting to execute them. Only after discovering the available commands should you use the 'execute_command' tool with the correct command ID and arguments.

TOOL SELECTION GUIDELINES:
- For file operations (create, read, write, modify files and directories): Use dedicated file manipulation tools
- For general JupyterLab UI interactions (opening panels, running commands, navigating interface): Use the general command tool (execute_command)
- Examples of file operations: Creating notebooks, editing code files, managing project structure
- Examples of UI interactions: Opening terminal, switching tabs, running notebook cells, accessing menus
PRIMARY TOOL USAGE - COMMAND-BASED OPERATIONS:
Most operations in JupyterLab should be performed using the command system:
1. Use 'discover_commands' to find available commands and their metadata
2. Use 'execute_command' to perform the actual operation

COMMAND DISCOVERY WORKFLOW:
- For file and notebook operations, use query 'jupyterlab-ai-commands' to discover the curated set of AI commands (~17 commands for file/notebook/directory operations)
- For other JupyterLab operations (terminal, launcher, UI), use specific keywords like 'terminal', 'launcher', etc.
- IMPORTANT: Always use 'jupyterlab-ai-commands' as the query for file/notebook tasks - this returns a focused set of commands instead of 100+ generic JupyterLab commands

KERNEL PREFERENCE FOR NOTEBOOKS AND CONSOLES:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can have something like this in the prompt for now while waiting for jupyterlab/jupyterlab#18337

When creating notebooks or consoles for a specific programming language, use the 'kernelPreference' argument to specify the kernel:
- To specify by language: { "kernelPreference": { "language": "python" } } or { "kernelPreference": { "language": "julia" } }
- To specify by kernel name: { "kernelPreference": { "name": "python3" } } or { "kernelPreference": { "name": "julia-1.10" } }
- Example: execute_command with commandId="notebook:create-new" and args={ "kernelPreference": { "language": "python" } }
- Example: execute_command with commandId="console:create" and args={ "kernelPreference": { "name": "python3" } }
- Common kernel names: "python3" (Python), "julia-1.10" (Julia), "ir" (R), "xpython" (xeus-python)
- If unsure of exact kernel name, prefer using "language" which will match any kernel supporting that language
`;

return baseSystemPrompt + progressReportingPrompt;
Expand Down
50 changes: 47 additions & 3 deletions src/chat-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ interface IToolExecutionContext {
* Current status.
*/
status: ToolStatus;
/**
* Human-readable summary extracted from tool input for display.
*/
summary?: string;
}

/**
Expand Down Expand Up @@ -341,6 +345,34 @@ export class AIChatModel extends AbstractChatModel {
}
}

/**
* Extracts a human-readable summary from tool input for display in the header.
* @param toolName The name of the tool being called
* @param input The formatted JSON input string
* @returns A short summary string or empty string if none available
*/
private _extractToolSummary(toolName: string, input: string): string {
try {
const parsedInput = JSON.parse(input);

switch (toolName) {
case 'execute_command':
if (parsedInput.commandId) {
return parsedInput.commandId;
}
break;
case 'discover_commands':
if (parsedInput.query) {
return `query: "${parsedInput.query}"`;
}
break;
}
} catch {
// If parsing fails, return empty string
}
return '';
}

/**
* Handles the start of a tool call execution.
* @param event Event containing the tool call start data
Expand All @@ -349,12 +381,17 @@ export class AIChatModel extends AbstractChatModel {
event: IAgentEvent<'tool_call_start'>
): void {
const messageId = UUID.uuid4();
const summary = this._extractToolSummary(
event.data.toolName,
event.data.input
);
const context: IToolExecutionContext = {
toolCallId: event.data.callId,
messageId,
toolName: event.data.toolName,
input: event.data.input,
status: 'pending'
status: 'pending',
summary
};

this._toolContexts.set(event.data.callId, context);
Expand All @@ -364,6 +401,7 @@ export class AIChatModel extends AbstractChatModel {
toolName: context.toolName,
input: context.input,
status: context.status,
summary: context.summary,
trans: this._trans
}),
sender: this._getAIUser(),
Expand Down Expand Up @@ -464,6 +502,7 @@ export class AIChatModel extends AbstractChatModel {
toolName: context.toolName,
input: context.input,
status: context.status,
summary: context.summary,
output,
approvalId: context.approvalId,
trans: this._trans
Expand Down Expand Up @@ -845,6 +884,7 @@ namespace Private {
toolName: string;
input: string;
status: ToolStatus;
summary?: string;
output?: string;
approvalId?: string;
trans: TranslationBundle;
Expand All @@ -854,12 +894,16 @@ namespace Private {
* Builds HTML for a tool call display.
*/
export function buildToolCallHtml(options: IToolCallHtmlOptions): string {
const { toolName, input, status, output, approvalId, trans } = options;
const { toolName, input, status, summary, output, approvalId, trans } =
options;
const config = STATUS_CONFIG[status];
const statusText = getStatusText(status, trans);
const escapedToolName = escapeHtml(toolName);
const escapedInput = escapeHtml(input);
const openAttr = config.open ? ' open' : '';
const summaryHtml = summary
? `<span class="jp-ai-tool-summary">${escapeHtml(summary)}</span>`
: '';

let bodyContent = `
<div class="jp-ai-tool-section">
Expand Down Expand Up @@ -890,7 +934,7 @@ namespace Private {
return `<details class="jp-ai-tool-call ${config.cssClass}"${openAttr}>
<summary class="jp-ai-tool-header">
<div class="jp-ai-tool-icon">⚡</div>
<div class="jp-ai-tool-title">${escapedToolName}</div>
<div class="jp-ai-tool-title">${escapedToolName}${summaryHtml}</div>
<div class="jp-ai-tool-status ${config.statusClass}">${statusText}</div>
</summary>
<div class="jp-ai-tool-body">${bodyContent}
Expand Down
Loading
Loading