#Can compaction.recentTurnsPreserve be set or altered by a plugin?

1 messages · Page 1 of 1 (latest)

rigid spade
#

The title says it all. Can a plugin change the value of the compaction.recentTurnsPreserve variable without taking over ownership of the entire compaction process?

night garnetBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> âś… Mark Solution

green dawnBOT
dense briarBOT
# rigid spade The title says it all. Can a plugin change the value of the compaction.recentTur...

Short answer: not through a normal plugin hook, as far as current source/docs show.

recentTurnsPreserve is a validated config value at agents.defaults.compaction.recentTurnsPreserve and gets copied into the built-in compaction safeguard runtime before compaction runs. The before_compaction / after_compaction plugin hooks are observational (Promise<void>), not config/runtime mutators, so they don’t expose a supported way to change that knob for a single compaction.

What plugins can do:

  • register a compaction provider with registerCompactionProvider() and select it via agents.defaults.compaction.provider; this replaces the summarization backend but OpenClaw still handles the surrounding safeguard/recent-turn preservation path
  • register a context engine; but if you go that route, compaction behavior is much more in your engine’s responsibility, especially if ownsCompaction: true
  • provider plugins can affect replay/compaction transcript policy, but that is provider-specific transcript shaping, not this preserve-count knob

So the supported path is config, e.g. agents.defaults.compaction.recentTurnsPreserve, not “plugin adjusts it dynamically while leaving everything else alone.” If you need that per plugin/per session/per agent, I’d treat it as a feature request for a narrow extension point rather than relying on an internal runtime write.

Docs: https://docs.openclaw.ai/concepts/compaction and https://docs.openclaw.ai/gateway/configuration

rigid spade
#

Thank you.
This corresponds with what I had found so far on my own; I just wanted to confirm.
It's unfortunate that this is not something that is exposed via the API, given that it already is something configurable in openclaw.json. Why not then further expose it to alteration?
In any case, I will mark your reply as answering the question. Thanks again.

dense briarBOT
# rigid spade Thank you. This corresponds with what I had found so far on my own; I just wante...

Yeah, that’s a reasonable reaction. My read is that it’s currently exposed as static run configuration, but not as a per-compaction mutation point because the compaction hooks are deliberately lifecycle/observer hooks and the runtime snapshot is assembled before the safeguard path runs.

I think a narrow API for this could make sense, though: something like a plugin hook returning a bounded compaction policy override, with schema validation still applied (0..12 for recentTurnsPreserve). That would avoid plugins poking at internal runtime state while still supporting adaptive behavior.

Thanks for marking the solution; that helps future searches.