A lightweight Python library that allows any LLM agent to self-improve through feedback, without retraining models.
Project description
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
All of this happens without any model retraining - just by enhancing prompts with contextual feedback.
✨ 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 dead_simple_self_learning
Dependencies
-
Required:
- Python 3.7+
- numpy >=1.20.0
- sentence-transformers >=2.2.0
-
Optional:
- openai >=1.0.0 (for OpenAI embeddings and LLM feedback selection)
- langchain, agno (for specific integration examples)
Install with optional OpenAI dependency:
pip install "dead_simple_self_learning[openai]"
Install for development:
pip install "dead_simple_self_learning[dev]"
🚀 Quick Start
from openai import OpenAI
from dead_simple_self_learning import SelfLearner
# Initialize OpenAI client (you need your own API key)
client = OpenAI(api_key="YOUR_OPENAI_API_KEY")
# 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 = generate_text(base_prompt, 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
enhanced_prompt = learner.apply_feedback(task, base_prompt)
enhanced = generate_text(enhanced_prompt, task)
print("######################Improved output:", enhanced)
📊 Package Structure
dead_simple_self_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 dead_simple_self_learning import Embedder
# Use a HuggingFace model (no API key required)
embedder = Embedder(model_name="miniLM")
# Use OpenAI (requires API key in env var OPENAI_API_KEY)
embedder = Embedder(model_name="openai")
# Generate an embedding
vector = embedder.embed("your text here")
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dead_simple_self_learning-1.1.4.tar.gz.
File metadata
- Download URL: dead_simple_self_learning-1.1.4.tar.gz
- Upload date:
- Size: 21.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
06a66dfe8e4a826802f74d94fa9dc049dee256f58f39679ba3854297a71c47e7
|
|
| MD5 |
b50de3bce8bbfeec7eed2dc45bbeef0e
|
|
| BLAKE2b-256 |
59cb923d450a7b01b9510e06a45466ef7981b3209eae9bdbce2934792eb1ae3b
|
File details
Details for the file dead_simple_self_learning-1.1.4-py3-none-any.whl.
File metadata
- Download URL: dead_simple_self_learning-1.1.4-py3-none-any.whl
- Upload date:
- Size: 20.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff5204a6c908c04c366d9a80b6490b67ceb889279912e8f716dcc67c1c6c6745
|
|
| MD5 |
aa60cc3e4c111dee3704c93a50d1e2a3
|
|
| BLAKE2b-256 |
fc2bcfa991ce04cd6c59c9b067f9ed3ecf1c423bb7d56de1c7cf4c6e9df34da5
|