Skip to main content

Framework-agnostic, provider-agnostic context-window packer for LLM chat history.

Project description

convopack

Framework-agnostic, provider-agnostic context-window packer for LLM chat history.

Status: pre-alpha. API may change before 0.1.0.

Why

LLM apps accumulate messages until they overflow the model's context window. Existing fixes are framework-locked (LangChain, LangGraph), provider-specific (Anthropic context-management beta), or designed for long-term semantic memory rather than turn-by-turn packing (mem0).

convopack is a small, focused library that takes a conversation history and a token budget and returns the largest tail that fits, while:

  • preserving tool_use / tool_result pairs atomically,
  • normalising message shapes across OpenAI, Anthropic, and Gemini,
  • letting you plug in any tokenizer or summariser,
  • staying async-friendly and zero-dependency at the core.

Install

pip install convopack                 # core only
pip install "convopack[tiktoken]"     # + OpenAI tokenizer
pip install "convopack[anthropic]"    # + Anthropic tokenizer
pip install "convopack[all]"          # everything

Quickstart

from convopack import Packer, Recency

packer = Packer(
    budget=8000,
    tokenizer="tiktoken:gpt-4o",
    strategy=Recency(),
    pin=["system", "first_user"],
)

packed = packer.pack(messages)        # list[dict] in, list[dict] out

Strategies

Strategy When to use
Recency Keep the tail that fits. Cheapest, no LLM call.
SummaryEvict Summarise evicted turns into a single system message.
Importance Score each turn yourself; drop the lowest until it fits.
SemanticDedup Remove near-duplicate turns first.

Comparison

Feature convopack LangChain trim_messages mem0 Anthropic native
Framework-free yes no no yes
Multi-provider message shapes yes partial n/a no
Tool-call pair safety yes no n/a yes (one type)
Pluggable strategy yes no n/a no
Async summariser yes no n/a n/a
Scope per-turn per-turn cross-session per-turn

License

MIT

Project details


Download files

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

Source Distribution

convopack-0.1.0.tar.gz (16.2 kB view details)

Uploaded Source

Built Distribution

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

convopack-0.1.0-py3-none-any.whl (19.2 kB view details)

Uploaded Python 3

File details

Details for the file convopack-0.1.0.tar.gz.

File metadata

  • Download URL: convopack-0.1.0.tar.gz
  • Upload date:
  • Size: 16.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for convopack-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4f3a217ee099290aa7b0385e311848c2554469e55f03d856eedf2d8d82eda562
MD5 85655b2c1785a393b25735631bcbe4c3
BLAKE2b-256 805605eba84a209acf3c374ae4fd5defbd541a3012193feb3fcc6aee1a1a5dde

See more details on using hashes here.

File details

Details for the file convopack-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: convopack-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 19.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for convopack-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b3a6a791ecbf65feda7f5f6bbed10dcb813e039da6fdf24c0d36281ad3d0f40a
MD5 9bf01a33289aadb194cbded508ca429b
BLAKE2b-256 9f70644bd941b5b0efa69c14cfb6dc0c53a9608771bb54d809f923e89fdef890

See more details on using hashes here.

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