A tiny stdin/stdout IPython worker
Project description
clikernel
clikernel is a tiny stdin/stdout worker around execnb.shell.CaptureShell. It keeps one IPython-compatible Python process alive and returns concise text for each request.
The Key Idea
The idea of clikernel is to be a persistent python process that LLMs can use as their primary tool.
A persistent Python process is a good default tool for an LLM agent. The agent can import a module, inspect it, keep helper functions around, cache results, patch objects, and then continue from that state on the next request.
This is especially useful with pyskills. The agent can discover skills, read their docs, import the ones it needs, and keep using them in the same session. That makes Python a universal workbench for repo inspection, API checks, file edits, data transforms, and experiments.
clikernel gives an agent the part of a notebook kernel it usually needs: send code, wait for the result, read concise text, and keep the Python state.
Protocol
On startup, clikernel prints loading status followed by a fresh ready delimiter:
please wait, loading...
loading complete. first delimiter:
--aB3x9
Send one line to execute it immediately:
1+1
For multiline code, send -- on its own line, then the code, then the latest ready delimiter exactly:
--
def f(x):
return x + 1
f(2)
--aB3x9
After execution, clikernel prints the rendered output followed by a new ready delimiter:
3
--Q7z2M
Outputs are rendered with fastcore.nbio.render_text. A single non-empty output is printed directly. Multiple outputs use raw XML-ish tags, for example <stdout>, <display_data mime="text/markdown">, and <execute_result>.
clikernel sets quiet defaults for IPYTHONDIR, MPLCONFIGDIR, and MPLBACKEND=Agg before creating the shell. Existing IPYTHONDIR and MPLCONFIGDIR values are left alone. Loading messages and any startup warnings are printed before the first delimiter. Set CLIKERNEL_STATE_DIR to choose the default parent directory.
Why The Protocol Is Odd
clikernel is built for a client that reads stdout as tokens. Local echo is disabled when stdin is a TTY. The client already knows the code it sent, so echoing it back only makes the LLM read slow, expensive tokens that add no information.
Each response ends with a delimiter on its own line. The client can read until that line appears instead of parsing prompts or waiting and guessing. The delimiter changes after every request. This matters for multiline input, where the current delimiter is also the block terminator. A random current delimiter is unlikely to appear in generated code, copied logs, examples, or earlier transcript text. Old delimiters stop working as soon as the next response is printed.
Startup messages appear before the first delimiter. After that first delimiter, the stream follows the request-response protocol. Outputs are rendered as concise text, using unescaped XML if required when there's multiple outputs.
IPython history is disabled. IPYTHONDIR and MPLCONFIGDIR get quiet defaults when the environment has not already set them, and MPLBACKEND defaults to Agg.
Development
pip install -e .[dev]
Versioning
Version lives in clikernel/__init__.py as __version__.
Release
- Ensure your GitHub issues are labeled (
bug,enhancement,breaking). - Run:
ship-gh
ship-pypi
ship-bump # dev release always later than prod release
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 clikernel-0.1.0.tar.gz.
File metadata
- Download URL: clikernel-0.1.0.tar.gz
- Upload date:
- Size: 9.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
88fe5b97c57e76c33bfbe2a3bbe4e9a74ea7f53df29245f1f203a4d486dbc064
|
|
| MD5 |
96658a0047da83c9046c1b1448574f91
|
|
| BLAKE2b-256 |
0ae265d7aa8605db44c6e5f8ff14a618f137d66f7e9152988ec0ffeb5e094117
|
File details
Details for the file clikernel-0.1.0-py3-none-any.whl.
File metadata
- Download URL: clikernel-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e93437e1cf2bca3f73e72eca6e28126575c6ae32cc0d0547eb491656eb1bbb97
|
|
| MD5 |
6c72287747e7e7d0dba7b545ddd6a8c4
|
|
| BLAKE2b-256 |
d8eb376fafb0bce4d99f23079d9e9b7d03179f5e0d46d4930d9b9be65e907fc8
|