AI Agent
Use AI agents to write, edit, and run notebook code.
pynb supports AI agents that can read, write, and execute notebook code on your behalf.
Bring Your Own Agent (BYOA)
pynb does not bundle its own AI model. Instead, it connects to external agents you already have access to. Currently supported:
- OpenAI Codex (requires a ChatGPT subscription)
- Claude (coming soon)
Setup
Authentication
Go to Settings > Agent to check the agent status and authenticate.
- Login with OpenAI: Opens a browser window for OAuth login with your ChatGPT account
- Use API Key: Enter an OpenAI API key directly
Codex is downloaded automatically the first time you use the agent. If you already have codex on your PATH (e.g., installed via Homebrew), pynb uses that.
Using the Agent
Starting a Thread
Open the agent panel in the notebook sidebar. Type a message describing what you want to do, for example:
- "Add a cell that loads data.csv and plots the revenue column"
- "Fix the error in cell 3"
- "Install pandas and rewrite the SQL cell as a DataFrame pipeline"
The agent creates a new thread for each conversation. Previous threads are listed in the sidebar and can be resumed.
What the Agent Can Do
The agent interacts with your notebook through these tools:
| Tool | Description |
|---|---|
list_cells | List all cells with index, type, and source preview |
read_cell | Read a cell's full source code |
edit_cell | Modify a cell's source or change its type |
insert_cell | Add a new cell at a specific position |
delete_cell | Remove a cell |
run_cell | Execute a cell and get its output |
list_dependencies | Show the notebook's declared dependencies |
install_packages | Install packages and persist them to the notebook |
remove_dependencies | Remove packages from the dependency list |
The agent can also run shell commands, search the web, and read/write files in its sandboxed working directory.
Approval Workflow
When the agent wants to run a command or make a file change, it may request your approval depending on the approval policy. You can approve or decline each action individually.
Interrupting
Click Stop to interrupt the agent mid-turn. The agent finishes its current action and stops.
Requirements
- A ChatGPT subscription (Plus, Pro, or Team) for Codex access
- macOS 15+ (same as pynb itself)
- Internet connection for agent communication