A lightweight Python library that allows any LLM agent to self-improve through feedback, without retraining models.
Last updated Jul 13, 2026
62
Stars
8
Forks
0
Issues
0
Stars/day
Attention Score
16
Topics
Language breakdown
Python 100.0%
โธ Files
click to expand
README
Dead Simple Self-Learning
A lightweight Python library that allows any LLM agent to self-improve through feedback, without retraining models.
๐ Overview
Problem: LLM agents struggle to consistently learn from user feedback without requiring costly model retraining or complex infrastructure.
Solution: This library provides a simple system for capturing, storing, and reusing feedback for LLM tasks. It works by:
- Collecting feedback on LLM outputs
- Storing this feedback with embeddings of the original task
- Retrieving relevant feedback for similar future tasks (feedback selection layer: only openai right now)
- Enhancing prompts with the feedback to improve results
โจ Features
- Simple API: Just a few methods to enhance prompts and save feedback
- Multiple Embedding Models: Support for OpenAI and HuggingFace models (MiniLM, BGE-small)
- Local-First: Uses JSON files for storage with no external DB requirements
- Smart Feedback Selection: Uses OpenAI to choose the most relevant feedback for a task
- Async Support: Both synchronous and asynchronous APIs for better performance
- Customizable: Configurable thresholds, formatters, and memory handling
- Zero Infrastructure: Works out of the box with minimal setup
- Framework Agnostic: Works with any LLM provider (OpenAI, Anthropic, etc.)
- Integration Examples: Ready-to-use examples with LangChain, Agno, and more
๐ง Installation
You can install the package via pip:
pip install deadsimpleself_learning
Dependencies
- Required:
- Optional:
Install with optional OpenAI dependency:
pip install "deadsimpleself_learning[openai]"
Install for development:
pip install "deadsimpleself_learning[dev]"
๐ Quick Start
from openai import OpenAI
from deadsimpleself_learning import SelfLearner
Initialize OpenAI client (you need your own API key)
client = OpenAI(apikey="YOUROPENAIAPIKEY")
Initialize a self-learner (no API key needed for miniLM)
learner = SelfLearner(embedding_model="miniLM")
Define our task and original prompt
task = "Write a product description for a smartphone"
base_prompt = "You are a copywriter."
Generate text without feedback
def generate_text(prompt, task):
return client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "system", "content": prompt}, {"role": "user", "content": task}]
).choices[0].message.content
Generate original text
original = generatetext(baseprompt, task)
print("#######################Original output:", original)
Save feedback for the task
feedback = "Keep it under 100 words and focus on benefits not features"
learner.save_feedback(task, feedback)
Apply feedback to the prompt
enhancedprompt = learner.applyfeedback(task, base_prompt)
enhanced = generatetext(enhancedprompt, task)
print("######################Improved output:", enhanced)
๐ Package Structure
deadsimpleself_learning/
โโโ init.py # Package exports
โโโ main.py # CLI entrypoint
โโโ embedder.py # Handles embedding generation
โโโ memory.py # Manages storage and retrieval
โโโ learner.py # Core functionality
๐ Detailed Guide
Core Components
Embedder
The Embedder class generates vector embeddings for tasks:
from deadsimpleself_learning import Embedder
Use a HuggingFace model (no API key required)
embedder = Embedder(model_name="miniLM")
Use OpenAI (requires API key in env var OPENAIAPIKEY)
embedder = Embedder(model_name="openai")
Generate an embedding
vector = embedder.embed("your text here")๐ More in this category