Skip to main content

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)

Source distribution for contextclip 0.0.3
File Size Uploaded
contextclip-0.0.3.tar.gz 5.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for contextclip 0.0.3
File Interpreter ABI Platform
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

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

0.0.2

2 release files

0.0.1

2 release 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