Skip to main content

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

  1. Pure rules, no LLM overhead — every lever is <5ms
  2. Zero external dependencies — no numpy, no torch, no network calls
  3. Model-agnostic — works with any LLM (GPT, Claude, open-source, local)
  4. Incremental adoption — use 1 lever or all 5, middleware adapter or direct call
  5. Framework-independent — use with LangChain, custom kernels, or CLI

Requirements

  • Python 3.8+

License

MIT

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

thinking_lever-0.1.0.tar.gz (24.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

thinking_lever-0.1.0-py3-none-any.whl (23.9 kB view details)

Uploaded Python 3

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

Hashes for thinking_lever-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2196753291806577cc7a2051dcbffafdb5392337ad68e26c95e8a64895c95de4
MD5 c21f9c818586c57997c334b61e63cfc1
BLAKE2b-256 ee5f7b971dacad31736695362aeb2844e720969a3878ca809e38ce7daae805a8

See more details on using hashes here.

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

Hashes for thinking_lever-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a8184d4900e8ab8b86577cfd4bc3b944c1e3f3cd14c59382273ecc9114187a20
MD5 be23abf6130f58e10a29a45b5683a577
BLAKE2b-256 b28f989a2b33c623176832fc13db5d74592526fc62bdaee1d2523bacc1181080

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page