Skip to content

kavediyaharsh/agentmlops

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Integrating Agentic AI into MLOps Pipelines:

A Python-Based Framework for Autonomous Model Monitoring & Adaptation

This repository provides a demonstration of integrating agentic AI into MLOps workflows using LangChain, Hugging Face models, and MLflow.
The pipeline simulates data drift detection, risk assessment, and automatic retraining, while logging all results to MLflow for transparency and reproducibility.


🚀 Features

  • LLM-driven agents: Uses a large language model (LLaMA-3.1-8B) from Hugging Face via LangChain.
  • Data drift detection: Implements a Kolmogorov–Smirnov (KS) test to detect drift between old and new data distributions.
  • Risk assessment: Simple bias score comparison between historical and current accuracy.
  • Model retraining: Retrains a PyTorch model on simulated new data if drift is detected and risk is low.
  • Experiment tracking: Logs metrics, parameters, and models with MLflow for reproducibility and visualization.

📂 Project Structure

agentmlops/
├── agent-mlops-pipeline.py   # main Python script
├── requirements.txt          # project dependencies
├── .env                      # template for Hugging Face API token
└── README.md                 # documentation (this file)

⚙️ Setup Instructions

Follow these steps to set up and run the project on your local system.

1. Clone the repository

git clone https://github.com/your-username/agentmlops.git
cd agentmlops

2. Create and activate a virtual environment

# Create virtual environment
python3 -m venv venv

# Activate (Mac/Linux)
source venv/bin/activate

# Activate (Windows PowerShell)
venv\Scripts\activate

3. Install dependencies

pip install -r requirements.txt

4. Configure environment variables

  • Create a .env file in the same directory.

  • Add your Hugging Face access token to .env:

    HUGGINGFACEHUB_API_TOKEN="your_token_here"

🔑 You need access to the LLaMA-3.1-8B model to run this demo.

5. Verify installation

python --version
pip list

▶️ Running the Pipeline

Run the script:

python agent-mlops-pipeline.py

Expected output (example):

Deterministic pipeline result: ✅ Drift detected. Retrained model safely.

📊 Tracking with MLflow

To visualize results with MLflow, open another terminal and start the UI:

mlflow ui

Then go to http://127.0.0.1:5000 in your browser.

You will see:

  • Parameters:
    • deterministic_agent_response (drift/risk/retrain result)
    • llm_agent_response (LLM agent output, if available)
  • Metrics:
    • accuracy (simulated model accuracy)
    • historical_accuracy (baseline reference)
  • Artifacts:
    • retrained model (logged via MLflow if retraining is triggered)

📖 Code Overview

  • detect_drift → applies a KS-test between old and new predictions.
  • assess_risk → compares current accuracy to historical accuracy.
  • retrain_model → retrains a simple PyTorch model on new data.
  • LangChain Agent → orchestrates tools via natural language queries.
  • MLflow logging → ensures reproducibility and experiment tracking.

The workflow is as follows:

  1. Generate dummy old and new datasets.
  2. Detect drift (shift simulated with added noise).
  3. If drift is detected:
    • Assess risk.
    • Retrain the model if safe.
  4. Log results to MLflow.
  5. Optionally, query the pipeline via the LLM agent for reasoning steps.

📌 Notes

  • This demo uses synthetic data and a simple linear model.
  • It is designed to illustrate the integration of agentic AI with monitoring, retraining, and experiment tracking.
  • Extend it with real datasets and production-grade models for applied research.

📜 License

This repository is shared for academic and research purposes.

About

This is the working code for research paper.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages