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.1.0.tar.gz (76.1 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.1.0-py3-none-any.whl (44.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: netanel_core-0.1.0.tar.gz
  • Upload date:
  • Size: 76.1 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.1.0.tar.gz
Algorithm Hash digest
SHA256 c3a44f936c738a5b69b61d36b74ac7a4a8e090836d47f9deb2b47bf3d4b61d93
MD5 b3efae326536108532a5176588e99681
BLAKE2b-256 a7e7b71caa4235a812625e6ea36aa7578bb16d4347db8db48474a74baa68f0a6

See more details on using hashes here.

Provenance

The following attestation bundles were made for netanel_core-0.1.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.1.0-py3-none-any.whl.

File metadata

  • Download URL: netanel_core-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 44.3 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 72898ef1bce39a6189f708d1e984fc6e98874e32a8dbf9d516960c301c7f0107
MD5 d3f46d3c5189eeb36be89c5b25f50435
BLAKE2b-256 53f67542953bf511fbe67a97fc9d075212b792949d0ebe003e70845df97aca53

See more details on using hashes here.

Provenance

The following attestation bundles were made for netanel_core-0.1.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