AI Agent

Work alongside an AI that can write code, run cells, and iterate on analysis in your notebooks.

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:

CapabilityDescription
Read notebookSees all cells, outputs, and context
Create cellsAdds new code or markdown cells
Edit cellsModifies existing cell content
Run cellsExecutes code and sees the output
Delete cellsRemoves cells when appropriate
Query datasetsExplores 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:

  1. Load your dataset
  2. Write aggregation code
  3. Create a visualization
  4. Explain what it found

Debugging

"This cell is throwing a KeyError"

The AI will:

  1. Read the failing cell
  2. Identify the issue
  3. Fix the code
  4. 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

  1. Be specific – "Plot sales by month as a line chart" works better than "visualize sales"
  2. Provide context – Mention column names or data characteristics if known
  3. Iterate – Follow up with refinements: "Make the x-axis labels readable"
  4. 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

ShortcutAction
⌘J / Ctrl+JToggle AI panel
⌘⇧J / Ctrl+⇧JToggle panel mode (slideover ↔ side)
EscapeStop AI / close panel
EnterSend message

Next Steps