imbue-mngr-autocompact
Automatic context compaction plugin for mngr that manages context compaction for conversational agents implementing HasCompactionMixin (e.g., Claude Code agents).
Overview
In LLM-based coding agents using Claude Code and similar architectures, prompt cache TTL remains warm for a finite lifespan (e.g., 60 minutes for Anthropic Claude models). When an agent sits idle, its prompt cache expires, causing subsequent turns to incur full cache-miss latency and token costs.
mngr-autocompact triggers context compaction (such as Claude's /compact) shortly before cache expiration (e.g., after 57 minutes of idle time), or right before delivering a new prompt to a stale agent. This drastically reduces prompt token usage and latency while keeping concise summary context in the conversation.
The plugin is completely stateless: it does not rely on long-lived daemon threads or in-memory global state, making it reliable in standard, short-lived mngr CLI workflows.
Configuration
Configure the plugin in settings.toml under [plugins.autocompact], or via mngr config:
[plugins.autocompact]
# Compaction mode: "disabled" (default), "proactive_timer", or "on_next_prompt"
mode = "proactive_timer"
# Minutes before cache expiration to trigger compaction (default: 3)
epsilon_offset_minutes = 3
# Minimum context size in tokens required to trigger compaction (default: 200000; set to 0 to disable)
min_context_tokens = 200000
# Optional override for model cache TTL in minutes (uses agent's reported TTL if omitted)
# cache_ttl_minutes = 60
You can also configure options from the CLI:
# Enable proactive periodic compaction
mngr config set plugins.autocompact.mode proactive_timer
# Set token threshold to 80k
mngr config set plugins.autocompact.min_context_tokens 80000
Modes
proactive_timer: Enables staleness checks when runningmngr autocompact checkormngr autocompact run. An agent is considered stale when it is running, idle, and its idle time $\ge (T_{\text{cache_ttl}} - \epsilon)$.on_next_prompt: Automatically checks staleness before delivering a message to an agent (hooked intomngr message). If the agent is idle past its cache TTL, compaction is triggered immediately before the message is sent.disabled: Disables automatic compaction checks.
Usage
CLI Commands (mngr autocompact)
The plugin registers the autocompact command group on mngr with two subcommands: check (inspect only) and run (execute compaction):
# Inspect which agents need compaction without triggering it
mngr autocompact check my-agent
mngr autocompact check agent-1 agent-2
mngr autocompact check --all
# Run compaction on stale agents
mngr autocompact run my-agent
mngr autocompact run agent-1 agent-2
mngr autocompact run --all
# Output results as JSON
mngr autocompact check --all --format json
mngr autocompact run --all --format json
Example JSON output for check:
{"agents": ["agent-1", "agent-2"]}
Example JSON output for run:
{"compacted": ["agent-1", "agent-2"]}
Scheduling Proactive Compaction
Because mngr CLI processes are short-lived, proactive compaction is driven by running mngr autocompact run --all periodically via your preferred scheduler (cron, systemd timer, or background task).
For example, to compact stale agents every 5 minutes with cron:
*/5 * * * * mngr autocompact run --all -q
Agents are only compacted once per idle epoch (until a new turn completes), ensuring that frequent checks never issue redundant compactions.
A check never waits on a busy agent. If another send to the agent (a user's message, a mngr message) holds its message lock for more than a few seconds, or the agent is no longer idle once the lock is free, it is skipped and reconsidered on the next check.
A long-running process that embeds mngr can run the same check on its own timer instead of launching the CLI: compact_stale_agents_by_name(mngr_ctx, names) in imbue.mngr_autocompact.manager compacts whichever of the named agents are stale and returns the names it compacted. Unlike mngr autocompact run, it skips a name it cannot use (one matching no agent, an agent on an offline host, a stopped agent, or one without compaction support) rather than failing the batch, since an embedder lists its agents a moment before calling. Its docstring has the details, including the provider instances a caller that builds a context per call must release.
Agent Compatibility
The plugin is agent-agnostic and interacts with any agent implementing the HasCompactionMixin interface (imbue.mngr.interfaces.agent.HasCompactionMixin), including:
request_compaction(instructions=None, message_lock_timeout_seconds=None, expected_idle_since=None): sends/compact(optionally with instructions) or the agent's native compaction command, optionally bounding the wait for the agent's message lock and skipping an agent that is no longer idle since the given moment.get_cache_ttl_minutes(): reports prompt cache TTL (default: 60 minutes for Claude).get_context_tokens(): reports context token count from recent transcript turns, orNonewhen it is unknown. The Claude and Pi harnesses reportNoneafter a compaction until the agent's next turn reports a real size, so an agent compacted since its last turn is not compacted again.get_idle_since(): reports when the agent finished its latest turn.
Metadata
Release files for imbue-mngr-autocompact 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| imbue_mngr_autocompact-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for imbue_mngr_autocompact-0.1.0-py3-none-any.whl |
Release files / imbue_mngr_autocompact-0.1.0-py3-none-any.whl
| Download URL | imbue_mngr_autocompact-0.1.0-py3-none-any.whl |
|---|---|
| Size | 13.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
593d92876ff3530b530673d6b6170a26f46718bf055528b31f486cd6b8023dd4
|
|
BLAKE2b-256 checksum How to use checksums |
6bb522ee49e878fd6bdf747133f2cfd02f539023b34e7a1027497534f6d72bc1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.
Transparency logSecurity for imbue-mngr-autocompact 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
1 file in this release has been uploaded with provenance metadata.
Attestation for imbue_mngr_autocompact-0.1.0-py3-none-any.whl
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.