Reflow (Python)
Part of LoopEngine — a runtime
for defining and running AI agents through a transparent ReAct loop —
handling retries for prompt-too-long / truncated-output model failures.
Published to PyPI as reflowkit. 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 reflow import Reflow
async def on_prompt_too_long(messages):
return (await context_clip.recover(messages)).messages
reflow = Reflow(
on_prompt_too_long=on_prompt_too_long,
on_media_too_large=lambda messages: strip_large_images(messages),
on_truncated=lambda messages, attempt: [*messages, continue_message],
max_truncation_retries=2,
)
result = await reflow.call(
lambda messages: anthropic.messages.create(model=model, messages=messages, max_tokens=4096),
initial_messages,
)
# result.value — the response
# result.recoveries — ordered log of what happened, e.g. ["prompt_too_long"]
# result.truncated — True if still truncated after exhausting retries
Test
pytest
Status
Prompt-too-long recovery, media-too-large recovery, and bounded
truncation recovery are real and tested, with default classifiers for
common Anthropic/OpenAI-shaped errors. Published as
reflowkit on PyPI — the bare
reflow name is taken by an unrelated abandoned package.
Metadata
Release files for reflowkit 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 | Provenance | Actions |
|---|---|---|---|---|
| reflowkit-0.0.3.tar.gz | 6.2 kB | Without provenance | Details for reflowkit-0.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| reflowkit-0.0.3-py3-none-any.whl | Python 3 | none | any | Details for reflowkit-0.0.3-py3-none-any.whl |
Total release size: 12.0 kB
Release files / reflowkit-0.0.3.tar.gz
| Download URL | reflowkit-0.0.3.tar.gz |
|---|---|
| Size | 6.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d07f4038cb6599779eaf28e7c2c8efc9ebe8fcd39869d1dca8c17ac78d929cd2
|
|
BLAKE2b-256 checksum How to use checksums |
3d7bf6faa9dbf7cccdc39fbf7504212903153b4d61a2d53cf66ff442d35d3aed
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.8
|
Release files / reflowkit-0.0.3-py3-none-any.whl
| Download URL | reflowkit-0.0.3-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
54055b968d1b97be08893b8b2a46b96b91c5c8f068c8981c2267b64b6729482a
|
|
BLAKE2b-256 checksum How to use checksums |
878be27eac967cf98c36483e7ab6334919c7f98b2aaaf703f45cbb0483bef23e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.8
|
Security for reflowkit 0.0.3
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.