Skip to content

Context Compression & MoA

源码版本v2026.7.20

Responsibility

Two things: (1) when history messages approach the provider's context limit, summarize/trim old messages to free up budget (context_compressor); (2) optionally use a Mixture-of-Agents path to aggregate outputs from multiple models (moa_loop). Both run inside the main loop — one keeps long conversations from overflowing the context window, the other aggregates multiple models for better answers.

Key Files

Data Flow

  1. Each turn the main loop evaluates whether compression is needed (see _should_run_preflight_estimate:213).
  2. When the threshold is hit, context_compressor is called:
  3. The "new space" freed by compression is partially refunded via iteration_budget.refund() (agent/iteration_budget.py), letting the main loop run a few more turns.
  4. If MoA is enabled, moa_loop calls multiple providers in parallel this turn and aggregates them as an enhancement or arbitration of the main answer.

Summary

The compressor is what keeps long conversations going; the core tradeoff is "what to drop, what to keep" — it prioritizes tool calls and path mentions, because losing them makes subsequent turns "amnesic". MoA is an orthogonal enhancement that can be toggled. Neither changes the main-loop structure; they only cut in at the right moment.

Unofficial community learning site. Content based on the MIT-licensed NousResearch/hermes-agent source.