Self-improving metacognitive recipe tools that learn from execution feedback and extract patterns to provide recommendations
The Learner Tools are 4 specialized learner engines that extract patterns from recipe execution feedback, enabling self-improving metacognitive recipes. Each learner logs executions and feedback, then learns patterns to provide actionable recommendations.
Learn which decisions work best in specific contexts.
When to use: When your recipe makes strategic choices that affect outcomes
Example:
from amplifier.learning.decision_historian import DecisionHistorian
dh = DecisionHistorian()
dh.log_execution(
execution_id="task_001",
context={"difficulty": "hard", "time_available": "30 min"},
decision={"approach": "step_by_step"},
outcome={"success_rate": 0.95}
)
Learn personal writing voice and preferences from user edits.
When to use: When generating text that users edit to match their style
Example:
from amplifier.learning.style_learner import StyleLearner
sl = StyleLearner()
sl.log_execution(
execution_id="email_001",
input_prompt="Professional email",
generated_output="I am writing to inform you..."
)
sl.log_edits(
execution_id="email_001",
edits=[{"original": "I am", "replacement": "I'm", "reason": "casual"}]
)
Learn pipeline performance and identify optimization opportunities.
When to use: When optimizing multi-stage recipe pipelines
Example:
from amplifier.learning.meta_recipe_tuner import MetaRecipeTuner
mrt = MetaRecipeTuner()
mrt.log_stage(
recipe_id="blog_writer",
run_id="run_001",
stage_name="research",
duration_sec=12.5,
quality_metric=0.92
)
Learn information extraction and prioritization rules.
When to use: When extracting relevant sections from source material
Example:
from amplifier.learning.knowledge_compressor import KnowledgeCompressor
kc = KnowledgeCompressor()
kc.log_extraction(
extraction_id="extract_001",
source_type="research_paper",
input_tokens=2500,
sections=[
{"name": "abstract", "tokens": 200},
{"name": "results", "tokens": 1000}
]
)
kc.log_feedback(
extraction_id="extract_001",
kept_sections=["abstract", "results"],
removed_sections=["methods"],
reason="Focus on findings"
)
All learners follow the same pattern:
1. Initialize learner
learner = StyleLearner()
2. Log executions
learner.log_execution(...)
3. Log feedback
learner.log_edits(...)
4. Learn patterns
result = learner.learn()
5. Get recommendations
recs = learner.get_recommendations()
6. Use recommendations to improve
Apply learned patterns in next iteration
Each learner has minimum data requirements before patterns emerge:
| Learner | Min Samples | Min Feedback |
|---|---|---|
| Decision Historian | 3 | 2 contexts |
| Style Learner | 3 | 5 edits |
| Meta-Recipe Tuner | 5 | 2 stages |
| Knowledge Compressor | 5 | 3 sections |
class SelfImprovingRecipe:
def __init__(self):
self.decision_historian = DecisionHistorian()
self.style_learner = StyleLearner()
self.meta_recipe_tuner = MetaRecipeTuner()
self.knowledge_compressor = KnowledgeCompressor()
def execute(self, input_data):
# Log decision
self.decision_historian.log_execution(...)
# Generate and log style
output = self.generate(input_data)
self.style_learner.log_execution(...)
# Track performance
self.meta_recipe_tuner.log_stage(...)
return output
def collect_feedback(self, feedback_data):
self.style_learner.log_edits(...)
self.knowledge_compressor.log_feedback(...)
def improve(self):
# Learn from all sources
self.decision_historian.learn()
self.style_learner.learn()
self.meta_recipe_tuner.learn()
self.knowledge_compressor.learn()
# Get recommendations
return {
"decisions": self.decision_historian.get_recommendations(),
"style": self.style_learner.get_recommendations(),
"performance": self.meta_recipe_tuner.get_recommendations(),
"extraction": self.knowledge_compressor.get_recommendations()
}
β File-based persistence: JSONL for append-only logs, JSON for recommendations β Cloud-sync safe: Exponential backoff retry for OneDrive/Dropbox delays β Probabilistic confidence: 0-1 scale confidence metrics β Minimum thresholds: Prevents false patterns from sparse data β Full type hints: 100% type coverage β Comprehensive validation: Strict input validation β Production-ready: 44 tests, 100% passing
All learner data stored in:
.data/learning/
βββ decision_historian/
β βββ executions.jsonl
β βββ feedback.jsonl
β βββ recommendations.json
βββ style_learner/
β βββ executions.jsonl
β βββ feedback.jsonl
β βββ style_model.json
βββ meta_recipe_tuner/
β βββ executions.jsonl
β βββ tuning_model.json
βββ knowledge_compressor/
βββ executions.jsonl
βββ feedback.jsonl
βββ compression_model.json
# Install from iMehr Marketplace
/skill learner-tools
# Or import directly
from amplifier.learning.decision_historian import DecisionHistorian
from amplifier.learning.style_learner import StyleLearner
from amplifier.learning.meta_recipe_tuner import MetaRecipeTuner
from amplifier.learning.knowledge_compressor import KnowledgeCompressor
learn()learn()learn()execution_id="email_2024_10_25_001" not "x"All learners validate inputs and raise helpful errors:
# Raises ValueError
sl.log_execution(execution_id="", ...) # Empty ID
# Correct
sl.log_execution(execution_id="email_001", ...)
Use companion slash commands for interactive access:
/learner-guide - Interactive tutorial/learner-log - Log execution data/learner-analyze - Analyze patterns/learner-status - Check status/learner-clear - Reset data/learner-export - Backup/exportdocs/LEARNER_TOOLS_GUIDE.mddocs/LEARNER_QUICK_REFERENCE.mdexamples/learner_integration_example.pyQ: "Need more data" A: Learners have minimum samples. Log more executions and try again.
Q: "Confidence too low" A: Confidence < 0.7 means unreliable. Log more varied data.
Q: "No patterns found" A: Not enough variation in feedback. Try different approaches.
Version: 1.0.0 License: MIT Repository: https://github.com/imehr/amplifier Status: Production Ready