Metadata-Version: 2.4
Name: distilroute
Version: 0.1.0
Summary: Distill an LLM intent classifier into a cheap local router trained from its own logs.
Author-email: anto-pv <antopv833@gmail.com>
License-Expression: MIT
Project-URL: Homepage, https://github.com/anto-pv/distilroute
Project-URL: Repository, https://github.com/anto-pv/distilroute
Project-URL: Issues, https://github.com/anto-pv/distilroute/issues
Keywords: llm,intent-classification,routing,langgraph,distillation,tfidf
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: scikit-learn>=1.3
Provides-Extra: dev
Requires-Dist: pytest>=7; extra == "dev"
Dynamic: license-file

# distilroute

Divert traffic away from an expensive LLM intent classifier. `distilroute`
logs the LLM's own decisions, trains a cheap local TF-IDF+LogisticRegression
model from them, and routes high-confidence traffic locally — while never
routing worse than LLM-only.

## Install

```bash
pip install distilroute
```

## Use

```python
from distilroute import Distiller

d = Distiller(store="routes.jsonl", retrain_every=500)
route = d.wrap(my_llm_classify_fn)   # my_llm_classify_fn(text) -> (intent, confidence)

intent, source, conf = route("cancel my order")   # source: "local" | "llm"

d.train()            # manual retrain (also fires automatically every retrain_every logs)
print(d.report())    # "Local model can handle 61% of traffic at confidence >= 0.9, ..."
```

### LangGraph

```python
from distilroute.adapters.langgraph import make_router_node
node = make_router_node(d)   # drop into your graph in place of the classifier node
```

### CLI (cron-friendly)

```bash
distill status     # how many decisions logged, current threshold
distill train      # retrain and print the coverage report
distill report     # print the last coverage report
```

## How it stays safe

The local model only answers when its confidence clears a threshold that was
proven on a holdout to agree with the LLM at least `target_agreement` (default
95%) of the time. Everything else falls back to the LLM. Worst case = today.
