Correlation Relevance Plugin
Agent-agnostic rule-based context enrichment engine for Hermes Agent.
What it does: When you execute a task, correlation rules automatically surface related memories (must_also_fetch) before task execution — so decisions are made with full context rather than in isolation.
Reference upstream: ether-btc/openclaw-correlation-plugin (MIT, v2.1.0) — TypeScript plugin for OpenClaw.
Quick Start
# Install
pip install correlation-lib
# Create rules file at ~/.hermes/correlation-rules.json
[
{
"id": "cr-001",
"trigger_context": "config-change",
"trigger_keywords": ["config", "setting", "modify"],
"must_also_fetch": ["backup-location", "rollback-instructions"],
"relationship_type": "constrains",
"confidence": 0.95
}
]
from correlation_lib import create_engine
# With Hermes Agent (optional — requires hermes-agent package):
try:
from correlation_lib_adapters.hermes import HermesRecallBackend, HermesContextBackend
recall = HermesRecallBackend()
context = HermesContextBackend()
except ImportError:
# Standalone mode: provide your own backends
# (see examples/demo.py for a MockBackend implementation)
raise ImportError(
"hermes-agent not installed. Install it, or provide your own "
"RecallBackend/ContextBackend implementations."
)
engine = create_engine(
"rules.json",
recall_backend=recall,
context_backend=context,
)
# In your agent loop:
if engine.enricher.is_new_task(user_message):
result = engine.enricher.on_task_start(user_message)
print(context.format_injected())
Architecture
correlation-lib/ # Pure Python, zero framework deps
├── engine.py # Thin facade/factory
├── rules.py # Schema + validation
├── matcher.py # Keyword/context/confidence matching
├── lifecycle.py # State machine (proposal → testing → validated → promoted → retired)
├── enricher.py # Orchestrates match→recall→inject
├── tracker.py # EffectivenessTracker (self-improvement)
├── interfaces.py # Protocol definitions
├── diagnostics.py # Runtime diagnostics
└── rule_provider.py # File-based rule loader (hot-reload optional)
correlation_lib_adapters/
└── hermes/ # Hermes Agent adapter
├── adapter.py # CorrelationMemoryProvider
└── backends.py # HermesRecallBackend, HermesContextBackend
Decisions
| Decision | Choice | Rationale |
|---|---|---|
| Q1 — Self-improvement | A: Fully automated | Auto-promote and auto-demote based on firing_count + effectiveness_ratio |
| Q2 — Trigger point | B: on_task_start | New task detection heuristic; prefetch as fallback for high-confidence rules |
| Q3 — Hot-reload | C: Configurable | watch_enabled: false default; power users can enable |
| Q4 — Effectiveness store | A: SQLite standalone | ~/.hermes/correlation-effectiveness.db — independent of Mnemosyne |
Lifecycle States
proposal → testing → validated → promoted → retired
↑__________↓___________↓____________↓
auto-demote on low effectiveness
- Auto-promote:
firing_count >= 30 AND effectiveness_ratio >= 0.8 - Auto-demote:
firing_count >= 10 AND effectiveness_ratio < 0.3 - Hard demote:
firing_count >= 90 AND effectiveness_ratio < 0.20→ back to PROPOSAL
Configuration
In ~/.hermes/config.yaml:
memory:
provider: correlation
correlation:
rule_file: ~/.hermes/correlation-rules.json
watch_enabled: false
db_path: ~/.hermes/correlation-effectiveness.db
Rule Schema
{
"id": "cr-001",
"trigger_context": "config-change",
"trigger_keywords": ["config", "setting", "modify"],
"must_also_fetch": ["backup-location", "rollback-instructions"],
"relationship_type": "constrains",
"confidence": 0.95,
"lifecycle": { "state": "promoted" },
"learned_from": "config-misconfiguration-leads-to-service-outage"
}
| Field | Type | Description |
|---|---|---|
id |
string | Unique rule identifier |
trigger_context |
string | Semantic domain (e.g., config-change, error-debugging) |
trigger_keywords |
string[] | Keywords that activate this rule |
must_also_fetch |
string[] | Context paths to retrieve when rule fires |
relationship_type |
string | constrains, supports, diagnosed_by, etc. |
confidence |
float | 0.0–1.0 |
lifecycle.state |
string | proposal, testing, validated, promoted, retired |
Development
pip install -e ".[dev]"
python -m pytest tests/ -v
License
MIT
Metadata
Release files for correlation-lib 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| correlation_lib-0.4.0.tar.gz | 28.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| correlation_lib-0.4.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 59.7 kB
Release files / correlation_lib-0.4.0.tar.gz
| Download URL | correlation_lib-0.4.0.tar.gz |
|---|---|
| Size | 28.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
07ba00326a02d06729e6b52a38b334f7c4cf36d2a06d903835191fa4fcc03a0a
|
|
BLAKE2b-256 checksum How to use checksums |
7348a267bab9611361d586e844d3f8166e8897dfd6c0067b70008366817cba65
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.2
|
Release files / correlation_lib-0.4.0-py3-none-any.whl
| Download URL | correlation_lib-0.4.0-py3-none-any.whl |
|---|---|
| Size | 31.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ec41a9143df67f060784bcda92e3b824c7c6a35957392b075dc6f1ccc96ad2ad
|
|
BLAKE2b-256 checksum How to use checksums |
520b901b7e2ad8997fcaec81eb3ef1f35159677a0ead3581494eb1ff747c4a66
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.2
|