Install
openclaw skills install context-guardian-keeperProduction-ready context continuity skill for autonomous AI agents. Use when tasks may outlive a single LLM context window, when you need durable checkpoints, structured summaries, restart recovery, pressure-aware trimming, or when the agent must stop safely instead of continuing blindly after context loss.
openclaw skills install context-guardian-keeperUse this skill to keep long-running agent work resumable, loss-aware, and safe. Use it when a task may outlive one model context window or when a host must stop safely before context loss causes bad decisions.
Follow this order. Do not skip steps.
Read these before acting:
references/task-state-schema.md — required task-state fields.references/summary-template.md — required summary shape.The host must provide all of these:
0.0 to 1.0 before each major action,If the host cannot provide the durable task-state read/write path, emit STATUS:MISSING_STATE and stop.
next_action is non-empty.touched_files, or files explicitly required by next_action.phase in this document corresponds to current_phase in references/task-state-schema.md; last_successful_action corresponds to last_action.summary or last_action.outcome; touched_files and relevant_artifacts correspond to the path values inside the artifacts array.references/task-state-schema.md, set next_action to START, write the initial durable state, write an initial summary from references/summary-template.md, and continue.STATUS:MISSING_STATE and stop.STATUS:MISSING_STATE and stop.next_action is empty, emit STATUS:MISSING_STATE and stop.next_action is DONE, COMPLETE, or FINISH, write final durable state + summary, emit STATUS:COMPLETE, and stop.STATUS:MISSING_STATE and stop.Default thresholds. Override them through host configuration when available:
warning_threshold = 0.55compress_threshold = 0.70critical_threshold = 0.85< 0.55 → continue normally0.55 to < 0.70 → continue, but expect fresher state/summary discipline0.70 to < 0.85 → continue only with a fresh summary before the next major action>= 0.85 → write checkpoint + summary, emit STATUS:HALT_CONTEXT_LIMIT, stop autonomous executionThis skill requires a host-provided numeric pressure value. Do not estimate pressure from characters, words, or token guesses in production hosts. Use this fallback only when the host cannot provide a reliable pressure value:
pressure = 0.0.Reference implementation note: scripts/context_guardian.py includes a character-based pressure estimator for reference/test environments only. Production hosts must prefer explicit host-owned pressure reporting over that estimator, and the reference SafetyGate.evaluate(...) accepts a host pressure override plus explicit integration flags such as action_changed_state, phase_or_goal_changed, and summary_conflict so integrations can follow the contract directly and avoid suppressing required checkpoints or summaries during low-pressure state transitions.
Repeat this loop before every major action.
next_action is DONE, COMPLETE, or FINISH, write final durable state + summary, emit STATUS:COMPLETE, and stop.STATUS:MISSING_STATE and stop.warning_threshold, continue to Step 3.warning_threshold but below compress_threshold, continue to Step 3.compress_threshold but below critical_threshold, continue to Step 3 and write a fresh summary in Step 5 before the next major action.critical_threshold, go to the Halt Rule.goal, phase, next_action, last_successful_action, constraints, and relevant_artifacts.goal, phase, next_action, last_successful_action, constraints, and all file paths listed in touched_files or explicitly named in next_action.warning_threshold, pressure is at or above compress_threshold, the summary conflicted with durable state, or the action changed phase or goal.This rule overrides everything else.
If pressure is at or above critical_threshold, or required pressure is missing after the first turn, do this immediately:
STATUS:HALT_CONTEXT_LIMIT,Do not soften this halt with confidence-based exceptions.
Do not continue autonomously after STATUS:HALT_CONTEXT_LIMIT.
When you write a summary, preserve:
Do not depend on raw chat history alone for recovery. Do not guess missing durable state that should be read from storage. Do not invent missing tool outputs.
Ignore this section if you are the runtime agent executing a task. Use this section only when wiring the module into a host agent loop.
references/integration-checklist.md to identify the smallest safe integration point.references/task-state-schema.md.action_changed_state=True whenever the guarded action mutated durable task state so below-critical turns still produce the required checkpoint. Also pass phase_or_goal_changed=True or summary_conflict=True whenever those conditions are true so the reference implementation emits the fresh summary required by the runtime contract even at normal pressure.STATUS:MISSING_STATE, STATUS:HALT_CONTEXT_LIMIT, and STATUS:COMPLETE as real state signals.status, ensure, checkpoint, bundle is usually enough.--root ... flag in every command.summaries/latest-summary.md for runtime reads, even when timestamped summaries are also stored.references/task-state-schema.md — canonical task-state fields.references/summary-template.md — canonical summary format.references/config-example.yaml — config shape, paths, thresholds.references/persisted-task-state.example.json — persisted state example.references/summary-example.md — concrete markdown summary example.references/integration-checklist.md — host-loop integration checklist, including weak-model-safe wrapper rules.references/implementation-notes.md — practical wrapper and runtime integration notes.Use scripts/context_guardian.py as the source-of-truth reference implementation when the host project uses Python or when behavior is ambiguous.
If wording and the reference implementation diverge, scripts/context_guardian.py governs the deterministic integration contract, while SKILL.md governs the mandatory agent execution behavior.
Use scripts/test_context_guardian.py to validate checkpoint creation, summary generation, restart recovery, critical-threshold stop behavior, and trimming policy.
A valid implementation must: