AI2ML is a hybrid AI + ML control plane for reducing the cost of large language model usage. The big LLM stays the generalist reasoning layer, while AI2ML continuously monitors traffic, turns repeated behavior into datasets, trains a smaller model, and deploys that smaller model to absorb routine work.
This repository now contains a complete local MVP of that loop.
Large LLMs are expensive to run at scale. In real systems, many requests are not truly novel. They repeat the same narrow patterns again and again:
- classification
- routing
- filtering
- cache decisions
- simple delegation decisions
- structured pre-processing before an LLM call
AI2ML keeps the expensive LLM for hard or novel cases and gradually builds a cheaper ML layer for the repetitive ones.
The codebase implements a full five-stage pipeline:
MonitorAgentgenerates or captures workload events.CollectorAgentvalidates and persists those events.AggregatorAgenttransforms raw events into ML-ready aggregate rows.TrainerAgentbuilds a lightweight delegation model from the aggregates.ProviderAgentdeploys the latest model and serves predictions.
The current trainer/provider layer is intentionally lightweight and dependency free. It uses a heuristic model as the built-in baseline so the whole AI2ML loop works locally without external ML infrastructure. That baseline can later be replaced by a richer ML backend.
- agents.py contains the main agent implementations.
- main.py builds the runtime and exposes
run_full_pipeline(). - server.py exposes the Flask API.
- storage.py persists agent snapshots, events, aggregates, and model versions.
- config.py defines runtime and agent configs.
- Agents.md documents the architecture and schemas.
- Create and activate a virtual environment.
- Install dependencies with
pip install -r requirements.txt. - Run the API with
python3 server.py. - Optionally run a full local demo loop with
python3 main.py.
Main endpoints:
GET /healthGET /api/statusGET /api/agentsPOST /api/pipeline/monitorPOST /api/pipeline/collectPOST /api/pipeline/aggregatePOST /api/pipeline/trainPOST /api/pipeline/deployPOST /api/pipeline/runGET /api/data/eventsGET /api/data/aggregatesGET /api/modelsPOST /api/models/predictPOST /api/models/compare
Run the entire AI2ML loop in one request:
curl -X POST http://localhost:5000/api/pipeline/run \
-H 'Content-Type: application/json' \
-d '{"behavior_type":"user_engagement","duration_hours":24,"event_count":120}'Ask the deployed model whether a request should stay on the LLM or be delegated:
curl -X POST http://localhost:5000/api/models/predict \
-H 'Content-Type: application/json' \
-d '{"input_data":{"event_type":"classification"}}'Runtime data is persisted under ./data:
agent_data.pklcollected_events.jsonaggregated_data.csvmodel_versions.json
If you want to improve AI2ML, send ideas, fixes, or architectural proposals as GitHub pull requests. Proposal-style PRs are welcome, especially for new routing strategies, aggregation logic, model backends, and infrastructure integrations.
AI2ML is licensed under the custom terms in LICENSE.
In short:
- commercial use is allowed
- attribution is required
- you may not resell AI2ML itself as a standalone product
- you may not present AI2ML as if it were your original standalone work
The standard MIT text is included only as a reference in LICENSE-MIT.md. The operative license for this project is the custom LICENSE.