Skip to content

joyshmitz/openfang-lcm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

openfang-lcm

Lossless Context Management for LLM agents. DAG-based conversation compression with searchable history.

Problem

LLM agents have hard context window limits. When conversation history overflows, the standard approach is lossy trimming — oldest messages are silently dropped. The agent permanently loses information: prior decisions, facts, instructions, and reasoning.

Solution

Instead of dropping messages, openfang-lcm archives them into a persistent DAG (Directed Acyclic Graph) and replaces them with a compact LLM-generated summary. Original messages remain searchable and retrievable through agent tools.

Context fills to 70% → drain oldest 10 messages →
  archive as leaf nodes in SQLite →
  LLM summarize → store summary node →
  inject [CONTEXT SUMMARY] into active context →
  agent can search/expand compressed history via tools

Architecture

dag.rs          DagNode (Leaf/Summary), depth tracking
store.rs        SQLite persistence with WAL, V1→V2 migration
compressor.rs   LcmSummarizer trait, decomposed compress pipeline
tools.rs        lcm_grep / lcm_describe / lcm_expand
integration.rs  LosslessContextManager (main entry point)

Three agent tools

Tool Purpose
lcm_grep Search all archived nodes (including compressed history)
lcm_describe Show DAG structure for a session
lcm_expand Retrieve full original content of any archived node

Usage

use openfang_lcm::{LosslessContextManager, LcmSummarizer};

// Create a manager backed by SQLite
let lcm = LosslessContextManager::new(&db_path, summarizer, &session_id)?;

// Get tool definitions for the LLM
let tools = lcm.tool_definitions();

// On context overflow — compress oldest messages
lcm.recover_overflow(&mut messages, 10).await;

// Handle tool calls from the agent
let (content, is_error) = lcm.handle_tool_call("lcm_grep", &input);

Inspired by

  • LCM paper — Lossless Context Management concept
  • lossless-claw — TypeScript LCM plugin for OpenClaw (1,645+ stars)

This is a clean-room Rust implementation (no code copied).

License

MIT

About

Lossless Context Management for LLM agents — DAG-based conversation compression with searchable history

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages