ToolOutputCompressor
org.llm4s.context.ToolOutputCompressor
object ToolOutputCompressor
Handles intelligent compression and externalization of tool outputs.
Tool outputs (from function calls, API responses, file reads) can be very large and quickly consume the context window. This compressor applies content-aware strategies to reduce their size while preserving essential information.
==Content Type Detection==
The compressor automatically detects content types:
- '''JSON/YAML''': Removes null values, empty strings, truncates large arrays
- '''Logs''': Keeps head/tail, collapses repeated lines
- '''Errors''': Preserves error message and top stack frames
- '''Binary''': Replaces with placeholder (always externalized)
- '''Text''': Generic word-based truncation
==Size Thresholds==
Content is processed based on size:
- '''< 2KB''': Kept as-is (no compression)
- '''2KB - 8KB''': Inline compression (type-specific)
- '''> 8KB''': Externalized to ArtifactStore with content pointer
==Externalization==
Large content is stored in an ArtifactStore and replaced with a pointer:
[EXTERNALIZED: abc123... | JSON | JSON object with 42 fields, 15234 bytes]
The original content can be retrieved using the artifact key.
Attributes
- See also
-
ArtifactStore for content storage interface
DeterministicCompressor which uses this for the tool compaction phase
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
ToolOutputCompressor.type
Members list
In this article