Gateway Context Compression Guard (src/gateway_compression.rs)

librefang · crates/librefang-runtime/src/gateway_compression.rs · rust · MIT
ai, files, infra, lang:rust

Implements a deterministic, pre-LLM safety net compression pass to prevent context window overflow from large tool results and backlogs. Reuse when managing LLM agent memory constraints.

// Source: https://github.com/librefang/librefang | License: MIT | Copyright 2024 LibreFang Contributors
// Provided via justclaw.it.com; keep this notice with the code.
//! Gateway-level safety-net compression (#4972).
//!
//! A cheap, deterministic, non-LLM pass that runs at the very top of the
//! agent loop — *before* the first prompt build, before any LLM call, and
//! before the LLM-based [`crate::context_compressor`] / `compactor` would
//! ever get a chance to run.
//!
//! ## Why a second compression seam exists
//!
//! The LLM-based agent-level compactor (`context_compressor.rs`) runs
//! *inside* the agent loop, only after the loop has decided to do work.
//! That's the right home for proper history summarisation, but it leaves a
//! gap: sessions that grow *between* turns (overn

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key