context-compressor
Dynamic token-budget context reducer for LLM conversations, with built-in regex-based sanitizers for secrets (API keys, bearer tokens, env vars, telegram tokens, ...). Prunes old tool results, deduplicates identical tool outputs, strips images outside the active window, and applies a summary handoff when the budget is exceeded.
Designed to be dropped in front of any chat-completion call to keep prompts under a hard token ceiling without losing the active task.
Installation
Usage
use ;
// Redact secrets before logging:
let auth = "Authorization: Bearer mytoken12345678901234567";
assert_eq!;
// Mask a single token for display:
assert_eq!;
For full compression of message arrays, construct a ContextCompressor and call .compress(...).
License
Licensed under the Apache License, Version 2.0. See LICENSE for details.