Skip to content

feat(compact): reactive compaction with adaptive window cap and context reservation - #274

Open
jiangchuanso wants to merge 1 commit into
iOfficeAI:mainfrom
jiangchuanso:feat/reactive-compaction
Open

jiangchuanso wants to merge 1 commit into
iOfficeAI:mainfrom
jiangchuanso:feat/reactive-compaction

Conversation

@jiangchuanso

Copy link
Copy Markdown

Summary

Introduce reactive compaction: instead of compacting only on a fixed trigger, the agent reacts to context-window pressure, preserves the most recent original messages, and emits context/compaction events so hosts (e.g. JSON stream consumers) can observe what happened.

  • Adaptive reservation + window cap (crates/aion-config/src/compact.rs, config.rs): compaction reserve and a configurable window cap are parsed from config, so reserved headroom adapts to the effective context window.
  • Reactive flow (crates/aion-agent/src/compact/auto.rs, estimate.rs, context_usage.rs, engine.rs): compaction is driven by context-usage signals; recent original turns are kept verbatim instead of being folded into the summary. New context/compaction notifications are published through the output sinks (output/sink.rs, output/protocol_sink.rs).
  • Window-trimmed summarization input, and responses exceeding the window (HTTP 400) are now classified as PromptTooLong rather than a generic error (crates/aion-providers/src/error.rs, transport.rs, retry.rs).
  • Protocol events (crates/aion-protocol/src/events.rs, commands.rs, crates/aion-types/src/compact.rs): new context/compaction events are added to the JSON stream protocol and documented in docs/json-stream-protocol.md.

Test plan

  • Unit tests cover the auto-compact policy (auto_test.rs), provider error classification (error_test.rs) and protocol command construction (commands_test.rs).
  • Integration test crates/aion-agent/tests/autocompact_test.rs exercises the end-to-end compact behavior.
  • Existing cargo test / cargo clippy gates in CI validate the change.

…xt reservation

Implement reactive compaction that preserves recent original messages and emits context/compaction events. Add adaptive reservation and a configurable window cap, and map over-window 400 responses to PromptTooLong.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant