Part 3 of the 3-Part Master Specification documents the Autonomous Multi-Agent Reasoning, Governance, and Physical Action Execution Layer of the Order-to-Cash (O2C) Delivery Risk Copilot.
While Part 1 established real-time ingestion pipelines (Weather, Strikes, and Regulatory Document Generators) and Part 2 built the Unified ML Feature Store, Two-Stage Hurdle Predictive Engine, and Hybrid Dense/Sparse RAG, Part 3 provides the operational brain that transforms statistical predictions into binding supply chain actions.
graph TD
subgraph "PART 1: REAL-TIME INGESTION"
A1["Open-Meteo & RSS Feeds"] --> A2["SQLite DB (weather_readings, strike_news)"]
A2 --> A3["Document Generators (23 Word Protocols)"]
end
subgraph "PART 2: PREDICTIVE ML & RAG CORE"
B1["10 SAP ERP Tables"] --> B2["MLDatabaseExtension (19 Features)"]
B2 --> B3["Two-Stage Hurdle PredictiveEngine (97.1% Acc, 5.6h MAE)"]
A3 --> B4["Hybrid RAG Engine (82 Docs, 909 Chunks, FAISS + BM25)"]
B3 & B4 --> B5["Consolidated Prediction & Risk Payload"]
end
subgraph "PART 3: MULTI-AGENT REASONING & EXECUTION"
B5 --> C1["AgenticOrchestrator (Daily Lifecycle)"]
C1 --> D1["Specialist 1: RouteSupervisorAgent<br/>(Telematics GPS, Transit Velocity, Bypass Corridors)"]
C1 --> D2["Notification: ClinicNotificationDispatcher<br/>(12h Early Warnings for Force Majeure Compliance)"]
C1 --> D3["Specialist 2: ContractAdjudicatorAgent<br/>(SLA Matrices, Post-17:00 Violations, FM Waivers)"]
C1 --> D4["Specialist 3: QualityMitigationAgent<br/>(Prescription Diet Stock-outs, HPLC Assays, QA Holds)"]
D1 & D2 & D3 & D4 --> E1["Specialist 4: LLMReasoningEngine<br/>(Multi-Model Synthesis: Qwen / Llama-3 / GPT / Local)"]
E1 --> F1["SAPActionExecutor<br/>- Delivery Block: VBAK-LIFSK = '01'<br/>- Date Adjustment: VBAK-VDATU<br/>- Carrier Debit Memo: SAP_BKPF / BSEG"]
E1 --> F2["MSTeamsDispatcher<br/>(Interactive Adaptive Cards v1.4 with 2h SLA Approval Gate)"]
E1 --> F3["Audit Logger: daily_agent_report_YYYY-MM-DD.json"]
end
The multi-agent framework replaces monolithic LLM prompts with collaborative specialist agents, each possessing dedicated domain knowledge, operational constraints, and statutory mandates:
graph TD
A["Prediction Payload (Order ID, Carrier, Tier, ETA, Root Cause, RAG Rules)"] --> B["RouteSupervisorAgent"]
B -->|Telematics Active?| C{GPS Signal Check}
C -->|Lost > 12h| C1["Assess $200 Blind-Tracking Penalty<br/>Void Force Majeure Eligibility"]
C -->|Active| C2["Verify Velocity <= 55 km/h & Corridor Hazard"]
C1 & C2 --> D["ClinicNotificationDispatcher"]
D --> D1["Send Proactive 12h Early Warning to Clinic<br/>Preserves Statutory Force Majeure Defense"]
D1 --> E["ContractAdjudicatorAgent"]
E --> E1{Force Majeure Candidate?}
E1 -->|Yes & 12h Notice & GPS OK| E2["Grant 72h Penalty Waiver<br/>Waive $500/day SLA under Clause 4.2 / 8.4"]
E1 -->|No or Notice Missed| E3["Calculate SLA Delay Penalty:<br/>Platinum: $500/day | Gold: 5%/day (Cap 25%)"]
E --> E4{ETA >= 17:00?}
E4 -->|Yes| E5["Receiving Window Breach: Assess $150 Redelivery Fee"]
E2 & E3 & E5 --> F["QualityMitigationAgent"]
F --> F1{Specialty Diet & Delay > 48h?}
F1 -->|Yes| F2["Authorize $1,000 Emergency Air Freight Pallet"]
F --> F3{Temp > 40°C or Shelf-Life < 6m?}
F3 -->|Yes| F4["Mandate QA Quarantine Hold '01' & Lab HPLC Assay"]
F2 & F4 --> G{Mitigation Cost > $500 or Penalty > $1000?}
G -->|Yes| G1["DIRECTOR_APPROVAL_REQUIRED<br/>Dispatch MS Teams Adaptive Card (2h SLA)"]
G -->|No| G2["AUTONOMOUSLY_APPROVED<br/>Execute Immediate Autonomous ERP Write-Back"]
File Location: d:\Progamming\O2C_AI\modules\agent_specialists.py
Classes: RouteSupervisorAgent, ContractAdjudicatorAgent, QualityMitigationAgent, LLMReasoningEngine
Purpose: Defines the domain-specialist agent personas and LLM legal reasoning engine that evaluate telematics telemetry, calculate contractual penalties, plan quality mitigations, and synthesize authoritative executive briefs.
Purpose: Monitors linehaul shipment milestones, evaluates GPS telematics connectivity, assesses required transit velocity against physical corridor limits, and flags regional transit choke points.
1. analyze_route(self, prediction_payload: Dict[str, Any], order_data: Dict[str, Any]) -> Dict[str, Any]
- Purpose: Analyzes corridor physical feasibility, verifies carrier GPS tracking status, assesses blind-tracking breach penalties, and flags unrealistic linehaul transit speed demands.
- Input Parameters:
prediction_payload (Dict[str, Any])— Comprehensive prediction dictionary from Engine A (dest_city,shipping_type,carrier_name,haversine_distance_km,required_transit_speed_kmh).order_data (Dict[str, Any])— Raw order feature dictionary from ERP (telematics_status).
- Output Return Type:
Dict[str, Any]— Route analysis dictionary (telematics_active,telematics_penalty_usd,telematics_notes,route_hazards,corridor_distance_km,transit_speed_kmh,destination_city,shipping_mode). - How it helps the data: Detects GPS blind-tracking breaches (levying a mandatory $200 carrier chargeback) and flags high-velocity transit hazards before legal contract adjudication begins.
Purpose: Evaluates contractual SLAs across customer tiers (Platinum, Gold, Independent), enforces receiving dock operating hours (17:00 cut-off), and rigorously tests Force Majeure criteria against the statutory 12-hour proactive notification mandate.
1. adjudicate_contract(self, prediction_payload: Dict[str, Any], order_data: Dict[str, Any], route_analysis: Dict[str, Any], notice_given_12h: bool = True) -> Dict[str, Any]
-
Purpose: Evaluates customer contract terms, verifies Force Majeure eligibility (requiring verified Act of God telemetry, active GPS telematics, and
$\ge 12\text{h}$ proactive notice), calculates tiered late delivery penalties, and determines carrier chargeback liability. -
Input Parameters:
-
prediction_payload (Dict[str, Any])— Engine A inference dictionary (customer_tier,order_value_usd,delay_hours,will_be_delayed,predicted_eta,root_causes). -
order_data (Dict[str, Any])— Receiving dock closing time (close_time). -
route_analysis (Dict[str, Any])— Telematics and route hazards fromRouteSupervisorAgent. -
notice_given_12h (bool)— Boolean flag indicating whether a proactive early warning was issued$\ge 12\text{h}$ before delivery.
-
-
Output Return Type:
Dict[str, Any]— Adjudication dictionary (customer_tier,force_majeure_status,force_majeure_waived,sla_delay_penalty_usd,after_hours_violation,after_hours_redelivery_fee_usd,total_carrier_chargeback_usd,penalty_clauses). - How it helps the data: Establishes exact, contractually grounded dollar liabilities, waiving penalties when statutory Force Majeure applies or passing liabilities through to carriers via debit memos.
Purpose: Evaluates pharmaceutical and veterinary diet product fragility, protects against stock-out emergencies by authorizing replacement air freight, flags shelf-life expiration risks, and enforces governance approval thresholds.
1. plan_mitigation(self, prediction_payload: Dict[str, Any], order_data: Dict[str, Any], contract_analysis: Dict[str, Any]) -> Dict[str, Any]
-
Purpose: Formulates corrective action plans for distressed shipments. Authorizes
$1,000 emergency Air Freight replacement pallets for prescription diets delayed $ >48\text{h}$, mandates SAP QA Quarantine Holds (LIFSK = '01') for short-dated products ($<6\text{ months}$ ) or extreme heatwaves ($>40^\circ\text{C}$ ), and routes actions exceeding $500 to the Regional Logistics Director via MS Teams. -
Input Parameters:
-
prediction_payload (Dict[str, Any])— Engine A risk payload (has_specialty_diet,delay_hours,will_be_delayed,root_causes). -
order_data (Dict[str, Any])— Material attributes (min_shelf_life,material_description). -
contract_analysis (Dict[str, Any])— Financial liability dictionary fromContractAdjudicatorAgent.
-
-
Output Return Type:
Dict[str, Any]— Mitigation payload (has_specialty_diet,material_description,mitigation_actions,total_mitigation_cost_usd,qa_hold_required,qa_hold_reasons,approval_status,approval_gate,ms_teams_escalation_card). - How it helps the data: Prevents patient-critical veterinary therapy stock-outs and enforces enterprise financial governance before costs are incurred.
Purpose: Multi-provider LLM legal synthesis core. Merges mathematical predictions, retrieved RAG contract clauses, and specialist findings into a cohesive, legally binding executive decision brief.
- Purpose: Initializes LLM provider bridge, detecting available runtime environments in priority order: Databricks Foundation Model Serving (
databricks-meta-llama-3-70b-instruct), Google Gemini API (gemini-1.5-pro), OpenAI API (gpt-4o), Local Ollama (qwen2.5:7b), or Deterministic Local Expert fallback. - Input Parameters: None (Inspects environment variables
DATABRICKS_HOST,GEMINI_API_KEY,OPENAI_API_KEY,OLLAMA_HOST). - Output Return Type: None.
- How it helps the data: Ensures 100% continuous decision synthesis across cloud enterprise clusters, local offline developer laptops, and air-gapped server environments.
2. build_synthesis_prompt(self, order_id: str, customer_name: str, customer_tier: str, carrier_name: str, shipping_type: str, delay_prob: float, will_delay: bool, delay_hours: float, predicted_eta: str, route_analysis: Dict[str, Any], contract_analysis: Dict[str, Any], quality_analysis: Dict[str, Any], rag_citations: List[str]) -> str
- Purpose: Constructs an authoritative multi-section legal-operations prompt assembling SAP master data, Engine A ML delay predictions, Engine B retrieved contract clauses, and specialist agent determinations.
- Input Parameters:
order_id (str),customer_name (str),customer_tier (str),carrier_name (str),shipping_type (str),delay_prob (float),will_delay (bool),delay_hours (float),predicted_eta (str),route_analysis (Dict),contract_analysis (Dict),quality_analysis (Dict),rag_citations (List[str]). - Output Return Type:
str— Structured synthesis prompt. - How it helps the data: Binds numerical ML predictions, discrete rule IDs, and contract clause citations into an unambiguous prompt for LLM adjudication.
3. synthesize_executive_decision(self, order_id: str, customer_name: str, customer_tier: str, carrier_name: str, shipping_type: str, delay_prob: float, will_delay: bool, delay_hours: float, predicted_eta: str, route_analysis: Dict[str, Any], contract_analysis: Dict[str, Any], quality_analysis: Dict[str, Any], rag_citations: List[str]) -> str
- Purpose: Executes LLM synthesis via configured provider (or deterministic template fallback), producing a concise, legally binding executive briefing paragraph summarizing root cause, liability assignment, and action authorizations.
- Input Parameters: All 13 master data, prediction, specialist analysis, and RAG citation arguments.
- Output Return Type:
str— Executive decision brief string. - How it helps the data: Produces human-readable, legally grounded decision summaries written directly into the executive audit log and MS Teams notifications.
File Location: d:\Progamming\O2C_AI\modules\action_execution_engine.py
Classes: SAPActionExecutor, MSTeamsDispatcher, ClinicNotificationDispatcher
Purpose: Physical and digital execution layer. Applies automated write-backs to SAP ERP tables, generates and posts Microsoft Teams Adaptive Cards (v1.4) for human director approvals, and dispatches proactive 12-hour clinic early warnings.
Purpose: Manages automated ERP write-backs to SQLite SAP tables, logging full before-and-after audit records and generating carrier accounts payable debit memos.
- Purpose: Initializes SAP executor and creates required audit logging and debit memo tables.
- Input Parameters:
db_path (Path)— SQLite database path. - Output Return Type: None.
- How it helps the data: Prepares the relational tables required to store automated enterprise write-backs.
- Purpose: Opens a thread-safe connection with
sqlite3.Rowfactory. - Input Parameters: None.
- Output Return Type:
sqlite3.Connection. - How it helps the data: Provides low-overhead transactional access to local database tables.
- Purpose: Executes SQL DDL scripts creating
sap_action_audit_log(tracking Order ID, Action Type, Table, Field, Previous Value, New Value, Reason, Timestamp) andcarrier_debit_memos(tracking Carrier, Amount USD, Penalty Reason, Status). - Input Parameters: None.
- Output Return Type: None.
- How it helps the data: Establishes immutable tables for ERP compliance audits and carrier billing reconciliations.
4. execute_sap_writebacks(self, order_id: str, predicted_eta: str, qa_hold_required: bool, qa_reasons: List[str], carrier_chargeback_usd: float, carrier_name: str, penalty_clauses: List[str]) -> List[Dict[str, Any]]
- Purpose: Applies simulated SAP ERP transactional write-backs:
- QA Quarantine Delivery Block: Updates
SAP_VBAK.LIFSK = '01'if cargo requires inspection. - Promise Date Synchronization: Updates
SAP_VBAK.VDATUto the ML predicted ETA date. - Carrier Accounts Payable Debit Memo: Posts financial penalty to
carrier_debit_memosand logs debit record inSAP_BKPF.DMBTR.
- QA Quarantine Delivery Block: Updates
- Input Parameters:
order_id (str),predicted_eta (str),qa_hold_required (bool),qa_reasons (List[str]),carrier_chargeback_usd (float),carrier_name (str),penalty_clauses (List[str]). - Output Return Type:
List[Dict[str, Any]]— List of executed action confirmation dictionaries. - How it helps the data: Closes the loop from AI prediction to enterprise operational reality by updating ERP records and financial ledgers.
Purpose: Formats and transmits Microsoft Teams Adaptive Cards (v1.4) with interactive action buttons (Approve Expense, Reject & Hold) for human director oversight.
- Purpose: Initializes Teams dispatcher, resolves webhook URL from environment variables, and creates local persistence directory (
india_monitor_data/reports/ms_teams_cards/). - Input Parameters:
webhook_url (str | None). - Output Return Type: None.
- How it helps the data: Sets up the communication channel to enterprise collaboration platforms.
- Purpose: Generates schema-compliant Microsoft Adaptive Card JSON (v1.4) containing attention header, FactSet table (Sales Order, Clinic, Carrier, Cost, Urgency), action description, and two interactive
Action.Submitbuttons (Approve Expense/Reject & Hold). - Input Parameters:
escalation_data (Dict[str, Any])— Escalation card details fromQualityMitigationAgent. - Output Return Type:
Dict[str, Any]— Complete Adaptive Card JSON schema dictionary. - How it helps the data: Formats machine decisions into intuitive visual cards for executive decision-makers.
- Purpose: Persists Adaptive Card JSON to disk (
teams_card_order_{order_id}.json) and transmits payload to Microsoft Teams incoming webhook via HTTP POST (if configured). - Input Parameters:
escalation_data (Dict[str, Any]). - Output Return Type:
Dict[str, Any]—{"card_file", "dispatch_status", "card_payload"}. - How it helps the data: Guarantees that every high-value escalation is permanently recorded as an inspectable JSON artifact and transmitted to human managers.
Purpose: Dispatches automated early warnings to destination clinics
- Purpose: Initializes clinic notification dispatcher and ensures
clinic_early_warningstable exists. - Input Parameters:
db_path (Path). - Output Return Type: None.
- How it helps the data: Connects the notification dispatcher to the central SQLite database.
- Purpose: Executes SQL DDL creating
clinic_early_warningstable (Notice ID, Order ID, Clinic Name, Destination City, Predicted ETA, Delay Reason, Force Majeure Compliant, Sent At). - Input Parameters: None.
- Output Return Type: None.
- How it helps the data: Establishes an immutable record of external customer communications.
3. send_proactive_12h_notice(self, order_id: str, clinic_name: str, dest_city: str, predicted_eta: str, delay_reasons: List[str]) -> Dict[str, Any]
- Purpose: Formulates proactive customer notification text, inserts record into
clinic_early_warningstable, and returns dispatch confirmation withforce_majeure_compliant = True. - Input Parameters:
order_id (str),clinic_name (str),dest_city (str),predicted_eta (str),delay_reasons (List[str]). - Output Return Type:
Dict[str, Any]—{"notice_status", "force_majeure_compliant", "notice_message", "sent_at"}. - How it helps the data: Provides the legally required early-warning evidence needed by
ContractAdjudicatorAgentto waive $500/day late delivery penalties under Act of God clauses.
File Location: d:\Progamming\O2C_AI\modules\agentic_orchestrator.py
Classes: LLMSynthesizer, AgenticOrchestrator
Purpose: Master orchestration core. Controls the autonomous 6-step daily agent lifecycle, coordinates specialist reasoning across all distressed orders, commits batch predictions, generates daily executive reports, and exports clean CSV summaries.
Purpose: Bridges ML predictions and specialist agents. Sequences the execution order of RouteSupervisorAgent, ClinicNotificationDispatcher, ContractAdjudicatorAgent, QualityMitigationAgent, SAPActionExecutor, and LLMReasoningEngine.
- Purpose: Instantiates all 4 specialist agent instances, the SAP executor, the Teams dispatcher, and the clinic notifier.
- Input Parameters:
enable_teams_dispatch (bool)— Flag to enable live webhook delivery. - Output Return Type: None.
- How it helps the data: Assembles the multi-agent graph into a cohesive in-memory pipeline.
2. synthesize(self, prediction_payload: Dict[str, Any], order_data: Dict[str, Any] = None) -> Dict[str, Any]
- Purpose: Executes the end-to-end multi-agent evaluation for a single order:
- Calls
RouteSupervisorAgent.analyze_route()to verify telematics and corridor hazards. - Calls
ClinicNotificationDispatcher.send_proactive_12h_notice()to satisfy Force Majeure compliance. - Calls
ContractAdjudicatorAgent.adjudicate_contract()to calculate SLA penalties and Force Majeure status. - Calls
QualityMitigationAgent.plan_mitigation()to authorize emergency air freight and QA holds. - Calls
SAPActionExecutor.execute_sap_writebacks()to apply simulated ERP updates and AP debit memos. - Dispatches MS Teams Adaptive Card if director approval is required.
- Calls
LLMReasoningEngine.synthesize_executive_decision()to draft the executive summary. - Returns consolidated decision JSON payload.
- Calls
- Input Parameters:
prediction_payload (Dict[str, Any]),order_data (Dict[str, Any] | None). - Output Return Type:
Dict[str, Any]— Complete structured decision artifact containing customer profile, ML prediction, specialist analyses, legal adjudication, emergency actions, ERP write-backs, RAG citations, and executive brief. - How it helps the data: Merges predictions, legal rules, quality policies, and ERP write-backs into a unified, audit-proof operational record.
Purpose: Main autonomous execution driver. Executes the 6-stage daily lifecycle from real-time stream scraping through model retraining, batch inference, multi-agent synthesis, and executive report publishing.
- Purpose: Initializes database manager, weather service, news service, document generators, ML feature store extension, hybrid RAG engine, and LLM synthesizer.
- Input Parameters: None.
- Output Return Type: None.
- How it helps the data: Binds all 12 project modules into a single executable system.
2. run_daily_agent_cycle(self, date: str = None, order_limit: int = 5, target_order: str = None, all_orders: bool = False, repredict: bool = False, rebuild_rag: bool = False, enable_teams_dispatch: bool = False) -> Dict[str, Any]
- Purpose: Executes the autonomous 6-step daily agent operational lifecycle:
- Step 1: Ingests live weather telemetry and strike RSS articles into SQLite (
session_start). - Step 2: Verifies and rebuilds regulatory Word policy documents and Hybrid RAG vector index.
- Step 3: Refreshes SAP ERP feature store and trains Two-Stage Hurdle ML models (
train_models). - Step 4: Vectorized batch inference across unpredicted orders (skipping previously evaluated orders unless
repredict=True). - Step 5: Multi-agent synthesis (
LLMSynthesizer.synthesize), ERP write-backs, and Teams card generation. - Step 6: Compiles and exports
daily_agent_report_{date}.json, exports CSV snapshots, and logssession_end.
- Step 1: Ingests live weather telemetry and strike RSS articles into SQLite (
- Input Parameters:
date (str | None)— Operational target date (YYYY-MM-DD).order_limit (int)— Max orders to evaluate (default 5).target_order (str | None)— Single order ID override.all_orders (bool)— IfTrue, evaluates entire dataset.repredict (bool)— IfTrue, forces re-prediction of already evaluated orders.rebuild_rag (bool)— IfTrue, forces rebuild of FAISS and BM25 indexes.enable_teams_dispatch (bool)— IfTrue, transmits cards to live webhooks.
- Output Return Type:
Dict[str, Any]—{"status": "success", "date": today_str, "report_file": str, "decisions": List[Dict]}. - How it helps the data: Orchestrates the continuous daily transformation of raw streaming data into concrete ERP transactions and executive reports.
- Purpose: Exports daily weather readings and strike news tables from SQLite into flat CSV files (
weather_{date}.csv,strikes_{date}.csv) inindia_monitor_data/csv/. - Input Parameters:
target_date (str). - Output Return Type: None.
- How it helps the data: Provides portable tabular snapshots for external business intelligence tools (PowerBI, Tableau, Excel).
- Purpose: CLI entry point parsing command-line flags (
--date,--order,--limit,--all-orders,--repredict,--rebuild-rag,--enable-teams) and triggeringrun_daily_agent_cycle(). - Input Parameters: None (Parses
sys.argv). - Output Return Type: None.
- How it helps the data: Enables cron scheduling, Databricks job execution, and terminal CLI testing.
| Module / Component | Primary Input Data | Core Transformation / Function | Output Artifact | Downstream Consumer |
|---|---|---|---|---|
modules/agent_specialists.py (RouteSupervisor) |
Prediction payload & telematics status | GPS signal loss detection & speed feasibility check |
telematics_penalty_usd ($200) & route_hazards
|
ContractAdjudicatorAgent |
modules/action_execution_engine.py (ClinicNotifier) |
Order ID, Clinic name, City, ETA, Root causes | Generates early warning & logs timestamped record |
clinic_early_warnings table & force_majeure_compliant
|
ContractAdjudicatorAgent |
modules/agent_specialists.py (ContractAdjudicator) |
Route analysis, clinic notice flag, SLA tier | Multi-tier penalty math & Force Majeure waiver check |
sla_delay_penalty_usd, total_carrier_chargeback_usd
|
QualityMitigationAgent & SAPActionExecutor
|
modules/agent_specialists.py (QualityMitigation) |
Specialty diet flag, delay hours, shelf-life | Authorizes $1,000 Air Freight & QA holds; checks $500 approval gate |
mitigation_actions, approval_status, Teams card data |
MSTeamsDispatcher & SAPActionExecutor
|
modules/agent_specialists.py (LLMReasoning) |
Math + Rules + Master Data + RAG citations | Multi-model legal prompt construction & LLM synthesis |
executive_decision_brief string |
daily_agent_report.json |
modules/action_execution_engine.py (SAPExecutor) |
Mitigation decisions, revised ETA, chargebacks | Executes simulated SQL write-backs & audit logging |
sap_action_audit_log & carrier_debit_memos
|
SAP ERP System & Financial Ledgers |
modules/action_execution_engine.py (TeamsDispatcher) |
High-value escalation data (> $500 expense) | Schema-compliant Adaptive Card JSON generation (v1.4) | reports/ms_teams_cards/teams_card_order_*.json |
Regional Logistics Director (MS Teams) |
modules/agentic_orchestrator.py (Orchestrator) |
CLI arguments & daily schedules | 6-step autonomous operational cycle coordination | daily_agent_report_YYYY-MM-DD.json |
Executive Leadership & Operations Desks |
To see how the entire architecture functions as a unified system, follow the lifecycle of distressed Order 800000000000001 from raw ingestion to physical execution:
sequenceDiagram
autonumber
participant Ext as External Feeds (OWM / RSS)
participant P1 as Part 1: Ingestion & Generators
participant P2 as Part 2: Feature Store & RAG
participant P3_Orch as Part 3: Agentic Orchestrator
participant P3_Spec as Part 3: Specialist Agents
participant P3_Exec as Part 3: Action Execution (SAP & Teams)
Ext->>P1: Ingest 41.5°C Heatwave & Highway Strike RSS
P1->>P1: Generate Hyderabad_Weather_Protocol.docx ([RULE-W-HYD-01..04])
P1->>P2: Index 909 Chunks into FAISS & BM25
P2->>P2: MLDatabaseExtension joins 10 SAP Tables (19 Features)
P2->>P2: Two-Stage Hurdle Predicts: P(delay)=87.1%, Delay=67.0h
P2->>P2: Hybrid RAG retrieves Clause 4.2 Force Majeure & Platinum SLA
P2->>P3_Orch: Consolidated Prediction & Risk Payload
P3_Orch->>P3_Spec: RouteSupervisorAgent: GPS Active, Corridor=937 km
P3_Orch->>P3_Exec: ClinicNotificationDispatcher: Sends 12h Early Warning
P3_Orch->>P3_Spec: ContractAdjudicator: Force Majeure Granted (Act of God + 12h Notice) -> $500 Penalty Waived
P3_Orch->>P3_Spec: QualityMitigation: Specialty Diet >48h -> Authorizes $1,000 Emergency Air Freight
P3_Orch->>P3_Spec: LLMReasoningEngine: Synthesizes Authoritative Legal Brief
P3_Orch->>P3_Exec: SAPActionExecutor: VBAK-LIFSK='01' (QA Hold), VBAK-VDATU=ETA, BKPF Debit Memo
P3_Orch->>P3_Exec: MSTeamsDispatcher: Generates Adaptive Card for Logistics Director ($1,000 > $500 gate)
P3_Orch->>P3_Orch: Saves daily_agent_report_YYYY-MM-DD.json & Ends Session
- Open-Meteo detects a
$41.5^\circ\text{C}$ heatwave in Hyderabad; Google News RSS detects a truck strike along NH-44. -
WeatherPolicyGeneratorcreatesHyderabad_Weather_Protocol.docxwith[RULE-W-HYD-02](Force Majeure 72h waiver) and[RULE-W-HYD-03](HPLC assay mandate).
-
MLDatabaseExtensioncomputes 19 features: Haversine distance$= 937\text{ km}$ , weight$= 1,200\text{ kg}$ , customer tier$= \text{Platinum}$ . -
PredictiveEngine(Stage 1 Classifier) outputs$P(\text{delay}) = 87.1%$ . - Stage 2 Conditional Huber Regressor predicts
$67.0\text{ hours}$ delay. - Explainable AI (
feature_importances.json) attributes$85.2%$ risk to in-transit delay and$1.3%$ to weekend dock closure. - Hybrid RAG retrieves Platinum $500/day SLA terms and Force Majeure Section 4.2.
- Route Supervisor: Verifies GPS telematics is active (no $200 blind-tracking breach).
-
Clinic Dispatcher: Automatically records and sends a proactive early warning to the clinic
$>12\text{ hours}$ before arrival. -
Contract Adjudicator: Verifies that because heatwave
$>40^\circ\text{C}$ is documented, telematics is active, and proactive notice was given$\ge 12\text{h}$ , Force Majeure Clause 4.2 applies, completely waiving the $1,000 late delivery SLA penalty. However, because arrival ETA ($18:30$ ) violates the 17:00 dock close time, a $150 redelivery fee is charged back to the carrier. -
Quality Mitigation Planner: Detects that the shipment contains a critical prescription diet (
has_specialty_diet = 1) delayed$>48\text{h}$ . Authorizes an $1,000 emergency Air Freight replacement pallet and places the road consignment on SAP QA Quarantine Hold for laboratory vitamin potency testing. -
Action Execution:
-
SAPActionExecutorsetsSAP_VBAK.LIFSK = '01'(Delivery Block), updatesSAP_VBAK.VDATUto the revised ETA, and posts a $150.00 carrier debit memo tocarrier_debit_memos. -
MSTeamsDispatcherdetects that mitigation expense ($1,000) exceeds the $500 autonomous threshold, formatting and transmitting an interactive Adaptive Card to the Regional Logistics Director with a mandatory 2-hour response SLA.
-
-
Audit Logging: The complete consensus decision is saved in
daily_agent_report_YYYY-MM-DD.json.
| Document | Core Responsibility | Modules Covered | Primary Data Outputs |
|---|---|---|---|
| Part 1: Ingestion & Document Synthesis | External streaming sensor feeds, RSS web scrapers, and regulatory policy generators | config.pydatabase_manager.pyweather_service.pynews_service.pyweather_policy_generator.pystrike_intelligence_generator.py |
weather_readingsstrike_news23 .docx Policy Protocols ([RULE-W-*], [RULE-S-*]) |
| Part 2: Feature Store & Predictive RAG | 10-table SAP relational feature engineering, Two-Stage Hurdle ML models, and hybrid vector retrieval | ml_db_extension.pypredictive_engine.pyrag_engine.pyollama_service.py |
19-Feature Datasetrf_classifier.pkl (97.1% Acc)gb_regressor.pkl (5.6h MAE)FAISS & BM25 Indexes (909 Chunks) |
| Part 3: Agent Reasoning & Execution | Autonomous multi-agent specialists, SAP ERP write-backs, MS Teams Adaptive Cards, and daily cycle orchestration | agent_specialists.pyaction_execution_engine.pyagentic_orchestrator.py |
sap_action_audit_logcarrier_debit_memosclinic_early_warningsAdaptive Cards (v1.4) daily_agent_report.json |