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
# Install with dev dependencies (ruff + pytest)
pip install -e ".[dev]"
# Run tests
python -m pytest tests/ -v
# Lint
ruff check .
# Install with Hermes support (for live integration)
pip install -e ".[hermes]"
Deployment — Hermes Agent
Deploy this as a Hermes memory provider plugin:
# Link the plugin into Hermes
ln -sf /path/to/correlation-relevance-plugin/correlation_lib_adapters/hermes \
~/.hermes/plugins/correlation
# Add to ~/.hermes/config.yaml:
# memory:
# provider: correlation
# correlation:
# rule_file: ~/.hermes/correlation-rules.json
# watch_enabled: false
# db_path: ~/.hermes/correlation-effectiveness.db
Restart Hermes Agent — the correlation engine will prefetch related context automatically on matched tasks.
Migrating from OpenClaw
See UPSTREAM.md for the OpenClaw→Hermes porting guide.
License
MIT
Metadata
Release files for correlation-lib 0.3.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.3.0.tar.gz | 22.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| correlation_lib-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 51.8 kB
Release files / correlation_lib-0.3.0.tar.gz
| Download URL | correlation_lib-0.3.0.tar.gz |
|---|---|
| Size | 22.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3b9ab4c9fc1783d00a390f357063039dd05e1c5aac6faf1927d23207e654ad1e
|
|
BLAKE2b-256 checksum How to use checksums |
d2c9a8896d738728ded7687e492f8786f23d99f886eb9937f3d5c0bd76af86b3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.2
|
Release files / correlation_lib-0.3.0-py3-none-any.whl
| Download URL | correlation_lib-0.3.0-py3-none-any.whl |
|---|---|
| Size | 29.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
04b0606bd652fb161006d7260aeb9a7b10eb920b8c1d34d270d5f2af5e932c0e
|
|
BLAKE2b-256 checksum How to use checksums |
e912a2e565ad3de02c8eaa76c92405bfd9a901014a80cb53642e35ba516a8a22
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.2
|