ContextClip (Python)
Part of LoopEngine — a runtime for defining and running AI agents through a transparent ReAct loop — handling context-window budget tracking with staged recovery. Works standalone too, no dependency on LoopEngine itself.
Ported line-for-line from the TypeScript implementation. See the root README for the pitch, the prior-art table, and the scope decisions — this file only covers what's specific to running the Python code.
Install
pip install -e ".[dev]"
Quickstart
PYTHONPATH=src python3 examples/quickstart.py
from contextclip import ContextClipper
clipper = ContextClipper(budget_tokens=200, tail_messages=2)
status = clipper.check(messages)
if status.action == "over_hard_limit":
result = await clipper.recover(messages)
# result.action is "drained" or "summarized" — result.messages never
# touches the last `tail_messages` of the original list.
Test
pytest
Status
Budget tracking, threshold checks, and staged drain-then-summarize
recovery with tail preservation are real and tested. Published as
contextclip on PyPI.
Release files for contextclip 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| contextclip-0.0.3.tar.gz | 5.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| contextclip-0.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.3 kB
Release files / contextclip-0.0.3.tar.gz
| Download URL | contextclip-0.0.3.tar.gz |
|---|---|
| Size | 5.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
475ec16d71e0bd888b862d86514054be986dcd449974b003222b689fa3876dfa
|
|
BLAKE2b-256 checksum How to use checksums |
735e055313f8cee7383f34f448f3714df67b3dee797f43a221cd38e2ee6e350d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.8
|
Release files / contextclip-0.0.3-py3-none-any.whl
| Download URL | contextclip-0.0.3-py3-none-any.whl |
|---|---|
| Size | 5.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fd5bc640ea11ce34a37084aa3f9f03f47c33daae867e8157185a21e7f924bf1b
|
|
BLAKE2b-256 checksum How to use checksums |
45c116e918125cec96d7ce83742624f658634860dda75feff014a7bb509528a1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.8
|