A persistent Python notebook for AI agents, driven from the CLI
Project description
agentnb
A persistent project-scoped Python REPL for coding agents, exposed through a simple CLI.
Status: alpha. Expect rough edges and breaking changes. Use in local development workflows at your own risk.
Why
Agents can run shell commands, but they lose state when using one-off python -c and script invocations. agentnb gives agents a long-running IPython kernel they can drive with CLI commands, so they can explore incrementally, keep expensive setup in memory, inspect live variables, and recover without restarting from scratch on every step.
The right mental model is a persistent REPL for agents, or an append-only notebook without a notebook UI. agentnb keeps execution state and history, but it does not edit notebook cells or manage .ipynb files.
Module reloading is explicit. agentnb does not auto-reload edited modules on
every execution; use agentnb reload after changing project-local code.
exec follows normal IPython/Notebook semantics for output: if the final line
of a snippet is an expression, its value is returned as the execution result.
Install
uv add agentnb
# or
pip install agentnb
Quick Start
agentnb start --project /path/to/project --json
agentnb exec "from myapp.models import User" --json
agentnb exec --file analysis.py --json
agentnb vars --json
agentnb inspect User --json
agentnb stop --json
For multiline code, prefer --file or stdin/heredoc:
agentnb exec --json <<'PY'
import pandas as pd
df = pd.read_csv("tips.csv")
df.head()
PY
For lower-noise agent integrations, you can set defaults once per shell:
export AGENTNB_FORMAT=agent
That enables JSON output and suppresses suggestions across commands. You can also use
top-level flags such as agentnb --agent ..., agentnb --json ...,
agentnb --no-suggestions ..., and agentnb --quiet ....
In --agent mode, default payloads are compacted to reduce token usage:
trimmed error tracebacks, compact history entries, compact dataframe previews,
and structural summaries for common containers such as list and dict.
Recommended Workflow
The normal agent loop is:
agentnb start --jsonagentnb exec "..." --jsonfor short snippetsagentnb exec --file analysis.py --jsonor pipe code through stdin for multiline workagentnb vars --jsonagentnb inspect NAME --jsonagentnb reload --jsonafter editing project-local modulesagentnb reload myapp.module --jsonto target one imported moduleagentnb history --json
Use agentnb doctor --json if startup fails, agentnb interrupt --json if execution hangs, and agentnb reset --json if the namespace needs a clean slate.
If startup reports that ipykernel is missing, rerun agentnb start with
--auto-install or use agentnb doctor --fix --json.
Running agentnb with no arguments, or agentnb --help, prints an agent-oriented command guide and workflow summary.
Positioning
agentnb is optimized for stateful agent iteration inside a project:
- a persistent REPL the agent can keep using across steps
- a lightweight append-only notebook model backed by execution history
- module reload and variable inspection without a notebook editor
It is not a notebook editing tool:
- it does not edit cells
- it does not write
.ipynbfiles - it does not synchronize with JupyterLab
Commands
agentnb start [--project PATH] [--python PATH] [--auto-install]- top-level flags:
agentnb [--json] [--agent] [--quiet] [--no-suggestions] <command> agentnb status [--project PATH]agentnb exec [CODE] [-f FILE] [--timeout SECONDS] [--stdout-only|--stderr-only|--result-only] [--project PATH] [--json]agentnb vars [--project PATH] [--json] [--types|--no-types]agentnb inspect NAME [--project PATH] [--json]agentnb reload [MODULE] [--project PATH] [--json]agentnb history [--project PATH] [--errors] [--latest|--last N] [--all] [--json]agentnb interrupt [--project PATH] [--json]agentnb reset [--project PATH] [--json]agentnb stop [--project PATH] [--json]agentnb doctor [--project PATH] [--python PATH] [--fix] [--json]
Notes:
varsincludes type information by default.varshides imported helper routines and classes, and summarizes common containers compactly.historyshows semantic user-visible steps by default such asexec,vars,inspect,reload, andreset.- Use
history --allto include internal helper executions sent to the kernel. - Module reloading is explicit.
reload MODULEreloads one imported project-local module. - Bare
reloadreloads all currently imported project-local modules and reports rebound names and possible stale objects. - If reload reports stale objects, recreate them or run
agentnb resetwhen stale state is widespread. inspectgives compact previews for pandas-like dataframes and for commonlist/dictAPI payloads.
Out-of-the-box startup
On agentnb start, the runtime selects an interpreter in this order:
--pythoninterpreter<project>/.venvinterpreter- active
VIRTUAL_ENVinterpreter - current Python executable
If ipykernel is missing for the selected interpreter, agentnb start fails
with the exact install command. Pass --auto-install to let agentnb install
it for you, or use agentnb doctor --fix --json.
JSON Mode
Pass --json to emit a stable machine-readable envelope. This is the preferred mode for agent integrations.
Command-level success and execution success now align: if exec or reset
fails in the kernel, the top-level response has "status": "error" and the
command exits non-zero. The execution payload is still included in data.
Default JSON is intentionally compact for agent use: large event lists are
omitted, tracebacks are trimmed, and inspection/history payloads prefer short
previews over raw internal detail.
If you want that behavior by default, set AGENTNB_FORMAT=json or AGENTNB_FORMAT=agent.
agent also suppresses suggestions and enables quiet mode.
{
"schema_version": "1.0",
"status": "ok",
"command": "exec",
"project": "/path/to/project",
"session_id": "default",
"timestamp": "2026-03-08T21:00:00+00:00",
"data": {
"status": "ok",
"stdout": "",
"stderr": "",
"result": "42",
"execution_count": 1,
"duration_ms": 12
},
"suggestions": [
"Run `agentnb vars --json` to inspect the updated namespace.",
"Run `agentnb inspect NAME --json` to inspect a specific variable.",
"Run `agentnb history --json` to review prior executions."
],
"error": null
}
How It Works
agentnb starts an IPython kernel process and stores connection/session metadata under .agentnb/ in the target project. CLI commands connect via Jupyter messaging protocol.
Architecture
SessionStore: project/session metadata and stale cleanupHistoryStore: typed JSONL history records for semantic and internal execution historyKernelRuntime: lifecycle + execution APIRuntimeBackend: backend interface, with local IPython backend for v0.1NotebookOps: vars/inspect/reload semantic operationsOutputContract: human + JSON output from one response envelopeHooks: no-op extension points for future policy/plugins/telemetry
Development
uv sync --extra dev
uv run ruff check src tests
uv run ruff format --check src tests
uv run ty check src
uv run pytest
0.1.1 Ergonomics
- top-level
--agent,--json,--quiet, and--no-suggestionsflags AGENTNB_FORMAT,AGENTNB_NO_SUGGESTIONS, andAGENTNB_QUIETenvironment defaultsexec --stdout-only,--stderr-only, and--result-onlyfor script-friendly capturehistory --latestandhistory --last Nshortcuts
Current Ergonomics
execaccepts short inline code,--file, or stdin/heredoc for multiline snippetsvarsincludes type information by defaultvarshides imported helper routines and classes and summarizes common containers compactlyinspectgives compact previews for pandas-like objects and commonlist/dictpayloadshistorydefaults to semantic user-visible steps, with--allfor internal kernel executions--agentreturns compact JSON by default to reduce token usage during iterative workflows
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file agentnb-0.1.1.tar.gz.
File metadata
- Download URL: agentnb-0.1.1.tar.gz
- Upload date:
- Size: 30.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7ea3dbdd6f9053abfe382e0042d97039beffe578d9c586b509b914ce592f805b
|
|
| MD5 |
a62ad51b3f988f062de75ef215f550db
|
|
| BLAKE2b-256 |
bf25d37f316dfce7f7046d6baa29cae535ae6fbc7a3c7f2efa610f66c6b733b7
|
Provenance
The following attestation bundles were made for agentnb-0.1.1.tar.gz:
Publisher:
publish.yml on oegedijk/agentnb
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
agentnb-0.1.1.tar.gz -
Subject digest:
7ea3dbdd6f9053abfe382e0042d97039beffe578d9c586b509b914ce592f805b - Sigstore transparency entry: 1068350276
- Sigstore integration time:
-
Permalink:
oegedijk/agentnb@3cb2b07fd419254aac9c481e9ac4fe8e8c346cb1 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/oegedijk
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3cb2b07fd419254aac9c481e9ac4fe8e8c346cb1 -
Trigger Event:
push
-
Statement type:
File details
Details for the file agentnb-0.1.1-py3-none-any.whl.
File metadata
- Download URL: agentnb-0.1.1-py3-none-any.whl
- Upload date:
- Size: 36.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a0a8fd14f3c556cc4a40d336a6a0707b1b3cf9ad75e761b3a5e2f187815b7100
|
|
| MD5 |
a4f704f61470987394effb72b47efd5e
|
|
| BLAKE2b-256 |
7cf31c15e1ba60aa60e51092aaefdb79ec02585ee07d1daa458c7f248a649e33
|
Provenance
The following attestation bundles were made for agentnb-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on oegedijk/agentnb
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
agentnb-0.1.1-py3-none-any.whl -
Subject digest:
a0a8fd14f3c556cc4a40d336a6a0707b1b3cf9ad75e761b3a5e2f187815b7100 - Sigstore transparency entry: 1068350367
- Sigstore integration time:
-
Permalink:
oegedijk/agentnb@3cb2b07fd419254aac9c481e9ac4fe8e8c346cb1 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/oegedijk
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3cb2b07fd419254aac9c481e9ac4fe8e8c346cb1 -
Trigger Event:
push
-
Statement type: