implemenation on the ai agents and registry
This commit is contained in:
@@ -12,7 +12,9 @@ import redis.asyncio as aioredis
|
||||
from core.agent import SpecializedAgent
|
||||
from core.types import AgentTask, MessageType
|
||||
from core.logger import logger
|
||||
from core.llm import decide_assignment_failure, build_assignment_failure_context
|
||||
from core.llm import decide_assignment_failure, build_assignment_failure_context, LLM_MODEL
|
||||
from core.registry import registry
|
||||
from core.decisions import record_decision
|
||||
from config.system_config import (
|
||||
NATS_HOST, NATS_PORT, NATS_USER, NATS_PASSWORD,
|
||||
REDIS_HOST, REDIS_PORT, REDIS_PASSWORD,
|
||||
@@ -264,18 +266,12 @@ class DispatchAgent(SpecializedAgent):
|
||||
f"miler={miler_id} hub={hub_id} confidence={confidence} "
|
||||
f"reasoning={reasoning!r}"
|
||||
)
|
||||
|
||||
await self.send_message(
|
||||
recipient="HUB_AGENT",
|
||||
message_type=MessageType.AGENT_TASK,
|
||||
payload={
|
||||
"task_type": "prepare_receiving",
|
||||
"booking_id": booking_id,
|
||||
"miler_id": miler_id,
|
||||
"hub_id": hub_id,
|
||||
},
|
||||
correlation_id=str(booking_id),
|
||||
)
|
||||
# No longer forwarded to HUB_AGENT as `prepare_receiving`. HUB_AGENT
|
||||
# is a simulation over eight fictional hubs keyed "XX-HUB-01"; handed a
|
||||
# real backend hub id and booking id it answered "Hub not found" for
|
||||
# every assignment, so the hand-off did nothing but log noise. Restore
|
||||
# it only once HUB_AGENT reads real hubs (agent registry status:
|
||||
# simulation).
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"DispatchAgent booking.assigned handler error: {e}")
|
||||
@@ -305,17 +301,25 @@ class DispatchAgent(SpecializedAgent):
|
||||
f"reason={data.get('reason')!r}"
|
||||
)
|
||||
|
||||
if not registry.skill_enabled("assignment_failure_triage"):
|
||||
logger.info(
|
||||
f"[DISPATCH] booking={booking_id}: skill assignment_failure_triage is disabled "
|
||||
"in the agent registry; not triaging"
|
||||
)
|
||||
return
|
||||
|
||||
facts, count = await self._gather_assignment_facts(zone_id, lat, lon)
|
||||
realert_every = int(registry.threshold("assignment_failure_triage", "realertEvery", DISPATCH_REALERT_EVERY))
|
||||
logger.info(f"[DISPATCH] booking={booking_id} context facts: {facts}")
|
||||
|
||||
# Rate limit: once this zone has been alerted today, don't re-decide
|
||||
# (and don't pay for an LLM call) on every further failure.
|
||||
if facts.get("alert_already_sent_today"):
|
||||
if DISPATCH_REALERT_EVERY and count % DISPATCH_REALERT_EVERY == 0:
|
||||
if realert_every and count % realert_every == 0:
|
||||
await self._ops_alert(
|
||||
zone_id, booking_id,
|
||||
f"Zone {zone_id}: {count} failed assignments today and still climbing "
|
||||
f"(re-alert every {DISPATCH_REALERT_EVERY}; earlier alert already raised).",
|
||||
f"(re-alert every {realert_every}; earlier alert already raised).",
|
||||
severity="high",
|
||||
)
|
||||
else:
|
||||
@@ -325,7 +329,11 @@ class DispatchAgent(SpecializedAgent):
|
||||
)
|
||||
return
|
||||
|
||||
decision = await decide_assignment_failure(build_assignment_failure_context(facts))
|
||||
model = registry.model("DISPATCH_AGENT")
|
||||
decision = await decide_assignment_failure(build_assignment_failure_context(facts), model)
|
||||
if decision is not None:
|
||||
record_decision("assignment_failure", booking_id, facts, decision.action, decision.confidence,
|
||||
decision.reasoning, model or LLM_MODEL)
|
||||
|
||||
if decision is None:
|
||||
logger.warning(f"No LLM decision for booking {booking_id}; falling back to count>=3 heuristic")
|
||||
@@ -347,7 +355,7 @@ class DispatchAgent(SpecializedAgent):
|
||||
pass # transient — the backend will retry
|
||||
|
||||
elif decision.action == "notify_customer":
|
||||
if DISPATCH_AGENT_AUTONOMOUS:
|
||||
if registry.autonomous("DISPATCH_AGENT", DISPATCH_AGENT_AUTONOMOUS):
|
||||
await self._notify_customer_delay(booking_id)
|
||||
else:
|
||||
# Outward-facing action not authorised — raise an internal proposal instead.
|
||||
|
||||
Reference in New Issue
Block a user