Agent class supports context compression to handle large amounts of information efficiently. This is particularly useful when dealing with long conversation histories or large documents that might exceed the model’s context window.
Compression Strategies
Upsonic offers different compression strategies configured viacompression_strategy:
none(Default): No compression.simple: Basic whitespace removal and middle truncation if length exceeds limit.llmlingua: Advanced compression using the LLMLingua library (requirespip install llmlingua).
Simple Compression
Use simple compression for basic optimization without additional dependencies.LLMLingua Compression
Use LLMLingua for smart, semantic compression that preserves key information.Using
llmlingua requires installing the package: pip install llmlingua. The agent will perform the compression locally before sending the prompt to the LLM.
