Implementation:42 evey Hermes plugins apply learnings
| Knowledge Sources | |
|---|---|
| Domains | Experiential_Learning, Knowledge_Retrieval, Relevance_Scoring |
| Last Updated | 2026-10-29 00:00 GMT |
Overview
Concrete tool for retrieving past experiential lessons relevant to an upcoming task, using keyword overlap, model/tool matching, recency, and quality-extreme scoring.
Description
The apply_learnings handler (apply_handler) searches past lessons stored in ~/.hermes/workspace/orchestrator/learnings.jsonl for entries relevant to a given task description. It loads the most recent SEARCH_WINDOW = 200 learnings, tokenizes the task description (removing stopwords), and scores each learning using _relevance_score:
The relevance score combines four signals:
- Keyword overlap:
(matches / total_query_words) × 10— how many query words appear in the learning's text fields (task, what_worked, what_failed, do_differently, tags). - Model/tool match: +5 if the specified model_or_tool matches the learning's model_or_tool (case-insensitive).
- Recency bonus: +3 if <1 day old, +2 if <7 days, +1 if <30 days.
- Quality extremes: +2 if quality_score ≥9 or ≤2, +1 if ≥8 or ≤3 (very good or very bad results are more informative).
Results are sorted by relevance score (descending), capped at max_results (default 5, max 20), and include an advice field drawn from the learning's do_differently, what_failed, or what_worked field.
The companion learn_from_interaction tool (learn_handler) stores lessons: each entry includes task, model_or_tool, quality_score (1-10), what_worked, what_failed, do_differently, and tags. The JSONL file is pruned to MAX_LEARNINGS = 500 entries.
Usage
Call apply_learnings before starting a task to check for relevant past lessons. Call learn_from_interaction after completing a task to record what was learned. Registered on the evey_learner toolset.
Code Reference
Source Location
- Repository: hermes-plugins
- File: evey-learner/__init__.py
- Lines: L19-322 (_read_learnings L108-126, _append_learning L129-143, _relevance_score L146-188, learn_handler L191-228, apply_handler L231-307, schemas L29-100)
Signature
def apply_handler(args: dict, **kwargs) -> str:
"""
Args:
args: {
task_description: str (required) - upcoming task,
model_or_tool: str - planned model/tool (optional),
max_results: number - max results (default 5, capped 20)
}
Returns:
JSON: {status: "found"/"no_learnings"/"no_matches",
total_learnings, matches, applicable_lessons: list[{relevance_score, task, model_or_tool, quality_score, date, advice}],
advice_summary: str}
"""
def learn_handler(args: dict, **kwargs) -> str:
"""
Args:
args: {
task: str (required), quality_score: number (required, 1-10),
model_or_tool: str, what_worked: str, what_failed: str,
do_differently: str, tags: list[str]
}
Returns:
JSON: {status: "learned", quality_score, task_preview, total_learnings}
"""
def _relevance_score(learning: dict, query_words: list[str], model_or_tool: str = None) -> float:
"""Score how relevant a learning is to the current task. Higher = more relevant."""
Import
from evey_learner import apply_handler, learn_handler
# Or accessed via Hermes tool calls: apply_learnings, learn_from_interaction
I/O Contract
Inputs (apply_learnings)
| Name | Type | Required | Description |
|---|---|---|---|
| task_description | str | Yes | Description of the upcoming task |
| model_or_tool | str | No | Model or tool planned for the task |
| max_results | number | No | Max learnings to return (default 5, capped 20) |
Outputs (apply_learnings)
| Name | Type | Description |
|---|---|---|
| status | str | "found", "no_learnings", "no_matches", or "error"
|
| total_learnings | int | Total learnings in search window |
| matches | int | Number of matching learnings returned |
| applicable_lessons | list[dict] | Each: {relevance_score, task, model_or_tool, quality_score, date, advice}
|
| advice_summary | str | Concatenated advice lines for prompt injection |
Usage Examples
Apply Learnings Before a Task
result = tool_call("apply_learnings", {
"task_description": "Research the latest vector databases for RAG",
"model_or_tool": "claude-sonnet-4-20250514",
"max_results": 3
})
# {"status":"found","total_learnings":45,"matches":3,
# "applicable_lessons":[
# {"relevance_score":12.5,"task":"Research embedding models",
# "model_or_tool":"claude-sonnet-4-20250514","quality_score":9,"date":"2026-10-28",
# "advice":"Use web_search first, then delegate for synthesis"},
# ...],
# "advice_summary":"- Use web_search first, then delegate for synthesis (from: Research embedding..., q=9)"}
Learn From an Interaction
tool_call("learn_from_interaction", {
"task": "Generated Python function for CSV parsing",
"model_or_tool": "claude-sonnet-4-20250514",
"quality_score": 8,
"what_worked": "Clear code with error handling",
"what_failed": "Missed edge case with empty files",
"do_differently": "Always test with empty input files",
"tags": ["code", "python", "csv"]
})
# {"status":"learned","quality_score":8,"task_preview":"Generated Python...",
# "total_learnings":46}