Skip to main content

Self-learning LLM call library. Every call learns. Every call improves.

Project description

netanel-core

The self-learning LLM call. Every call learns. Every call improves.

CI Python 3.11+ License: MIT

A Python library that wraps any LLM with file-based memory and automatic quality improvement. No database required.

from netanel_core import LearningLLM

llm = LearningLLM(namespace="my-app")
result = llm.call("Write a function to validate emails")

print(result.response)  # The LLM's output
print(result.score)      # Quality score (0.0-1.0)
print(result.usage)      # Token usage for cost tracking

✨ Features

  • 🧠 Self-Learning - Extracts patterns from every call, builds better context over time
  • 📊 Quality-First - Auto-evaluation + retry loop, only stores high-quality outputs
  • 💾 File-Based Memory - No database, human-readable .md files, git-trackable
  • 🔄 Prompt Evolution - Auto-rewrites prompts based on learnings
  • 🎯 Bounded Safety - Max retries, tokens, iterations (NASA-grade)
  • 🤖 DeepAgent Support - Complex reasoning with LangGraph agents
  • 💰 Cost Tracking - Token usage for all calls

🚀 Quick Start

pip install netanel-core
from netanel_core import LearningLLM

llm = LearningLLM(namespace="my-app")
result = llm.call("Explain quantum computing simply")

if result.passed:
    print(result.response)
    print(f"Quality: {result.score:.2f}, Tokens: {result.usage['total_tokens']}")

📖 How It Works

Every llm.call() executes:

  1. RETRIEVE - Load memories from namespace
  2. BUILD - Create context (role + memories + task)
  3. CALL - Invoke LLM
  4. EVALUATE - Score quality (gpt-4o-mini + main model)
  5. RETRY - If score < threshold, retry with feedback
  6. EXTRACT - Extract patterns from successful responses
  7. STORE - Save to memories/{namespace}/patterns/
  8. EVOLVE - Trigger prompt improvements
  9. RETURN - Result with response + metadata

💡 Usage Examples

Custom Model

from langchain_openai import ChatOpenAI

model = ChatOpenAI(model="gpt-4", temperature=0.7)
llm = LearningLLM(namespace="gpt4-app", model=model)

DeepAgent Mode

result = llm.call(
    "Research AI papers and summarize trends",
    use_agent=True  # Multi-step reasoning
)
print(f"Steps: {result.agent_steps}")

Cost Tracking

total = sum(llm.call(task).usage['total_tokens'] for task in tasks)
cost = (total / 1_000_000) * 0.375  # gpt-4o-mini avg
print(f"Cost: ${cost:.4f}")

🎯 Configuration

from netanel_core import Config

config = Config(
    namespace="my-app",
    quality_threshold=0.8,
    max_retries=3,
    memories_dir="./memories",
)

llm = LearningLLM(config=config)

Or YAML:

namespace: my-app
quality_threshold: 0.8
max_retries: 3
config = Config.from_yaml("config.yaml")

📂 Memory Structure

memories/
└── {namespace}/
    ├── patterns/
    │   ├── 001-function-structure.md
    │   └── 002-error-handling.md
    └── prompts/
        └── current.md

Human-readable Markdown - inspect or version control.


🧪 Development

pip install -e .[dev]
pytest --cov

📚 Documentation


📝 License

MIT - see LICENSE


Built by Netanel Systems with LangGraph + Deep Agents

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

netanel_core-0.2.0.tar.gz (148.3 kB view details)

Uploaded Source

Built Distribution

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

netanel_core-0.2.0-py3-none-any.whl (67.2 kB view details)

Uploaded Python 3

File details

Details for the file netanel_core-0.2.0.tar.gz.

File metadata

  • Download URL: netanel_core-0.2.0.tar.gz
  • Upload date:
  • Size: 148.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for netanel_core-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ff8e8183dbef937ceafa7384d9d3d07389759a7ee8cb842f00852468fa9f1b0a
MD5 63cd0d8cebf1dae9fe47578f58c3240f
BLAKE2b-256 ccfce6bd4e5572deb6445d85d12215d7c079be37c64504c5190b40e1e249a9e7

See more details on using hashes here.

Provenance

The following attestation bundles were made for netanel_core-0.2.0.tar.gz:

Publisher: publish.yml on netanel-systems/netanel-core

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file netanel_core-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: netanel_core-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 67.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for netanel_core-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 72b8a062313fda2bcc8cf778564b14240f8cceb23019f26ac44993789fa39151
MD5 ef0039adca99ba8a3153ff57faa50f7e
BLAKE2b-256 5bf694f3716470b102feb28242260be0da022a3a5384b497c1654ecee1a6c6db

See more details on using hashes here.

Provenance

The following attestation bundles were made for netanel_core-0.2.0-py3-none-any.whl:

Publisher: publish.yml on netanel-systems/netanel-core

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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