ShieldCortex — Persistent Memory & Security for AI Agents
Give your agent a brain that persists between sessions and protect it from memory poisoning attacks.
When to Use This Skill
- You want to remember things between sessions (decisions, preferences, architecture, context)
- You need to recall relevant past context at the start of a session
- You want knowledge graph extraction from memories (entities, relationships)
- You need to protect memory from prompt injection or poisoning attacks
- You want credential leak detection in memory writes
- You want to audit what has been stored in and retrieved from memory
- You want to scan instruction files (SKILL.md, .cursorrules, CLAUDE.md) for threats
Setup
Install the npm package globally, then configure the MCP server:
npm install -g shieldcortex
shieldcortex install
Python SDK also available:
pip install shieldcortex
Core Workflow
Session Start
At the start of every session, retrieve prior context:
- Call
start_session to begin a new session and get relevant memories
- Or call
get_context with a query describing the current task
Remembering
Call remember immediately when any of these happen:
- Architecture decisions — "We're using PostgreSQL for the database"
- Bug fixes — capture root cause and solution
- User preferences — "Always use TypeScript strict mode"
- Completed features — what was built and why
- Error resolutions — what broke and how it was fixed
- Project context — tech stack, key patterns, file structure
Parameters:
title (required): Short summary
content (required): Detailed information
category: architecture, pattern, preference, error, context, learning, todo, note
importance: low, normal, high, critical
project: Scope to a specific project (auto-detected if omitted)
tags: Array of tags for categorisation
Recalling
Call recall to search for past memories:
mode: "search" — query-based semantic search (default)
mode: "recent" — most recent memories
mode: "important" — highest-salience memories
Filter by category, tags, project, or type (short_term, long_term, episodic).
Forgetting
Call forget to remove outdated or incorrect memories:
- Delete by
id for a specific memory
- Delete by
query to match content
- Always use
dryRun: true first to preview what will be deleted
- Use
confirm: true for bulk deletions
Session End
Call end_session with a summary to trigger memory consolidation. This promotes short-term memories to long-term and runs decay on old, unaccessed memories.
Knowledge Graph
ShieldCortex automatically extracts entities and relationships from memories.
graph_query — traverse from an entity, returns connected entities up to N hops
graph_entities — list known entities, filter by type (person, tool, concept, file, language, service, pattern)
graph_explain — find the path connecting two entities
Use the knowledge graph to understand relationships between concepts, technologies, and decisions across the project.
Memory Intelligence
consolidate — merge duplicate/similar memories, run decay. Use dryRun: true to preview
detect_contradictions — find conflicting memories (e.g., "use Redis" vs "don't use Redis")
get_related — find memories connected to a specific memory ID
link_memories — create explicit relationships (references, extends, contradicts, related)
memory_stats — view total counts, category breakdown, decay stats
Security & Defence
Every memory write passes through a 6-layer defence pipeline:
- Input Sanitisation — strips control characters and null bytes
- Pattern Detection — regex matching for known injection patterns
- Semantic Analysis — embedding similarity to attack corpus
- Structural Validation — JSON/format integrity checks
- Behavioural Scoring — anomaly detection over time
- Credential Leak Detection — blocks API keys, tokens, private keys (25+ patterns, 11 providers)
Iron Dome
Behavioural security layer that controls what agents can do, not just what they remember:
iron_dome_activate — activate with a profile: school, enterprise, personal, or paranoid
iron_dome_status — check active profile, trusted channels, and approval rules
iron_dome_check — gate an action (e.g., send_email, delete_file) before execution
iron_dome_scan — scan text for prompt injection patterns
Profiles control action gates (what actions require approval), channel trust (which instruction sources are trusted), and approval rules.
Security Tools
audit_query — query the forensic audit log of all memory operations
defence_stats — view defence system statistics (blocks, allows, quarantines)
quarantine_review — review and manage quarantined memories (list, approve, reject)
scan_memories — scan existing memories for signs of poisoning
scan_skill — scan an instruction file for hidden threats (SKILL.md, .cursorrules, CLAUDE.md, etc.)
Universal Memory Bridge
ShieldCortex can act as a security layer for any memory backend — not just its own. Use ShieldCortexGuardedMemoryBridge to wrap any memory system with the full defence pipeline:
import { ShieldCortexGuardedMemoryBridge, MarkdownMemoryBackend } from 'shieldcortex';
const bridge = new ShieldCortexGuardedMemoryBridge({
backend: new MarkdownMemoryBackend('~/.my-memories/'),
});
// All writes pass through the 6-layer defence pipeline
await bridge.write({ title: 'Decision', content: 'Use PostgreSQL' });
Built-in backends: MarkdownMemoryBackend, OpenClawMarkdownBackend. Implement the backend interface for custom storage.
Project Scoping
set_project — switch active project context
get_project — show current project scope
- Use
project: "*" for global/cross-project memories
Best Practices
- Remember immediately — call
remember right after a decision is made or a bug is fixed, not at the end of the session
- Use categories — architecture, pattern, preference, error, context, learning
- Set importance — mark critical decisions as
importance: "critical" so they resist decay
- Recall at session start — always call
get_context or start_session first
- End sessions properly — call
end_session with a summary to trigger consolidation
- Review contradictions — periodically run
detect_contradictions to catch conflicting information
- Scope by project — memories are automatically scoped to the current project directory
Troubleshooting
Memory not found in recall:
- Try
mode: "search" with different query phrasing
- Check
set_project — you may be searching the wrong project scope
- Use
includeDecayed: true to find memories that have faded
Memory blocked by firewall:
- The defence pipeline detected a potential threat (injection, credential leak)
- Check
audit_query for the specific block reason
- Review with
quarantine_review if it was a false positive
- Avoid including literal API keys or tokens in memory content
Consolidation removing memories:
- Run
consolidate with dryRun: true first to preview
- Mark important memories as
importance: "critical" to prevent decay
- Access memories regularly —
recall boosts activation and prevents decay
OpenClaw Auto-Memory
When using the OpenClaw hook, auto-memory extraction is off by default. Enable it to automatically extract memories from session output:
npx shieldcortex config --openclaw-auto-memory
When enabled, the system deduplicates against recent memories to avoid storing duplicates. Configure with:
openclawAutoMemory — enable/disable (default: false)
openclawAutoMemoryDedupe — deduplicate against existing memories (default: true)
openclawAutoMemoryNoveltyThreshold — similarity threshold for deduplication (default: 0.88)
openclawAutoMemoryMaxRecent — number of recent memories to check (default: 300)
Links
1---2name: shieldcortex3description: Persistent memory system with security for AI agents. Remembers decisions, preferences, architecture, and context across sessions with knowledge graphs, decay, contradiction detection, and a 6-layer defence pipeline with Iron Dome behavioural protection. Use when asked to "remember this", "what do we know about", "recall context", "scan for threats", "run security audit", "check memory stats", or when starting a new session and needing prior context.4---56# ShieldCortex — Persistent Memory & Security for AI Agents78Give your agent a brain that persists between sessions and protect it from memory poisoning attacks.910## When to Use This Skill1112- You want to remember things between sessions (decisions, preferences, architecture, context)13- You need to recall relevant past context at the start of a session14- You want knowledge graph extraction from memories (entities, relationships)15- You need to protect memory from prompt injection or poisoning attacks16- You want credential leak detection in memory writes17- You want to audit what has been stored in and retrieved from memory18- You want to scan instruction files (SKILL.md, .cursorrules, CLAUDE.md) for threats1920## Setup2122Install the npm package globally, then configure the MCP server:2324```bash25npm install -g shieldcortex26shieldcortex install27```2829Python SDK also available:3031```bash32pip install shieldcortex33```3435## Core Workflow3637### Session Start3839At the start of every session, retrieve prior context:40411. Call `start_session` to begin a new session and get relevant memories422. Or call `get_context` with a query describing the current task4344### Remembering4546Call `remember` immediately when any of these happen:4748- **Architecture decisions** — "We're using PostgreSQL for the database"49- **Bug fixes** — capture root cause and solution50- **User preferences** — "Always use TypeScript strict mode"51- **Completed features** — what was built and why52- **Error resolutions** — what broke and how it was fixed53- **Project context** — tech stack, key patterns, file structure5455Parameters:56- `title` (required): Short summary57- `content` (required): Detailed information58- `category`: architecture, pattern, preference, error, context, learning, todo, note59- `importance`: low, normal, high, critical60- `project`: Scope to a specific project (auto-detected if omitted)61- `tags`: Array of tags for categorisation6263### Recalling6465Call `recall` to search for past memories:6667- `mode: "search"` — query-based semantic search (default)68- `mode: "recent"` — most recent memories69- `mode: "important"` — highest-salience memories7071Filter by `category`, `tags`, `project`, or `type` (short_term, long_term, episodic).7273### Forgetting7475Call `forget` to remove outdated or incorrect memories:7677- Delete by `id` for a specific memory78- Delete by `query` to match content79- Always use `dryRun: true` first to preview what will be deleted80- Use `confirm: true` for bulk deletions8182### Session End8384Call `end_session` with a summary to trigger memory consolidation. This promotes short-term memories to long-term and runs decay on old, unaccessed memories.8586## Knowledge Graph8788ShieldCortex automatically extracts entities and relationships from memories.8990- `graph_query` — traverse from an entity, returns connected entities up to N hops91- `graph_entities` — list known entities, filter by type (person, tool, concept, file, language, service, pattern)92- `graph_explain` — find the path connecting two entities9394Use the knowledge graph to understand relationships between concepts, technologies, and decisions across the project.9596## Memory Intelligence9798- `consolidate` — merge duplicate/similar memories, run decay. Use `dryRun: true` to preview99- `detect_contradictions` — find conflicting memories (e.g., "use Redis" vs "don't use Redis")100- `get_related` — find memories connected to a specific memory ID101- `link_memories` — create explicit relationships (references, extends, contradicts, related)102- `memory_stats` — view total counts, category breakdown, decay stats103104## Security & Defence105106Every memory write passes through a 6-layer defence pipeline:1071081. Input Sanitisation — strips control characters and null bytes1092. Pattern Detection — regex matching for known injection patterns1103. Semantic Analysis — embedding similarity to attack corpus1114. Structural Validation — JSON/format integrity checks1125. Behavioural Scoring — anomaly detection over time1136. Credential Leak Detection — blocks API keys, tokens, private keys (25+ patterns, 11 providers)114115### Iron Dome116117Behavioural security layer that controls what agents can do, not just what they remember:118119- `iron_dome_activate` — activate with a profile: `school`, `enterprise`, `personal`, or `paranoid`120- `iron_dome_status` — check active profile, trusted channels, and approval rules121- `iron_dome_check` — gate an action (e.g., send_email, delete_file) before execution122- `iron_dome_scan` — scan text for prompt injection patterns123124Profiles control action gates (what actions require approval), channel trust (which instruction sources are trusted), and approval rules.125126### Security Tools127128- `audit_query` — query the forensic audit log of all memory operations129- `defence_stats` — view defence system statistics (blocks, allows, quarantines)130- `quarantine_review` — review and manage quarantined memories (list, approve, reject)131- `scan_memories` — scan existing memories for signs of poisoning132- `scan_skill` — scan an instruction file for hidden threats (SKILL.md, .cursorrules, CLAUDE.md, etc.)133134## Universal Memory Bridge135136ShieldCortex can act as a security layer for any memory backend — not just its own. Use `ShieldCortexGuardedMemoryBridge` to wrap any memory system with the full defence pipeline:137138```javascript139import { ShieldCortexGuardedMemoryBridge, MarkdownMemoryBackend } from 'shieldcortex';140141const bridge = new ShieldCortexGuardedMemoryBridge({142 backend: new MarkdownMemoryBackend('~/.my-memories/'),143});144145// All writes pass through the 6-layer defence pipeline146await bridge.write({ title: 'Decision', content: 'Use PostgreSQL' });147```148149Built-in backends: `MarkdownMemoryBackend`, `OpenClawMarkdownBackend`. Implement the backend interface for custom storage.150151## Project Scoping152153- `set_project` — switch active project context154- `get_project` — show current project scope155- Use `project: "*"` for global/cross-project memories156157## Best Practices1581591. **Remember immediately** — call `remember` right after a decision is made or a bug is fixed, not at the end of the session1602. **Use categories** — architecture, pattern, preference, error, context, learning1613. **Set importance** — mark critical decisions as `importance: "critical"` so they resist decay1624. **Recall at session start** — always call `get_context` or `start_session` first1635. **End sessions properly** — call `end_session` with a summary to trigger consolidation1646. **Review contradictions** — periodically run `detect_contradictions` to catch conflicting information1657. **Scope by project** — memories are automatically scoped to the current project directory166167## Troubleshooting168169**Memory not found in recall:**170- Try `mode: "search"` with different query phrasing171- Check `set_project` — you may be searching the wrong project scope172- Use `includeDecayed: true` to find memories that have faded173174**Memory blocked by firewall:**175- The defence pipeline detected a potential threat (injection, credential leak)176- Check `audit_query` for the specific block reason177- Review with `quarantine_review` if it was a false positive178- Avoid including literal API keys or tokens in memory content179180**Consolidation removing memories:**181- Run `consolidate` with `dryRun: true` first to preview182- Mark important memories as `importance: "critical"` to prevent decay183- Access memories regularly — `recall` boosts activation and prevents decay184185## OpenClaw Auto-Memory186187When using the OpenClaw hook, auto-memory extraction is off by default. Enable it to automatically extract memories from session output:188189```bash190npx shieldcortex config --openclaw-auto-memory191```192193When enabled, the system deduplicates against recent memories to avoid storing duplicates. Configure with:194195- `openclawAutoMemory` — enable/disable (default: false)196- `openclawAutoMemoryDedupe` — deduplicate against existing memories (default: true)197- `openclawAutoMemoryNoveltyThreshold` — similarity threshold for deduplication (default: 0.88)198- `openclawAutoMemoryMaxRecent` — number of recent memories to check (default: 300)199200## Links201202- npm: https://www.npmjs.com/package/shieldcortex203- PyPI: https://pypi.org/project/shieldcortex204- GitHub: https://github.com/Drakon-Systems-Ltd/ShieldCortex205- Website: https://shieldcortex.ai