PD03 commited on
Commit
7021f91
·
verified ·
1 Parent(s): c9a0b1a

Create tools.py

Browse files
Files changed (1) hide show
  1. tools.py +161 -0
tools.py ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import random
2
+ from datetime import datetime
3
+
4
+ class BaseTool:
5
+ """Base class for all procurement tools"""
6
+ def __init__(self, name):
7
+ self.name = name
8
+
9
+ def run(self, pr_data):
10
+ raise NotImplementedError
11
+
12
+ class InventoryTool(BaseTool):
13
+ def __init__(self):
14
+ super().__init__("InventoryTool")
15
+
16
+ def run(self, pr_data):
17
+ current_inventory = pr_data["Current_Inventory"]
18
+ required_quantity = pr_data["Quantity"]
19
+
20
+ # Simulate checking other locations
21
+ other_locations_inventory = random.randint(0, required_quantity * 2)
22
+ total_available = current_inventory + other_locations_inventory
23
+
24
+ if total_available >= required_quantity:
25
+ return {
26
+ "inventory_available": True,
27
+ "current_location": current_inventory,
28
+ "other_locations": other_locations_inventory,
29
+ "total_available": total_available,
30
+ "message": f"Sufficient inventory available: {total_available} units across all locations"
31
+ }
32
+ else:
33
+ return {
34
+ "inventory_available": False,
35
+ "current_location": current_inventory,
36
+ "other_locations": other_locations_inventory,
37
+ "total_available": total_available,
38
+ "shortage": required_quantity - total_available,
39
+ "message": f"Inventory shortage: {required_quantity - total_available} units needed"
40
+ }
41
+
42
+ class ExternalRiskTool(BaseTool):
43
+ def __init__(self):
44
+ super().__init__("ExternalRiskTool")
45
+
46
+ def run(self, pr_data):
47
+ # Simulate external risk assessment
48
+ category = pr_data["Category"]
49
+ external_disruption = pr_data["External_Disruption"]
50
+
51
+ # Risk factors based on category and external conditions
52
+ risk_factors = []
53
+ risk_score = 0.0
54
+
55
+ if external_disruption:
56
+ risk_factors.append("Supply chain disruption reported")
57
+ risk_score += 0.4
58
+
59
+ # Category-specific risks
60
+ if category == "Raw Materials":
61
+ if random.random() < 0.2: # 20% chance of commodity price volatility
62
+ risk_factors.append("Commodity price volatility detected")
63
+ risk_score += 0.3
64
+
65
+ if category == "IT Equipment":
66
+ if random.random() < 0.15: # 15% chance of semiconductor shortage
67
+ risk_factors.append("Semiconductor supply constraints")
68
+ risk_score += 0.25
69
+
70
+ # Geographic risk simulation
71
+ if random.random() < 0.1: # 10% chance of regional disruption
72
+ risk_factors.append("Regional weather/transport disruption")
73
+ risk_score += 0.2
74
+
75
+ high_risk = risk_score > 0.3
76
+
77
+ return {
78
+ "risk": high_risk,
79
+ "risk_score": risk_score,
80
+ "risk_factors": risk_factors,
81
+ "message": f"Risk assessment: {'HIGH RISK' if high_risk else 'LOW RISK'} - Score: {risk_score:.2f}"
82
+ }
83
+
84
+ class ContractTool(BaseTool):
85
+ def __init__(self):
86
+ super().__init__("ContractTool")
87
+
88
+ def run(self, pr_data):
89
+ contract_status = pr_data["Contract_Status"]
90
+ category = pr_data["Category"]
91
+
92
+ # Simulate contract validation
93
+ if contract_status == "Expired":
94
+ days_expired = random.randint(1, 90)
95
+ return {
96
+ "contract_expired": True,
97
+ "days_expired": days_expired,
98
+ "renewal_required": True,
99
+ "message": f"Contract expired {days_expired} days ago - renewal required"
100
+ }
101
+ else:
102
+ days_remaining = random.randint(30, 365)
103
+ auto_renewable = category in ["Office Supplies", "Services"]
104
+
105
+ return {
106
+ "contract_expired": False,
107
+ "days_remaining": days_remaining,
108
+ "auto_renewable": auto_renewable,
109
+ "terms_compliant": True,
110
+ "message": f"Contract valid for {days_remaining} days - terms compliant"
111
+ }
112
+
113
+ class POExecutionTool(BaseTool):
114
+ def __init__(self):
115
+ super().__init__("POExecutionTool")
116
+
117
+ def run(self, pr_data):
118
+ # Simulate PO creation and execution
119
+ po_number = f"PO-{random.randint(100000, 999999)}"
120
+ estimated_delivery = random.randint(3, 14) # 3-14 days
121
+
122
+ # Calculate costs
123
+ base_cost = pr_data["Budget"]
124
+ urgency_premium = {"Low": 0.0, "Medium": 0.05, "High": 0.15}
125
+ final_cost = base_cost * (1 + urgency_premium[pr_data["Urgency"]])
126
+
127
+ return {
128
+ "po_executed": True,
129
+ "po_number": po_number,
130
+ "estimated_delivery_days": estimated_delivery,
131
+ "final_cost": final_cost,
132
+ "cost_variance": ((final_cost - base_cost) / base_cost) * 100,
133
+ "message": f"PO {po_number} created - Estimated delivery: {estimated_delivery} days, Cost: ${final_cost:,.2f}"
134
+ }
135
+
136
+ class HumanNotificationTool(BaseTool):
137
+ def __init__(self):
138
+ super().__init__("HumanNotificationTool")
139
+
140
+ def run(self, pr_data):
141
+ # Simulate human notification
142
+ urgency = pr_data["Urgency"]
143
+ notification_channels = []
144
+
145
+ if urgency == "High":
146
+ notification_channels = ["Email", "SMS", "Slack"]
147
+ sla_hours = 2
148
+ elif urgency == "Medium":
149
+ notification_channels = ["Email", "Slack"]
150
+ sla_hours = 8
151
+ else:
152
+ notification_channels = ["Email"]
153
+ sla_hours = 24
154
+
155
+ return {
156
+ "notified": True,
157
+ "channels": notification_channels,
158
+ "sla_hours": sla_hours,
159
+ "escalation_level": urgency,
160
+ "message": f"Human review requested via {', '.join(notification_channels)} - SLA: {sla_hours}h"
161
+ }