Enterprise-grade AI-powered HR Management System for Kenya, built with LangGraph, OpenAI, and M-Pesa integration.
- Overview
- Features
- Architecture
- Quick Start
- Deployment
- API Documentation
- Observability
- PayLink Integration
- Configuration
- Development
- Testing
- License
Hifadhi is a production-ready multi-agent AI system designed specifically for HR management in Kenya. It automates candidate screening, onboarding, compliance verification (KRA/NSSF/NHIF), payroll processing via M-Pesa, and provides real-time analytics.
- π― Intelligent Routing - Supervisor agent analyzes intent and routes to specialists
- π° M-Pesa Payments - Automated salary processing via PayLink STK Push
- π Analytics - Real-time hiring metrics and pipeline insights
- β Compliance - KRA PIN, NSSF, NHIF verification
- π Onboarding - Automated task tracking and document collection
- π Candidate Screening - AI-powered application review
- π¬ RAG-Powered FAQ - ChromaDB vector search for HR questions
- π Observability - Phoenix (Arize) distributed tracing
| Agent | Responsibility | Tools |
|---|---|---|
| Supervisor | Central orchestrator, intent analysis | ask_user |
| Candidate Screening | Application tracking, interviews | get_candidate_details, get_application_status |
| Onboarding | Task management, document collection | get_onboarding_tasks |
| Compliance | KRA/NSSF/NHIF verification | get_compliance_status |
| Payroll | M-Pesa payments, salary processing | initiate_mpesa_stk_push, get_payroll_history |
| Analytics | Hiring metrics, pipeline analytics | get_hiring_metrics, get_pipeline_analytics |
| General Help | FAQ responses (RAG) | ChromaDB vector search |
| Human Escalation | Complex case handoff | N/A |
| Final Answer | Response polishing | N/A |
- Framework: LangGraph (state-based orchestration)
- LLM: OpenAI GPT-4o-mini
- Database: SQLite (500 candidates, 20 jobs, 1000 applications)
- Vector Store: ChromaDB (HR FAQs)
- Payments: PayLink M-Pesa API
- Observability: Phoenix (Arize)
- API: FastAPI
- Deployment: Docker + Docker Compose
βββββββββββββββ
β User Query β
ββββββββ¬βββββββ
β
βΌ
ββββββββββββββββββββββββββββββ
β Supervisor Agent β β Central Orchestrator
β (Intent Analysis) β
ββββββββ¬βββββββββββββββββββββ¬β
β β
βΌ βΌ
ββββββββββββββββ βββββββββββββββββ
β Specialist 1 β β Specialist 2 β
β (Payroll) β β (Screening) β
ββββββββ¬ββββββββ βββββββββ¬ββββββββ
β β
ββββββββββ¬ββββββββββββ
βΌ
ββββββββββββββββββ
β Final Answer β
β Agent β
ββββββββββββββββββ
Workflow Flow:
- User query β Supervisor
- Supervisor routes to specialist(s)
- Specialist executes tasks (tool calls)
- Returns to Supervisor
- Supervisor routes to Final Answer
- Polished response β User
- Python 3.11+
- Docker & Docker Compose (optional)
- OpenAI API key
- PayLink API credentials (for payments)
# 1. Clone repository
git clone https://github.com/yourusername/hifadhi-os.git
cd hifadhi-os
# 2. Create virtual environment
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
# 3. Install dependencies
pip install -r requirements.txt
# 4. Configure environment
cp .env.example .env
nano .env # Add your API keys
# 5. Initialize database
python data/setup_database.py
python data/load_hr_faqs.py
# 6. Run the system
python main.py$ python main.py
π€ Hifadhi Interactive Mode
Type 'exit' to quit
HR Manager: What is the status of application APP00001?
======================================================================
HIFADHI MULTI-AGENT SYSTEM
======================================================================
Query: What is the status of application APP00001?
======================================================================
---SUPERVISOR AGENT---
π User Query: What is the status of application APP00001?
Supervisor iteration: 1
π― Intent: check_application_status
β‘οΈ Routing to: candidate_screening_agent
---CANDIDATE SCREENING AGENT---
π Task: Check application status for APP00001
π Fetching details...
β
Done
======================================================================
FINAL RESPONSE
======================================================================
Application APP00001 (Jane Mwangi for Customer Service Representative):
β’ Status: Interview Scheduled
β’ AI Screening Score: 78/100
β’ Interview Date: 2024-12-15 at 10:00 AM
β’ Location: Nairobi Office
======================================================================# 1. Configure environment
cp .env.example .env
nano .env # Add API keys
# 2. Deploy
chmod +x deploy.sh
./deploy.sh
# Services will be available at:
# - API: http://localhost:8000
# - Docs: http://localhost:8000/docs
# - Phoenix: http://localhost:6006docker build -t hifadhi-agent-system .
docker run -d \
-p 8000:8000 \
--env-file .env \
-v $(pwd)/data:/app/data \
-v $(pwd)/logs:/app/logs \
--name hifadhi-app \
hifadhi-agent-system# Start services
docker-compose up -d
# View logs
docker-compose logs -f hifadhi
# Stop services
docker-compose down
# Rebuild
docker-compose build --no-cachehttp://localhost:8000
GET /Response:
{
"status": "online",
"system": "Hifadhi Multi-Agent OS"
}POST /chat
Content-Type: application/json
{
"query": "Process salary for candidate CAND00001",
"session_id": "optional-session-id"
}Response:
{
"response": "I've initiated a payment of KES 50,000...",
"session_id": "session_20241122_103045",
"agent_history": [
"Supervisor Agent: Analyzed intent",
"Payroll Agent: Processed payment"
],
"requires_action": false
}POST /webhooks/paylink
Content-Type: application/json
{
"transaction_id": "TRX123456",
"status": "completed",
"amount": 50000,
"mpesa_receipt_number": "PK12ABC345"
}Response:
{
"status": "received"
}Visit http://localhost:8000/docs for Swagger UI with live API testing.
Start Phoenix:
docker-compose up phoenixAccess Dashboard:
http://localhost:6006
Features:
- Distributed tracing across all agents
- LLM call monitoring
- Tool execution tracking
- Error debugging
- Performance metrics
Example Trace:
supervisor_agent (250ms)
ββ analyze_intent (50ms)
ββ extract_entities (30ms)
ββ route_decision (20ms)
payroll_agent (1200ms)
ββ tool.get_candidate_details (80ms)
ββ tool.initiate_mpesa_stk_push (1000ms)
ββ format_response (50ms)
final_answer_agent (100ms)
from tools.paylink_integration import initiate_mpesa_stk_push
result = initiate_mpesa_stk_push(
candidate_id="CAND00001",
amount=50000.0,
phone_number="0712345678",
payment_type="salary",
description="November 2024 Salary"
)
# Result:
# {
# "success": True,
# "transaction_id": "TRX123456789",
# "message": "STK Push sent to 254712345678",
# "status": "pending"
# }from tools.paylink_integration import process_bulk_payments
payments = [
{"candidate_id": "CAND00001", "amount": 50000, "phone_number": "0712345678"},
{"candidate_id": "CAND00002", "amount": 45000, "phone_number": "0723456789"}
]
results = process_bulk_payments(payments)
# {
# "total": 2,
# "pending": 2,
# "failed": 0
# }from tools.paylink_integration import check_payment_status
status = check_payment_status("TRX123456789")
# {
# "status": "completed",
# "mpesa_receipt": "PK12ABC345"
# }Edit .env:
# OpenAI
OPENAI_API_KEY=sk-proj-xxxxxxxxxxxxx
# PayLink
PAYLINK_API_KEY=your_api_key
PAYLINK_API_SECRET=your_api_secret
PAYLINK_WEBHOOK_SECRET=your_webhook_secret
PAYLINK_CALLBACK_URL=https://yourdomain.com/webhooks/paylink
# Phoenix
PHOENIX_COLLECTOR_ENDPOINT=http://127.0.0.1:6006/v1/traces
# Database
DATABASE_PATH=data/hifadhi.db
VECTOR_STORE_PATH=data/chroma_db
# Logging
LOG_LEVEL=INFOHifadhiOS/
βββ agents/ # 9 specialized agents
β βββ supervisor_agent.py
β βββ candidate_screening_agent.py
β βββ payroll_agent.py
β βββ ...
βββ workflows/ # LangGraph orchestration
β βββ langgraph_workflow.py
β βββ routing_logic.py
β βββ workflow_monitor.py
βββ tools/ # Database, PayLink, Analytics
β βββ database_tools.py
β βββ paylink_integration.py
β βββ analytics_tools.py
βββ utils/ # LLM client, tracing
β βββ llm_client.py
β βββ tracing.py
β βββ state_management.py
βββ data/ # SQLite DB + ChromaDB
βββ tests/ # Unit & integration tests
βββ docs/ # Documentation
βββ web_server.py # FastAPI server
βββ main.py # CLI entry point
βββ Dockerfile
βββ docker-compose.yml
- Create
agents/new_agent.py - Implement agent function with state parameter
- Add to
workflows/langgraph_workflow.py - Update routing logic in
workflows/routing_logic.py - Add tests in
tests/
python -m unittest discover tests# API tests
python -m unittest tests/test_api.py
# PayLink tests
python -m unittest tests/test_paylink.py
# Workflow tests
python -m unittest tests/test_workflow.py- β Unit tests for all agents
- β Integration tests for API endpoints
- β PayLink payment flow tests
- β Workflow routing tests
- β Database tools tests
- Average Query Processing: 2-3 seconds
- Database Queries: <100ms
- LLM Calls: 500-1500ms
- PayLink API: 1-2 seconds (STK Push)
- Concurrent Requests: 50+ (with Uvicorn workers)
- β Environment variable-based configuration
- β HMAC-SHA256 webhook signature verification
- β API key authentication for PayLink
- β Input validation (Pydantic models)
- β SQL injection prevention (parameterized queries)
- β Rate limiting (TODO for production)
MIT License - See LICENSE file for details
- Imain - Lead Developer
- OpenAI for GPT-4o-mini
- LangChain team for LangGraph
- Arize for Phoenix observability
- PayLink for M-Pesa integration
For issues and questions:
- GitHub Issues: Issues
- Email: support@hifadhi.ai
- Documentation: docs/
Built with β€οΈ in Kenya π°πͺ