
Multi-agent large language model (LLM) pipelines accumulate intermediate messages in a shared context window, leading to state bloat, increased inference costs, and degraded task fidelity due to the Lost-in-the-Middle effect. We present SemaGC (Semantic Garbage Collector), a runtime context management system for multi-agent LLM orchestration frameworks. SemaGC operates as a custom state reducer within LangGraph pipelines, transparently intercepting context updates to prune semantically drifted messages and compress relevant intermediate outputs into dense Micro-Rationales. Evaluated across five complex software engineering tasks on a 6-node pipeline, SemaGC achieves a consistent 42.9% reduction in context state size with an average GC overhead of only 1.91 seconds per pipeline execution. Our results demonstrate that cosine similarity between intermediate agent messages and the original task goal is an effective and lightweight signal for context garbage collection in multi-agent LLM systems.
