Skip to main content

llmsurgery

Install

pip install llmsurgery

What’s here

Dialogs are LLM conversations kept as Jupyter notebooks: notes, runnable code with outputs, and prompt/reply pairs in one editable, diffable document. This library is the data model and surgery toolkit for them, consisting of:

  • llmsurgery.dialog: Message, Dialog, and Attachment — a message carries exactly what the ipynb spec provides (content, output, type, id, attachments) plus a verbatim metadata dict, so host annotations round-trip untouched; hosts declare their own fields via meta_attrs and inject their subclasses through msg_cls and read_ipynb(cls=).
  • llmsurgery.ipynb: reading and writing dialogs as .ipynb files.
  • llmsurgery.hist: converting dialogs to LLM chat history, including recovering tool calls from replies as structured messages. Rendering defaults are deliberately unopinionated (bare prompts, pass-through media, verbatim latex); hosts install their policies as class members (prompt_txt, prep_img, media_extra, ai_renderers, UNSUPPORTED_MSG).
  • llmsurgery.ant: Claude Code session transcripts: read, write, search, curate, and build them from dialogs, so claude --resume opens an authored conversation.
  • llmsurgery.oai: Codex threads: drive codex app-server to inject authored histories, ready for codex resume.

The theory

A dialog is a conversation between a human, an AI, and an interpreter. Each message type addresses one of them and expects a certain kind of answer:

  • A prompt asks the AI a question and holds its reply.
  • A code message gives the interpreter source and holds its outputs.
  • A note is read by everyone and answered by nobody.
  • A raw message addresses no one. It is inert matter the conversation carries along.

A reply may itself contain runnable code with results, so a whole dialog can live inside one message. reply2dlg opens a reply up as a dialog and dlg2reply puts it back.

Dialogs and Jupyter notebooks both serialize to the ipynb format, but they are not the same thing. A notebook has cells. A dialog has messages. Messages can be prompts, which notebooks cannot express, and they make structure explicit that notebooks leave implicit. E.g a heading opens a section that runs to the next heading of the same level; an export directive marks the code that belongs to a module. The shared file format means the same tools read both. The word tells you which layer you are on. File-level tools such as fastcore.nbio and exhash speak of cells and notebooks. Everything in this library speaks of messages and dialogs.

The Dialog is the center of the library. Everything else is a projection of it. A storage projection must preserve everything that means something. What it does not understand it carries verbatim in metadata, and what is broken it heals rather than rejects. A transmission projection normalizes on purpose, and what it drops is written into its contract. A display projection only goes one way. The rule is to convert in, edit at the center, and project out. The function names say the same thing. Every converter has dlg on exactly one side.

projection contract in out
ipynb file storage, pragmatically lossless read_ipynb write_ipynb
Claude Code session storage sess2dlg dlg2sess
Codex thread storage (write-only so far) dlg2thread
fastllm chat (Msg/Part) transmission, normalizing chat2dlg dlg2chat
fastllm hist (live call input) transmission, one-way dlg2hist
a prompt’s reply self-similar reply2dlg dlg2reply
XML views display, one-way view_dlg, msg2xml

The session codecs route through chat on their way to the wire: ant’s dlg2msgs and oai’s dlg2items are each denorm_msgs(dlg2chat(...)).

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llmsurgery-0.0.4.tar.gz (93.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llmsurgery-0.0.4-py3-none-any.whl (97.5 kB view details)

Uploaded Python 3

File details

Details for the file llmsurgery-0.0.4.tar.gz.

File metadata

  • Download URL: llmsurgery-0.0.4.tar.gz
  • Upload date:
  • Size: 93.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for llmsurgery-0.0.4.tar.gz
Algorithm Hash digest
SHA256 f3a9a09c4607919c83f315ff5bd23186ad1cb2dd0714038e6e738b18ef5f9e2c
MD5 63dc701d6ccfd09c3d1b5b6b02fd6c7a
BLAKE2b-256 8b194a32f5c45d87846e02afaff5d29c5afc7a1dfc39cc8b5c9acfeba0407b59

See more details on using hashes here.

File details

Details for the file llmsurgery-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: llmsurgery-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 97.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for llmsurgery-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 9fa02161de1dd351e44b32c1ccc22d5bed6f8ec89d3d7f7b618ad7907cdc49d4
MD5 db0192cc21fb91ce0e491f02238e7f71
BLAKE2b-256 2b712ca3ec7287cab452332408e8c070b1ee679c40c075f162dc0f34ddc112c5

See more details on using hashes here.

Release history Release notifications | RSS feed

0.0.16

2 files

0.0.15

2 files

0.0.14

2 files

0.0.13

2 files

0.0.12

2 files

0.0.11

2 files

0.0.10

2 files

0.0.9

2 files

0.0.8

2 files

0.0.7

2 files

0.0.6

2 files

0.0.5

2 files

This release

0.0.4 This release

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page