Spaces:
Sleeping
Sleeping
Create agents.py
Browse files
agents.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# agents.py
|
| 2 |
+
import config
|
| 3 |
+
|
| 4 |
+
class LogisticsAgent:
|
| 5 |
+
"""
|
| 6 |
+
Base class for specific agents. In a real LLM app,
|
| 7 |
+
these would call OpenAI/Anthropic APIs.
|
| 8 |
+
"""
|
| 9 |
+
def __init__(self, name, role):
|
| 10 |
+
self.name = name
|
| 11 |
+
self.role = role
|
| 12 |
+
|
| 13 |
+
def negotiate(self):
|
| 14 |
+
raise NotImplementedError
|
| 15 |
+
|
| 16 |
+
class CostAgent(LogisticsAgent):
|
| 17 |
+
def negotiate(self):
|
| 18 |
+
return {
|
| 19 |
+
"msg": f"💰 {self.name}: 'We must cut fuel costs. Capping distance to {config.LIMIT_COST_STRATEGY}.'",
|
| 20 |
+
"constraint": config.LIMIT_COST_STRATEGY,
|
| 21 |
+
"label": "Budget-Focused"
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
class EcoAgent(LogisticsAgent):
|
| 25 |
+
def negotiate(self):
|
| 26 |
+
return {
|
| 27 |
+
"msg": f"🌿 {self.name}: 'Sustainability priority active. Strict range limit of {config.LIMIT_ECO_STRATEGY}.'",
|
| 28 |
+
"constraint": config.LIMIT_ECO_STRATEGY,
|
| 29 |
+
"label": "Eco-Friendly"
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
class DispatcherAgent(LogisticsAgent):
|
| 33 |
+
def negotiate(self):
|
| 34 |
+
return {
|
| 35 |
+
"msg": f"⚡ {self.name}: 'Delivery speed is paramount. Removing range limits.'",
|
| 36 |
+
"constraint": config.LIMIT_SPEED_STRATEGY,
|
| 37 |
+
"label": "High Velocity"
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
def get_agent_decision(strategy_mode):
|
| 41 |
+
"""Factory function to return the correct agent's decision."""
|
| 42 |
+
if strategy_mode == "Cost-Killer":
|
| 43 |
+
return CostAgent("Accountant", "Budget").negotiate()
|
| 44 |
+
elif strategy_mode == "Eco-Mode":
|
| 45 |
+
return EcoAgent("Greta", "Environment").negotiate()
|
| 46 |
+
else:
|
| 47 |
+
return DispatcherAgent("OpsLead", "Speed").negotiate()
|