implemenation on the ai agents and registry
This commit is contained in:
@@ -36,6 +36,7 @@ from core.agent import SpecializedAgent
|
||||
from core.types import AgentTask
|
||||
from core.logger import logger
|
||||
from core.http_client import api_get, api_post
|
||||
from core.registry import registry
|
||||
from config.system_config import (
|
||||
NATS_HOST, NATS_PORT, NATS_USER, NATS_PASSWORD,
|
||||
GO_API_BASE_URL, INTERNAL_API_KEY, ROUTE_OPTIMIZER_URL,
|
||||
@@ -162,7 +163,9 @@ class ExpressDispatchAgent(SpecializedAgent):
|
||||
logger.info(
|
||||
f"[EXPRESS] dispatch received — tenant={tenant_id} bookings={len(booking_ids)}"
|
||||
)
|
||||
if tenant_id and booking_ids:
|
||||
if not registry.skill_enabled("express_batch_dispatch"):
|
||||
logger.info("[EXPRESS] skill express_batch_dispatch is disabled in the agent registry; batch left for the console")
|
||||
elif tenant_id and booking_ids:
|
||||
await self._handle_batch(tenant_id, booking_ids)
|
||||
except Exception as e:
|
||||
logger.error(f"ExpressDispatchAgent batch handler error: {e}")
|
||||
@@ -212,10 +215,10 @@ class ExpressDispatchAgent(SpecializedAgent):
|
||||
return
|
||||
|
||||
# 3. Write back (or, in observation mode, only log the plan).
|
||||
if not EXPRESS_AGENT_AUTONOMOUS:
|
||||
if not registry.autonomous("EXPRESS_DISPATCH_AGENT", EXPRESS_AGENT_AUTONOMOUS):
|
||||
logger.info(
|
||||
f"[EXPRESS] tenant={tenant_id} OBSERVE-ONLY plan "
|
||||
f"(EXPRESS_AGENT_AUTONOMOUS=false): {json.dumps(assignments)}"
|
||||
f"(autonomy off): {json.dumps(assignments)}"
|
||||
)
|
||||
return
|
||||
|
||||
@@ -247,6 +250,10 @@ class ExpressDispatchAgent(SpecializedAgent):
|
||||
part (ordering); this only decides who."""
|
||||
load: Dict[int, int] = {r["miler_user_id"]: 0 for r in riders}
|
||||
rider_stops: Dict[int, List[Dict]] = {}
|
||||
# Tuned in the agent registry (skill express_batch_dispatch), else env.
|
||||
max_per_rider = int(registry.threshold("express_batch_dispatch", "maxPerRider", MAX_PER_RIDER))
|
||||
max_radius_km = registry.threshold("express_batch_dispatch", "maxRadiusKm", MAX_RADIUS_KM)
|
||||
load_penalty_km = registry.threshold("express_batch_dispatch", "loadPenaltyKm", LOAD_PENALTY_KM)
|
||||
|
||||
# Assign larger-pickup-cluster bookings first is unnecessary; simple
|
||||
# stable order keeps it predictable and testable.
|
||||
@@ -255,13 +262,13 @@ class ExpressDispatchAgent(SpecializedAgent):
|
||||
best_rider = None
|
||||
best_score = None
|
||||
for r in riders:
|
||||
if load[r["miler_user_id"]] >= MAX_PER_RIDER:
|
||||
if load[r["miler_user_id"]] >= max_per_rider:
|
||||
continue
|
||||
rlat, rlon = _rider_location(r, plat, plon)
|
||||
dist = _haversine_km(rlat, rlon, plat, plon)
|
||||
if dist > MAX_RADIUS_KM:
|
||||
if dist > max_radius_km:
|
||||
continue
|
||||
score = dist + LOAD_PENALTY_KM * load[r["miler_user_id"]]
|
||||
score = dist + load_penalty_km * load[r["miler_user_id"]]
|
||||
if best_score is None or score < best_score:
|
||||
best_score = score
|
||||
best_rider = r
|
||||
|
||||
Reference in New Issue
Block a user