Context Handover extracts Semantic Atoms, measures Context Drift, and optimally packs context into new sessions using a Bounded Knapsack Algorithm.
LLMs forget everything when a session ends. Standard memory is either too dumb or too expensive.
LLMs have no persistent memory across sessions. When a conversation ends, all context is lost. Existing solutions either use linear history (too dumb) or full vector re-indexing (too expensive).
Context Handover extracts Semantic Atoms, measures Context Drift, and optimally packs context using a Bounded Knapsack Algorithm for maximum efficiency.
Powerful tools for managing LLM context across sessions
Extract meaningful context units from conversations using LLM + Regex parsing
Measure topic shifts in real-time using KL Divergence and Cosine similarity
Optimize token usage mathematically with value-density knapsack algorithm
Track dependencies across sessions using directed acyclic graphs
Circuit breakers, retries, dead letter queue, and idempotency guarantees
Interactive observability dashboard for debugging and monitoring
How Context Handover processes and preserves semantic context
flowchart TD
subgraph Input["Input Layer"]
A[User Chat
Raw Text]
end
subgraph Processing["Processing Layer"]
B[Atom Extractor
LLM + Regex]
C[Atom Registry
Dedup + Embed]
D[Vector Store
Chroma/Qdrant]
end
subgraph Optimization["Optimization Layer"]
E[Drift Detector
KL + Cosine]
F[Token Budgeter
Knapsack Algo]
end
subgraph Output["Output Layer"]
G[Loss Ledger
Audit Trail]
H[New Session
Optimized Prompt]
end
A --> B
B --> C
C --> D
D --> E
D --> F
E --> G
F --> H
style Input fill:#1a1a1a,stroke:#c41e3a,color:#fff
style Processing fill:#1a1a1a,stroke:#8b1528,color:#fff
style Optimization fill:#1a1a1a,stroke:#c41e3a,color:#fff
style Output fill:#1a1a1a,stroke:#8b1528,color:#fff
style A fill:#2a1a1a,stroke:#c41e3a,color:#fff
style B fill:#2a1a1a,stroke:#c41e3a,color:#fff
style C fill:#2a1a1a,stroke:#c41e3a,color:#fff
style D fill:#2a1a1a,stroke:#c41e3a,color:#fff
style E fill:#2a1a1a,stroke:#c41e3a,color:#fff
style F fill:#2a1a1a,stroke:#c41e3a,color:#fff
graph LR
A[User Chat] --> B[Atom Extractor]
B --> C[Atom Registry]
C --> D[Vector Store]
D --> E[Drift Detector]
D --> F[Token Budgeter]
E --> G[Loss Ledger]
F --> H[New Session]
style A fill:#1a1a1a,stroke:#ff2d4f,color:#fff
style B fill:#1a1a1a,stroke:#c41e3a,color:#fff
style C fill:#1a1a1a,stroke:#8b1528,color:#fff
style D fill:#1a1a1a,stroke:#c41e3a,color:#fff
style E fill:#1a1a1a,stroke:#ff2d4f,color:#fff
style F fill:#1a1a1a,stroke:#8b1528,color:#fff
style G fill:#1a1a1a,stroke:#c41e3a,color:#fff
style H fill:#1a1a1a,stroke:#ff2d4f,color:#fff
The smallest unit of meaningful context. Like a single Lego brick that can be recombined.
Directed Acyclic Graph tracking atom relationships across sessions like a family tree.
Measures topic change since last handover, like a compass checking your course.
Mathematically selects the most valuable atoms for the token limit, like packing a suitcase.
Three simple steps to preserve context across sessions
Create a SessionManager and add your conversation messages. The system automatically tracks context as it's built.
from context_handover import SessionManager
manager = SessionManager(session_id="session_001")
manager.add_message(role="user", content="I want to build a rocket engine using methane.")
manager.add_message(role="assistant", content="Understood. Methane (CH4) offers high specific impulse...")
Automatically extract meaningful context units from your conversation history. Atoms capture semantic meaning, not just raw text.
# Extract atoms automatically
atoms = manager.extract_atoms()
print(f"Extracted {len(atoms)} semantic atoms.")
Create an optimized context package for the new session. The Knapsack algorithm ensures maximum value within token limits.
# Handover to a new session (preserving context)
new_session_pkg = manager.build_handover_package()
manager.handover_to_new_session("session_002", new_session_pkg)
Compare our approach with existing solutions
| Approach | Token Efficiency | Semantic Coherence | Latency | Auditability |
|---|---|---|---|---|
| โ Naive Buffer |
Low
|
Low
|
Fast โ | None โ |
| โก Vector Recall |
Medium
|
Medium
|
Slow ~200ms โ ๏ธ | Low โ ๏ธ |
| โ Context Handover |
High ๐ฏ
|
High ๐ฏ
|
Fast ~40ms โก | Full โ |
Seamless integration with popular frameworks
flowchart LR
A[Context Handover] --> B[LangChain]
A --> C[LlamaIndex]
A --> D[AutoGen]
A --> E[LangGraph]
A --> F[OpenTelemetry]
A --> G[Langfuse]
style A fill:#c41e3a,color:white
style B fill:#1a1a1a,stroke:#2196F3,color:#fff
style C fill:#1a1a1a,stroke:#FF9800,color:#fff
style D fill:#1a1a1a,stroke:#9C27B0,color:#fff
style E fill:#1a1a1a,stroke:#FF5722,color:#fff
style F fill:#1a1a1a,stroke:#00BCD4,color:#fff
style G fill:#1a1a1a,stroke:#E91E63,color:#fff
Custom Memory Module
Node Parser
State Handover
Native Tracing
Observability
Built for reliability at scale
Duplicate events auto-detected & ignored
Exponential backoff for LLM/Redis failures
Prevents cascading failures
Failed events saved for replay
Redaction & encryption hooks
Complete loss ledger for compliance
How atoms move through the system
sequenceDiagram
participant User
participant Manager
participant Extractor
participant Registry
participant Vector
User->>Manager: Add Message
Manager->>Extractor: Trigger Extraction
Extractor->>Extractor: Parse LLM + Regex
Extractor->>Registry: Submit Atoms
Registry->>Registry: Deduplicate
Registry->>Vector: Generate Embeddings
Vector-->>Manager: Confirmation
Manager-->>User: Done
style User fill:#1a1a1a,stroke:#c41e3a,color:#fff
style Manager fill:#1a1a1a,stroke:#ff2d4f,color:#fff
style Extractor fill:#1a1a1a,stroke:#8b1528,color:#fff
style Registry fill:#1a1a1a,stroke:#c41e3a,color:#fff
style Vector fill:#1a1a1a,stroke:#ff2d4f,color:#fff
Get up and running in minutes
from context_handover import SessionManager, SemanticAtom # Initialize manager manager = SessionManager(session_id="session_001") # Add meaningful interactions manager.add_message( role="user", content="I want to build a rocket engine using methane." ) manager.add_message( role="assistant", content="Understood. Methane (CH4) offers high specific impulse..." ) # Extract atoms automatically atoms = manager.extract_atoms() print(f"Extracted {len(atoms)} semantic atoms.") # Handover to a new session new_session_pkg = manager.build_handover_package() manager.handover_to_new_session("session_002", new_session_pkg)
Start building intelligent memory for your LLM applications today.