ph-clm
The model edits its own context. It can tombstone, replace, and rewrite sections of what it sees. The log keeps every original.
This package follows Context Language Models. The idea of that paper is
that a model keeps the context it works best with when it can edit that context
itself. In pH, an edit never rewrites the log. Each edit is a surface replace,
which is the mechanism that compaction and paste offload already use. The view of
the model changes, the log keeps the originals, and the transcript still shows
the user the conversation that they had.
Sections
The context of the model is divided into sections. A boundary is a point
where no tool call waits for a result. A section is therefore a user message, an
assistant reply, or an assistant message together with every tool result that it
asked for. The id of a section is the sequence number (seq) of its first event,
for example S412. That number never changes, so an id that the model reads on
one call is still valid on the next call.
Tools
| Tool | What it does |
|---|---|
context_sections |
Shows the map: the id, kind, and size of each section, and how many tokens follow it |
context_tombstone |
Replaces a run of sections with a one-line marker that gives the reason |
context_replace |
Replaces a run of sections with text that the model wrote: a summary or a rewrite |
context_rewrite |
Changes one passage inside the tool output or the reply of one section |
context_restore |
Undoes the latest edit of a section, one level. A rewrite is undone exactly. A removed or replaced run comes back as the text that it held |
context_recall |
Reads back the originals that a revised section stands for |
context_diff |
Shows a unified diff of a section against the originals that it stands for, after the edits that led there |
Every edit reports its cost. The prefix cache of a provider cannot serve anything after the first change. The provider therefore reads the sections after an edit again, one time.
Readouts
A readout is one line at the end of a tool result. When the same call edited the context file, the receipt of that edit follows it. A readout appears when a result takes the context past a threshold, which is a share of the context window. The line gives the size of the context and says how to free space.
- Each threshold is reported one time. It is reported again only after an edit brings the context back below it.
- The thresholds are the
remindAtsetting of theclm-contextrow. The default is[0.5, 0.75], and[]turns readouts off. - With compaction mounted, the last reminder moves. It comes
lastMargin(0.2) below the compaction trigger. With the default trigger of 0.85, that is 65%. The model then has room to act before compaction writes a summary for it. - In Code Mode, the readout shows the full call, including the keywords.
The context file
Before each request, the clm-mirror row writes the context of the model to a
file in the scratch directory of the agent's workspace. The file has one
[[SECTION S<id>]] block for each section. The model edits the file with the
tools that it already uses: edit, sed, or Python in a cell. When the call
that changed the file finishes, the row applies the changes through the same
editor that the tools use. The changes land in one batch, before the result of
the call. The result carries the receipt.
| Change in the file | Result |
|---|---|
| A section is deleted | A tombstone |
| The text of a tool result is changed | That result is rewritten in place |
| The result lines of a step are removed | The step is replaced by the text that is left |
| The text of a message is changed | A replacement (a reply is rewritten in place) |
| No section lines are left | One replacement for everything editable |
The header line of a revised section says what the section stands for. The text under the header is only the part that the model can edit.
The row refuses four kinds of change: a reorder, a damaged header, an edit to a protected section, and a file that was written before the last revision of the context. The result of the call gives the reason, and the row writes the file again.
The file holds a whole conversation, so the row keeps it private and short-lived:
- The directory has mode 0700 and the file has mode 0600.
- The file is deleted when the session leaves the store.
- If a link is put in place of the file, the row replaces the link and never reads through it.
The row applies only an edit that a tool call makes. If the file changes outside a call (in an editor, or by another process), the row records the change as declined and writes the file again before the next request.
To start a session with this bundle:
phern --profile rlm-clm
Metadata
Release files for ph-clm 0.13.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ph_clm-0.13.0.tar.gz | 54.6 kB | Without provenance | Details for ph_clm-0.13.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ph_clm-0.13.0-py3-none-any.whl | Python 3 | none | any | Details for ph_clm-0.13.0-py3-none-any.whl |
Total release size: 98.2 kB
Release files / ph_clm-0.13.0.tar.gz
| Download URL | ph_clm-0.13.0.tar.gz |
|---|---|
| Size | 54.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
922291fa2fb704052c390ae6e7bd0880f9c523c37a5ee480ee3e09c64ca5d4d0
|
|
BLAKE2b-256 checksum How to use checksums |
c10cf61b3607bd231b92db18b7a07815f06a58b72d05ff9aebeacc824d779135
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / ph_clm-0.13.0-py3-none-any.whl
| Download URL | ph_clm-0.13.0-py3-none-any.whl |
|---|---|
| Size | 43.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4464fa646b72f66be63fc0c30ca6c93a9e53a60c563cc12b78ff9db570568319
|
|
BLAKE2b-256 checksum How to use checksums |
f6a8eb7b3f212a2adcedc6f42c3fe784f37519d12114d7ab0ea81d88dd707e19
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for ph-clm 0.13.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.