AI Agent
Margin includes an AI agent that works alongside you in notebooks. Ask it to analyze data, create visualizations, fix errors, or explain code—and watch it work in real-time.
Opening the AI Panel
Press ⌘J (Mac) or Ctrl+J (Windows/Linux) to toggle the AI panel. You can also click the AI icon in the toolbar.
The panel appears on the right side of your notebook. Choose between:
- Slideover mode – Panel overlays the notebook (default)
- Side-by-side mode – Panel sits next to the notebook (toggle with ⌘⇧J)
What the AI Can Do
The AI agent has full access to your notebook:
| Capability | Description |
|---|---|
| Read notebook | Sees all cells, outputs, and context |
| Create cells | Adds new code or markdown cells |
| Edit cells | Modifies existing cell content |
| Run cells | Executes code and sees the output |
| Delete cells | Removes cells when appropriate |
| Query datasets | Explores your uploaded data |
When the AI works, you see everything happen live in your notebook—cells appear, code gets written, and executions run with visible output.
Example Workflows
Exploratory Analysis
"What's the distribution of sales by region?"
The AI will:
- Load your dataset
- Write aggregation code
- Create a visualization
- Explain what it found
Debugging
"This cell is throwing a KeyError"
The AI will:
- Read the failing cell
- Identify the issue
- Fix the code
- Re-run to verify
Explanations
"What does this code do?"
The AI explains the selected cell in plain English—without modifying anything.
Staying in Control
You're always in charge:
- Interrupt anytime – Click the stop button or press Escape to halt the AI mid-operation
- Navigate freely – Scroll away while the AI works; it won't get confused
- Edit alongside – Make your own changes to cells the AI isn't currently touching
- Start over – Clear the conversation to reset context
The AI scrolls cells into view as it works, so you can follow along. A visual indicator highlights cells the AI is currently editing or running.
Tips for Better Results
- Be specific – "Plot sales by month as a line chart" works better than "visualize sales"
- Provide context – Mention column names or data characteristics if known
- Iterate – Follow up with refinements: "Make the x-axis labels readable"
- Let it run – The AI often writes code, runs it, sees the output, and iterates—this is expected
Limitations
- The AI works in the notebook's kernel session—variables and state carry over between cells
- Large outputs may be truncated in the AI's view
- The AI cannot access external URLs or APIs beyond your uploaded datasets
- Complex multi-step analyses may require guidance through conversation
Keyboard Shortcuts
| Shortcut | Action |
|---|---|
| ⌘J / Ctrl+J | Toggle AI panel |
| ⌘⇧J / Ctrl+⇧J | Toggle panel mode (slideover ↔ side) |
| Escape | Stop AI / close panel |
| Enter | Send message |
Next Steps
- Learn about notebooks for the full editing experience
- Create briefs from your AI-assisted analysis
- Upload datasets for the AI to explore