Structured thinking framework for LLMs — multi-layer levers for better reasoning
Project description
thinking-lever 🧠🔧
Structured thinking framework for LLMs — a multi-layer architecture that enhances model reasoning through pure-rule preprocessing.
pip install thinking-lever
Why?
LLMs think better when you give them a framework. But most "reasoning" systems are proprietary, model-specific, or over-engineered.
thinking-lever is zero-dependency, model-agnostic, and runs in <5ms. You can drop it into any LLM stack and immediately get better-structured reasoning.
The 5 Levers
| Lever | Layer | What it does |
|---|---|---|
| L0 ContextLever | Input restructuring | Extracts entities, actions, constraints; scans directories; walks import graphs |
| L1 ThinkingLever | Intent routing | Detects task type (diagnose/design/optimize/predict/execute) and recommends thinking methods |
| L2 KnowledgeLever | External knowledge | Retrieves relevant facts from your knowledge base |
| L3 ExecutionLever | Verification | Runs code checks, fact validation, config validation |
| L4 ReflectionLever | Self-check | Iterative quality refinement |
Quick Start
CLI
# Classify a task
thinking-lever classify "Why is my API returning 500 errors?"
# Scan context
thinking-lever scan "Audit the security of ~/myproject/"
# Verify a result
thinking-lever verify "Check syntax" "$(cat myfile.py)"
# Walk dependencies
thinking-lever deps ~/myproject/ --depth 3
# Problem mapping
thinking-lever map "Design a microservice architecture"
# Self-check
thinking-lever reflect "Here is my answer..."
Python API
from thinking_lever import classify_task, format_injection, context_scan
# L1: Classify
result = classify_task("Rewrite this module to be more efficient")
print(result["pattern"]) # "optimize"
print(result["method"]) # "constraint_analysis"
# L0: Scan
ctx = context_scan("Fix the bug in src/handler.py")
print(ctx["entities"]) # ["file:src/handler.py", ...]
print(ctx["actions"]) # ["repair"]
print(ctx["risk_zones"]) # ["Modification: backup first"]
# Inject into prompt
injection = format_injection(result)
enhanced_prompt = f"{injection}\n\n{user_message}"
Middleware Integration
from thinking_lever import LeverMiddleware
middleware = LeverMiddleware(
enable_l0=True,
enable_l1=True,
)
# In your kernel's pre_process:
def pre_process(user_message):
enriched = middleware.process(user_message)
return enriched # Use this as your LLM input
A/B Test Results
In a real-world code audit scenario across 4 tasks:
| Metric | Without | With Lever | Improvement |
|---|---|---|---|
| Response time | baseline | 4.7x faster | ⚡ structured prep avoids back-and-forth |
| Tool utilization | 0% | 91% | LLM uses available tools correctly |
| Qualitative | verbose, unfocused | concise, precise | focused on what matters |
Design Philosophy
- Pure rules, no LLM overhead — every lever is <5ms
- Zero external dependencies — no numpy, no torch, no network calls
- Model-agnostic — works with any LLM (GPT, Claude, open-source, local)
- Incremental adoption — use 1 lever or all 5, middleware adapter or direct call
- Framework-independent — use with LangChain, custom kernels, or CLI
Requirements
- Python 3.8+
License
MIT
Project details
Release history Release notifications | RSS feed
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 thinking_lever-0.1.0.tar.gz.
File metadata
- Download URL: thinking_lever-0.1.0.tar.gz
- Upload date:
- Size: 24.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2196753291806577cc7a2051dcbffafdb5392337ad68e26c95e8a64895c95de4
|
|
| MD5 |
c21f9c818586c57997c334b61e63cfc1
|
|
| BLAKE2b-256 |
ee5f7b971dacad31736695362aeb2844e720969a3878ca809e38ce7daae805a8
|
File details
Details for the file thinking_lever-0.1.0-py3-none-any.whl.
File metadata
- Download URL: thinking_lever-0.1.0-py3-none-any.whl
- Upload date:
- Size: 23.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a8184d4900e8ab8b86577cfd4bc3b944c1e3f3cd14c59382273ecc9114187a20
|
|
| MD5 |
be23abf6130f58e10a29a45b5683a577
|
|
| BLAKE2b-256 |
b28f989a2b33c623176832fc13db5d74592526fc62bdaee1d2523bacc1181080
|