ContextStabilizer

Context Stabilizer

Typer_Body / ContextStabilizer
Plugin201 downloadsCommand1Event Listener1utilityentertainmentproductivityai

Context Stabilizer - Validates and manages conversation context using an audit model

Context Stabilizer Plugin

A LangBot plugin that validates and manages conversation context using an audit model.

Plugin Group

LangBot version

Python version

Features

  • Context Auditing: Uses a secondary LLM model (Model B) to audit conversation context
  • Steganography Detection: Detects hidden characters and zero-width characters that may indicate injection attacks
  • Context Compression: Automatically compresses long context while preserving key information
  • Prompt Injection Protection: Injects original system prompt reminder after compression
  • Adaptive Audit Frequency: Automatically adjusts audit frequency based on audit results
  • Configurable Frequency: Set how often to audit (every N conversation rounds)
  • Timeout Protection: Prevents auditing from blocking the main conversation flow

Installation

  1. Download the plugin
  2. Place it in the LangBot plugins directory
  3. Configure the plugin in the LangBot web interface

Configuration

Audit Model Settings

ConfigDescriptionDefault
audit_model_uuidThe LLM model used for auditingRequired
audit_system_promptSystem prompt for the audit modelBuilt-in

Frequency Settings

ConfigDescriptionDefault
audit_frequencyRounds between audits3
enable_adaptive_frequencyAuto-adjust frequency based on resultsfalse
frequency_increase_stepFrequency increase step on failure1
frequency_recovery_thresholdPasses needed before decreasing frequency3
min_audit_frequencyMinimum interval (highest frequency)1

Timeout Settings

ConfigDescriptionDefault
audit_timeout_secondsAudit timeout in seconds10
timeout_actionAction on timeout (remove_chunk/compress_all)remove_chunk

Compression Settings

ConfigDescriptionDefault
max_context_lengthMax messages before compression50
compress_target_lengthTarget messages after compression10
compression_model_uuidModel for compression (empty = use audit model)-
compression_promptPrompt for context summarizationBuilt-in
enable_prompt_injectionInject original prompt after compressiontrue

Steganography Detection

ConfigDescriptionDefault
enable_steganography_detectionEnable hidden character detectiontrue
steganography_patternsRegex patterns for detectionBuilt-in

Advanced Settings

ConfigDescriptionDefault
chunk_sizeMessages per audit chunk5
enable_loggingEnable detailed loggingfalse

Commands

CommandDescription
!ctxstab statusView current session audit status
!ctxstab auditForce audit on next message
!ctxstab compressForce compression on next message
!ctxstab resetReset audit counter
!ctxstab configView current configuration

How It Works

  1. Event Listening: Listens to PromptPreProcessing event to get conversation context
  2. Frequency Check: Decides whether to audit based on configured frequency
  3. Steganography Detection: Detects zero-width and hidden characters in context
  4. Context Splitting: Splits context into chunks for auditing
  5. Model Auditing: Uses audit model to check if chunks comply with original settings
  6. Result Processing: Compresses or removes problematic context based on audit results
  7. Adaptive Frequency: Adjusts audit frequency based on pass/fail results (if enabled)

License

MIT

LangContextStabilizer

Use Context Stabilizer in Feishu/Lark bots, DingTalk bots, WeCom bots, WeChat bots, QQ bots, Slack bots, Discord bots, Telegram bots, LINE Bots, and Matrix Bots.

Host your bot on LangBot Cloud and connect this extension to the collaboration platforms your team already uses.

Open LangBot Cloud

Comments