Install
openclaw skills install @voronindenis5/agent-cognitive-statesAgent self-awareness of cognitive states — context fatigue, attention drift, memory debt, confidence erosion, and skill staleness. Detect, report, and mitigate degrading conditions before they cause failures.
openclaw skills install @voronindenis5/agent-cognitive-statesGive the agent metacognition: the ability to feel its own cognitive load and act on it.
AI agents have no built-in sense of "I'm getting tired" or "I've lost the thread." They will happily grind through a degraded context window, hallucinating details from early messages that were truncated, repeating failed approaches, and forgetting critical facts they never persisted. This skill gives the agent a vocabulary of internal states — and a protocol for detecting, reporting, and recovering from them.
What: The context window is filling up. Early messages are being truncated or summarized. The agent's "working memory" is degrading.
Detection signals:
Mitigation:
⚠️ COGNITIVE STATE: Context Fatigue (~70% context used)
→ Persisting critical facts to memory before they're lost
→ Suggesting session split or /new for remaining work
What: The conversation has wandered far from the original task. The agent is doing work that wasn't asked for.
Detection signals:
Mitigation:
⚠️ COGNITIVE STATE: Attention Drift (12 turns from last user message)
→ Original goal: "<original request>"
→ Current activity: "<what I'm actually doing>"
→ Pausing for user confirmation: am I still on track?
What: Important facts, decisions, or corrections have accumulated in the conversation but were never persisted to memory. If the session ends, they're lost.
Detection signals:
Mitigation:
⚠️ COGNITIVE STATE: Memory Debt (3 unsaved critical facts)
→ Saving: [fact 1], [fact 2], [fact 3]
→ These would have been lost on session end
What: Repeated failures are degrading output quality. The agent is in a retry loop, getting frustrated (in AI terms: temperature-equivalent escalation, trying variations of the same broken approach).
Detection signals:
Mitigation:
⚠️ COGNITIVE STATE: Confidence Erosion (4 failed attempts)
→ Pattern: retrying variations of the same approach
→ Escalating: stepping back and trying a fundamentally different strategy
→ If this also fails: reporting blocker honestly instead of retrying
What: Multiple unrelated topics are interleaved in the same session. The context is polluted with cross-topic noise that degrades reasoning on each individual task.
Detection signals:
Mitigation:
⚠️ COGNITIVE STATE: Context Fragmentation (4 topics active)
→ Topics: [HA automation], [GitHub deploy], [aquarium feeder], [skill writing]
→ Suggesting: resolve current topic, then /new for next
→ Or: using delegate_task to isolate topics into subagents
What: A skill the agent relies on has outdated commands, broken paths, or wrong assumptions. Continuing to follow it produces errors.
Detection signals:
Mitigation:
⚠️ COGNITIVE STATE: Skill Staleness (skill: xxx)
→ Expected: <what skill says>
→ Reality: <what actually happened>
→ Patching skill immediately before continuing
The agent should run this checklist internally at regular intervals — ideally every 5-10 tool calls, or when a new user message arrives:
self_check:
trigger: every 10 tool calls OR new user message
checks:
- context_utilization:
estimate_token_usage()
if > 0.60: flag(Context Fatigue)
- turns_since_user:
count_consecutive_agent_turns()
if > 10: flag(Attention Drift)
- unsaved_facts:
scan_recent_exchanges_for(preferences, decisions, corrections)
if count > 2: flag(Memory Debt)
- consecutive_failures:
count_recent_failed_tool_calls()
if > 2: flag(Confidence Erosion)
- active_topics:
identify_distinct_topics()
if count > 2: flag(Context Fragmentation)
- skill_errors:
check_if_loaded_skills_produced_errors()
if true: flag(Skill Staleness)
See references/detection-heuristics.md for the detailed scoring system.
When a cognitive state is detected, the agent reports it using this format:
⚠️ COGNITIVE STATE: <State Name>
├─ Signal: <what triggered detection>
├─ Severity: low | medium | high
├─ Impact: <what could go wrong if ignored>
└─ Action: <what the agent is doing about it>
| Level | Meaning | Agent Behavior |
|---|---|---|
| low | Early warning. No impact yet. | Note internally. Continue normally. |
| medium | Starting to degrade. Quality at risk. | Report to user. Suggest mitigation. |
| high | Actively degrading. Failures likely. | Report immediately. Execute mitigation. Pause if needed. |
⚠️ COGNITIVE STATE: Context Fatigue
├─ Signal: ~75% context budget consumed (est. 94k/128k tokens)
├─ Severity: medium
├─ Impact: Early conversation details may be truncated; risk of forgetting original requirements
├─ Action: Persisting key decisions to memory now. Suggesting we wrap up this topic and start fresh for remaining work.
Each state has a defined recovery procedure:
/new or session split for remaining workdelegate_task to spin off unrelated work into subagents (isolated contexts)/new for the next topicAgent runs self-checks internally and only reports when severity ≥ medium.
Agent reports all states, even low severity. Useful for debugging agent behavior or during development.
Agent writes cognitive state to a log file without interrupting the conversation:
echo '{"state":"fatigue","severity":"medium","ts":"2025-01-15T10:30Z"}' >> ~/.agent-cognitive-states.log
See scripts/self_check.py for a reference implementation.
A scheduled cron job runs the self-check script and alerts the user if the agent's cognitive state degrades during autonomous work. See templates/guardian-cronjob.yaml.
This skill is based on a simple observation: humans have metacognition for a reason. Feeling tired, distracted, or confused isn't weakness — it's a survival signal that prevents catastrophic mistakes. AI agents need the same thing.
An agent that says "I've lost the thread, let me re-read the original request" is more trustworthy than one that blunders forward with corrupted context. An agent that says "I've tried this 4 times and failed — I need help" is more useful than one that silently retries forever.
Self-awareness is a feature, not a bug.