An intelligent, automated leave request processing system built with LangGraph and UiPath SDK that streamlines employee leave management through AI-powered decision making, policy compliance checks, and human-in-the-loop approvals.
graph TD
A[Start: Receive Leave Request] --> B[Extract Leave Information]
B --> C[Get Employee Details]
C --> D{All Fields Present?}
D -->|No| E[Employee HITL Form]
E --> D
D -->|Yes| F[Categorize Leave Type]
F --> G[Check Company Policy]
G --> H[Check Leave Availability]
H --> I{Policy Compliant?}
I -->|Needs HR| J[HR Approval HITL]
I -->|Auto Approved| K[Update Database]
I -->|Auto Rejected| L[Send Rejection Email]
J --> M{HR Decision}
M -->|Approved| K
M -->|Rejected| L
K --> N[Send Approval Email]
N --> O[End]
L --> O
- Intelligent Leave Request Parsing: Automatically extracts leave dates, duration, and reasons from natural language requests
- Smart Categorization: AI-powered classification of leave types (Vacation, Sick Leave, Maternity/Paternity, Bereavement, Personal Leave)
- Policy Compliance: Real-time validation against company policies using UiPath Context Grounding
- Leave Balance Management: Integration with employee database via MCP (Model Context Protocol)
- Human-in-the-Loop (HITL): Action Tasks (UiPath Action App) for missing information and HR approvals
- Automated Email Notifications: Sends approval/rejection emails with detailed information
- Database Integration: Automatic leave balance updates upon approval
The agent is built using a state machine architecture with LangGraph, enabling complex workflows with conditional branching and human intervention points.
- LangGraph State Machine: Orchestrates the entire workflow
- UiPath Services Integration:
- Context Grounding: Policy document retrieval and compliance checking
- MCP Server: Database operations (employee details, leave balance)
- HITL Actions: Action Tasks (UiPath Action App) for user input and approvals
- LLM (GPT-4): Natural language understanding and decision making
- Email Service: Automated notifications via MCP
- Python 3.10+
- UiPath Automation Suite account
- LLM API key
- MCP Server configured with database access
-
Clone the repository
git clone https://github.com/rajneeshk94/LeaveManagementAgent.git cd LeaveManagementAgent -
Install dependencies
pip install -r requirements.txt
-
Configure environment variables
Create a
.envfile:# MCP Server MCP_SERVER_URL=https://your-mcp-server-url # Optional: If not using UiPath's LLM OPENAI_API_KEY=your_openai_key
-
Set up UiPath Resources
- Context Grounding Index: Create an index named
company-policy-indexwith your HR policies - MCP Server Tools: Configure the following tools:
getemployeedetails: Retrieve employee informationgetleavebalance: Fetch leave balanceupdateleavebalance: Update leave records- sendemail`: Email notification service
- HITL Apps: Deploy the following apps in your
Sharedfolder:LeaveRequestApp: Employee information appHRApprovalApp: HR approval app
- Context Grounding Index: Create an index named
-
Authenticate with UiPath
uipath auth
-
Package the project
uipath pack
-
Publish the project
uipath publish - When prompted, select tenant to upload
import asyncio
from main import agent, GraphState
async def process_leave_request():
# Initialize state with employee's leave request
initial_state = GraphState(
leave_request="I need leave from Dec 20 to Dec 25 for vacation",
employee_email="[email protected]"
)
# Run the agent
final_state = None
async for event in agent.astream(initial_state):
print(f"Event: {event}")
final_state = event
# Check final status
if final_state:
print(f"\nFinal Status: {final_state['final_status']}")
# Run the async function
if __name__ == "__main__":
asyncio.run(process_leave_request())The system supports five leave types:
- Vacation: Personal time off, travel, recreation
- Sick Leave: Illness, medical appointments, mental health
- Maternity/Paternity: Pregnancy, childbirth, adoption
- Bereavement: Death of family member, funeral attendance
- Personal Leave: Personal matters not covered elsewhere
{
"Vacation": 20,
"Sick Leave": 12,
"Maternity/Paternity": 90,
"Bereavement": 5,
"Personal Leave": 3
}HR approval is required when:
- Leave duration exceeds 5 days
- Leave type is Maternity/Paternity
- Policy violations detected
- Insufficient leave balance
- Policy explicitly requires HR review
Your MCP server should implement these endpoints:
GET /getemployeedetails
{
"employee_email": "[email protected]"
}GET /getleavebalance
{
"employee_email": "[email protected]"
}POST /updateleavebalance
{
"employee_email": "[email protected]",
"leave_type": "Vacation",
"days": 5
}POST /sendemail
{
"Recipient": "[email protected]",
"Subject": "Leave Request Status",
"Body": "<html>...</html>"
}leave-management-agent/
├── main.py # Main agent code
├── requirements.txt # Python dependencies
├── .env # Environment variables (not committed)
├── README.md # This file
├── Images/
│ ├── agent.png
- Update the
categorize_nodesystem prompt - Add default balance in
default_leave_balance() - Update company policies in Context Grounding index
Edit the check_policy_node function to adjust:
- HR approval thresholds
- Policy validation logic
- Balance checking rules
Customize email content in:
send_approval_email_nodesend_rejection_email_node
