Skip to main content

Lossless, provable, composable LLM context compression

Project description

secondwind

Lossless, provable, composable LLM tool-output compression, in-process.

import secondwind

session = secondwind.Session()
out = session.rewrite(request)          # compress a whole request's tool outputs
print(out["stats"])                     # tokens saved
secondwind.compress(block)              # or compress a single tool-output block

# one-line LiteLLM integration:
import litellm
from secondwind.litellm import SecondwindCallback
litellm.callbacks = [SecondwindCallback()]

# ASGI gateway (Starlette / FastAPI): rewrite request bodies before you forward them upstream
from secondwind.asgi import SecondwindMiddleware
app.add_middleware(SecondwindMiddleware)

# LangChain (LCEL): compress tool outputs before the model call
from secondwind.langchain import compress_tool_outputs
chain = compress_tool_outputs() | model

# LangGraph: compress the tool outputs an agent loop re-sends before each model call
from secondwind.langchain import compress_pre_model_hook
agent = create_react_agent(model, tools, pre_model_hook=compress_pre_model_hook())

# Agno: a lossless drop-in for its LLM-based tool-result compression
from secondwind.agno import SecondwindCompressionManager
agent = Agent(model=..., compress_tool_results=True,
              compression_manager=SecondwindCompressionManager(compress_tool_results=True))

# Strands Agents: compress tool results as they are produced
from secondwind.strands import SecondwindHooks
agent = Agent(model=..., tools=[...], hooks=[SecondwindHooks()])

# Cursor: a postToolUse hook that rewrites MCP tool output the model sees
#   ~/.cursor/hooks.json -> { "version": 1, "hooks": { "postToolUse": [ { "command": "python -m secondwind.cursor" } ] } }
# Bring your own codec: it competes in the best-of-N search, and secondwind proves
# decode(encode(x)) == x for every block, so a wrong codec is dropped, never shipped.
class MyCodec:
    def encode(self, text): ...   # -> str | None
    def decode(self, wire): ...   # -> str | None
session = secondwind.Session(codec=MyCodec())     # reckless is safe: proven per-instance
session = secondwind.Session(proposers=False)     # turn the aggressive search off

# Offload big blocks and recover them on demand, or back the store with Redis / S3 / a database.
session = secondwind.Session(resolver="resolve", offload_dir="~/.secondwind/offload")
session = secondwind.Session(store=MyStore())     # any object with put(id, value) and get(id)

Every result is lossless and independently verifiable (secondwind.verify(wire, hash)); the native library is bundled, so there is no build step and no model download.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

secondwind-0.1.0-py3-none-win_amd64.whl (15.9 MB view details)

Uploaded Python 3Windows x86-64

secondwind-0.1.0-py3-none-manylinux_2_34_x86_64.whl (16.0 MB view details)

Uploaded Python 3manylinux: glibc 2.34+ x86-64

secondwind-0.1.0-py3-none-manylinux_2_34_aarch64.whl (16.0 MB view details)

Uploaded Python 3manylinux: glibc 2.34+ ARM64

secondwind-0.1.0-py3-none-macosx_11_0_x86_64.whl (15.9 MB view details)

Uploaded Python 3macOS 11.0+ x86-64

secondwind-0.1.0-py3-none-macosx_11_0_universal2.whl (16.0 MB view details)

Uploaded Python 3macOS 11.0+ universal2 (ARM64, x86-64)

File details

Details for the file secondwind-0.1.0-py3-none-win_amd64.whl.

File metadata

  • Download URL: secondwind-0.1.0-py3-none-win_amd64.whl
  • Upload date:
  • Size: 15.9 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for secondwind-0.1.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 e332052d7fb244b8a5ba4165d73fd1d2598c0e01c8269defff8a464256f6dbc5
MD5 6fbbad209ff9eb8883b6101baa4a9796
BLAKE2b-256 c8bff2f8ab62f82a581a4508f1b5da4059770ee06c76a1088a4644435fb212c7

See more details on using hashes here.

Provenance

The following attestation bundles were made for secondwind-0.1.0-py3-none-win_amd64.whl:

Publisher: wheels.yml on orchetron/secondwind

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file secondwind-0.1.0-py3-none-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for secondwind-0.1.0-py3-none-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 d252a1eddd882f269e24d058d5748469738d3405d23abf7bce23e6424e531aa6
MD5 7c3eec8807f53b38d6ef2ee68e44996c
BLAKE2b-256 0f6ff1c434869ef2c2f9571a7dabf700d59affe31b7c021e93830c011a6c803b

See more details on using hashes here.

Provenance

The following attestation bundles were made for secondwind-0.1.0-py3-none-manylinux_2_34_x86_64.whl:

Publisher: wheels.yml on orchetron/secondwind

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file secondwind-0.1.0-py3-none-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for secondwind-0.1.0-py3-none-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 203ea687689082c8236a1e6962d20237297ed35e52d2dc6dc85a25796ea9fab9
MD5 349042375065416edceb28fe2b3f45b7
BLAKE2b-256 be0f98a087ae219a8af37dfad4880be2deb184298e92d4ec1292e0fce2822ba2

See more details on using hashes here.

Provenance

The following attestation bundles were made for secondwind-0.1.0-py3-none-manylinux_2_34_aarch64.whl:

Publisher: wheels.yml on orchetron/secondwind

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file secondwind-0.1.0-py3-none-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for secondwind-0.1.0-py3-none-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 773605f7acc45e72a2211d06b31b1d582aa21b0cd7ef9ddcbe85d89b46bfd4db
MD5 627ff249d8cbd8cd32715833a69d7383
BLAKE2b-256 ef9af1a9aebcb6fc24eddd0c6a4292858e509547bd7e9d7800ecb778f76700c9

See more details on using hashes here.

Provenance

The following attestation bundles were made for secondwind-0.1.0-py3-none-macosx_11_0_x86_64.whl:

Publisher: wheels.yml on orchetron/secondwind

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file secondwind-0.1.0-py3-none-macosx_11_0_universal2.whl.

File metadata

File hashes

Hashes for secondwind-0.1.0-py3-none-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 d981a60c5953dd1c02ffef2c193105c37481e97b9a45418e06b69567216a5ef2
MD5 5a93cfed131406c6ee99680f87d6105d
BLAKE2b-256 f8ee13696e3c7845259a2cc2b7ab49277f832d52f3c43ad0ef0a7ca851bb7e1e

See more details on using hashes here.

Provenance

The following attestation bundles were made for secondwind-0.1.0-py3-none-macosx_11_0_universal2.whl:

Publisher: wheels.yml on orchetron/secondwind

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page