An Agent Fabric broker, written in Agent Script, watches tracking for every outbound and inbound test kit, catches anomalies — stuck in transit, temperature excursion, delivery exception — and drives resolution with the carrier or patient. The agent reasons over the ambiguous case; Agent Script codifies the fixed rules and hand-offs so every action runs through the same trusted Action Layer APIs.
Tags: life-sciences, medtech, agent-fabric, agent-script, broker, agent-orchestration, cold-chain, supply-chain, event-driven
Automated Shipment Anomaly Detection: Agent Fabric Broker
Objective: Turn shipment tracking from a report you read after a kit is lost into an agent that acts while the kit is still recoverable. An Agent Fabric broker monitors tracking for all outbound and inbound test kits, detects anomalies — stuck in transit, temperature excursion, delivery exception — and proactively initiates resolution with the carrier or the patient. Agent Script gives the broker guided determinism: fixed rules and hand-offs a validation owner can read, with the LLM reasoning only over the cases the rules leave open, and every side effect flowing through the same governed Action Layer APIs.
What's Getting Built
- Shipment Anomaly Broker (Agent Script) — the broker tracks events, classifies each against the codified rules, and calls the Action Layer tools to resolve — reasoning over ambiguous cases and handing off to a human where the script says so ·
SUBSCRIBE tracking.event, CLASSIFY anomaly, DECIDE resolve|escalate, INVOKE tool
- biz-crm-shipment-tracking-int-new (App API) — the broker's eyes: normalizes carrier tracking for every outbound and inbound kit into one shipment status the agent monitors ·
GET /shipments/{id}/tracking, SUBSCRIBE /events, GET /shipments?state=in-transit
- ResolveShipmentIssue-process-api (Process API) — the deterministic resolution the agent triggers once it has decided: opens the carrier action, notifies the patient, and records the disposition ·
POST /resolve, GET /resolution/{id}, POST /notify/patient
- so2c-logistics-system-api (System API) — system of record for the logistics/order-to-cash view — confirms the kit, lane, and expected transit the agent judges an anomaly against ·
GET /orders/{id}, GET /kits/{id}, GET /lanes/{id}/sla
- biz-crm-pier-bridge-int (App API) — bridge into the CRM/PIER surface so the resolution and its status are visible to the service teams working the patient relationship ·
POST /cases, PATCH /cases/{id}, GET /patient/{id}/contact
- biz-crm-problemcase-consumer (Event consumer) — consumes problem-case events so a human-worked case and the agent stay in sync — the agent stands down when a person takes the case, and picks back up when it returns ·
CONSUME problemcase.opened, CONSUME problemcase.closed
Value chain phase
Phase 05 — Supply Chain & Logistics. Distribution, secure cold-chain tracking, and warehouse management.
- Scope of this plan: Proactive monitoring of test-kit shipments, anomaly detection and classification, and agent-driven resolution with carriers and patients through the Action Layer.
- Data in this phase: ERP systems, real-time freight-tracking data, and partner EDI feeds.
- Receives from: Phase 04 — Manufacturing & QC.
- Hands off to: Phase 06 — Commercial & Patient Services.
Prerequisites
- Anypoint Platform org with API Manager and a non-production deployment target.
- Secrets Manager or secure properties configured for every regulated system credential.
- Named validation owner — GxP flows need a change-control path agreed before the first deployment.
- Agent Fabric broker runtime with Agent Script enabled — the codified rules and hand-offs the LLM reasons within.
- Action Layer APIs published and governed in API Manager: biz-crm-shipment-tracking-int-new, ResolveShipmentIssue-process-api, so2c-logistics-system-api, biz-crm-pier-bridge-int, and biz-crm-problemcase-consumer.
- Anomaly thresholds agreed with quality and logistics — dwell time per lane, temperature limits per kit type from stability data, and the delivery-exception codes that warrant action.
- Patient and carrier contact channels with consent and quiet-hours rules the agent must honour before it reaches out.
Choose your path
- Broker-led, fully automated — Choose for the anomaly classes the rules resolve unambiguously — a clear in-transit stall or a confirmed excursion with a defined disposition — where the agent invokes ResolveShipmentIssue-process-api without a human gate.
- Broker-led with hand-off — Choose for ambiguous or high-consequence cases — reaching a patient, disputing a carrier charge, or a quarantine call — where Agent Script hands off to a problem case and the agent resumes only after the human decision returns.
Platform notes
Agent Script and the broker
- Agent Script is where the fixed rules and hand-offs live — the part a validation owner reads and change-controls. The LLM reasons within those rules; it does not invent new actions.
- Every side effect is a call to a governed Action Layer API, never a direct write. The tools are the same ones a human or another flow would use, so the agent inherits their auth, rate limits, and audit.
- Keep the anomaly rules as data — dwell thresholds, temperature limits, exception codes — so tuning a lane is configuration, not a script change on a validated flow.
Tracking and logistics sources
- biz-crm-shipment-tracking-int-new normalizes carriers into one status vocabulary; the agent should never branch on a raw carrier code.
- so2c-logistics-system-api holds the expected transit and lane SLA the agent judges against — an anomaly is a deviation from that record, not an absolute.
CRM and case surfaces
- biz-crm-pier-bridge-int makes the agent's work visible to service teams; a resolution the agent drives should read the same as one a person drives.
- biz-crm-problemcase-consumer is the coordination point — treat the human case as authoritative while it is open so the agent and the person never act on the same shipment at once.
Architecture
1. Business requirements
- Monitor tracking for every outbound and inbound test kit continuously, not on a batch or a report cadence.
- Detect anomalies early enough to act — a stall while the kit can still be rerouted, an excursion before the sample is compromised, an exception before a redelivery window closes.
- Resolve automatically where the rules are unambiguous, and hand off to a person where they are not, without dropping the shipment on the floor between the two.
- Reduce sample loss and improve the patient and provider experience by closing the loop proactively rather than after a complaint.
2. Proactive monitoring
- Subscribe to normalized tracking events from biz-crm-shipment-tracking-int-new for both outbound and inbound legs.
- Pull expected transit and lane SLA from so2c-logistics-system-api so every shipment is judged against its own commitment, not a global rule.
- Track dwell time per lane and time-out-of-range per kit type, accumulating rather than only reacting to a single breach.
- Treat a silent tracker or a missing scan as an anomaly requiring disposition, not as an implicit pass.
3. Anomaly detection and classification
- Classify each shipment against the Agent Script rules into stuck-in-transit, temperature excursion, delivery exception, or clear — with the LLM reasoning only over cases the rules leave open.
- Attach the evidence the classification rests on — the dwell, the excursion profile, the exception code — so a reviewer can see why the agent decided as it did.
- Debounce transient carrier noise so a single stale scan does not trigger an action; act on a sustained deviation.
- Record every classification, including the no-action ones, for audit and for tuning the thresholds.
4. Agent Script rules (guided determinism)
- These are the codified rules the broker evaluates first — deterministic, change-controlled, and readable by a validation owner. The LLM only reasons over the DEFAULT row, where no rule matched.
- Each rule names the condition it fires on, the deterministic action through the Action Layer, and whether it hands off to a human before or after acting.
- Thresholds (dwell multiple, minutes out of range, exception codes) are configuration per lane and kit type, not values baked into the rule.
| Rule |
Condition |
Deterministic action |
Hand-off |
stuck_in_transit |
dwellHours > lane.expectedTransitHours × 1.25 and last scan older than 12h |
INVOKE ResolveShipmentIssue-process-api → carrier trace, notifyPatient: true |
None — auto-resolve |
temp_excursion |
telemetry.minutesOutOfRange > kit.allowedMinutes for the kit's stability profile |
DISPOSITION quarantine and record the excursion profile |
Quality, after acting |
delivery_exception |
carrier exception code in the actionable set (address, refused, damaged) |
INVOKE ResolveShipmentIssue-process-api → reschedule or reship per code |
Human on the 2nd exception for one shipment |
inbound_no_return |
outbound delivered, no inbound scan within the return window |
INVOKE ResolveShipmentIssue-process-api → patient reminder within consent and quiet hours |
None — auto-resolve |
silent_tracker |
no scan or telemetry for longer than the lane's reporting interval |
raise an exception for disposition — never treat as a pass |
Logistics ops |
high_value_hold |
any anomaly on a flagged high-value or time-critical kit |
no autonomous action |
Human before acting — always |
DEFAULT |
no rule matched (ambiguous case) |
reason(LLM) → propose a resolution with evidence |
Human before acting — agent resumes on close |
5. Agent-driven resolution
- For rules-resolved anomalies, invoke ResolveShipmentIssue-process-api to open the carrier action and notify the patient, then record the disposition.
- For ambiguous or high-consequence cases, hand off through biz-crm-pier-bridge-int to a problem case and pause the agent on that shipment.
- Honour patient consent and quiet-hours before any outreach — the agent asks the contact API, it does not assume.
- Never take two conflicting actions on one shipment: the problem-case state from biz-crm-problemcase-consumer gates whether the agent or the human owns it.
6. Human hand-off and coordination
- Consume problemcase.opened to stand the agent down on a shipment a person has taken, and problemcase.closed to let it resume.
- Surface the agent's classification and evidence on the case so the person starts from what the agent already knows rather than from scratch.
- Escalate on tool exhaustion — a resolution API that keeps failing is an operations problem, not something for the agent to retry forever.
- Keep the CRM view current so service teams see the same resolution status the agent is acting on.
7. Security and GxP compliance
- Validate the integration against ISO 13485:2016 as incorporated by the FDA Quality Management System Regulation, effective 2 February 2026 — software validation and change control apply to this flow.
- Meet 21 CFR Part 11 for electronic records and signatures on every quality-relevant flow.
- Carry the UDI through every quality record the integration touches — complaint, servicing, and device history records — because inspections check that thread across systems, not within one.
- Respect the four obligations ISO 13485 does not cover: Medical Device Reporting (21 CFR 803), corrections and removals (806), device tracking (821), and UDI (830).
- Preserve audit trails no operator can edit, and retain evidence in the form an inspection under Compliance Program 7382.850 will ask for.
- Treat a mapping change on a quality-relevant flow as a controlled change under change management, never as a hotfix.
- An agent action that touches a regulated shipment is a controlled action — the Agent Script rules and their changes are change-controlled the same as any validated flow.
- A quarantine or disposition decision the agent reaches from telemetry is a quality decision — record it, and its evidence, with the rigour of a human one.
- The agent acts only through governed Action Layer APIs, so its access, rate limits, and audit trail are the platform's, not a separate ungoverned path.
For pre-built API specifications, implementation templates, and reference architecture, see the MuleSoft Accelerator for Life Sciences on Anypoint Exchange.
Sample payload — Broker anomaly classification and decision
{
"shipmentId": "SHP-2026-0098211",
"kitId": "KIT-DX-004182",
"direction": "inbound",
"lane": { "id": "LANE-US-NE-07", "expectedTransitHours": 48, "slaBreachAt": "2026-09-14T18:00:00Z" },
"observed": { "dwellHours": 63, "lastScanAt": "2026-09-12T09:20:00Z", "excursion": null },
"classification": { "type": "STUCK_IN_TRANSIT", "confidence": 0.94, "reasonedBy": "rules" },
"decision": { "action": "RESOLVE", "tool": "ResolveShipmentIssue-process-api", "notifyPatient": true, "handOff": false },
"governance": { "consentChecked": true, "quietHoursRespected": true, "decidedAt": "2026-09-13T01:12:00Z" }
}
Testing and validation
- Replay a tracking stream that stalls past the lane SLA and confirm the broker classifies STUCK_IN_TRANSIT and invokes ResolveShipmentIssue-process-api.
- Replay a temperature excursion beyond the kit's threshold and confirm the classification, the disposition, and the quality notification fire.
- Feed an ambiguous case and confirm the broker hands off to a problem case through biz-crm-pier-bridge-int rather than acting.
- Open a problemcase.opened event mid-resolution and confirm the agent stands down; close it and confirm it resumes.
- Send a resolution outside a patient's quiet hours and confirm the agent defers outreach until permitted.
- Exhaust retries on a failing resolution call and confirm the broker escalates instead of looping.
Phased rollout
Phase 1 — Connect
- Subscribe the broker to biz-crm-shipment-tracking-int-new in a non-production channel and confirm it sees both outbound and inbound legs.
- Wire so2c-logistics-system-api context and prove the agent judges anomalies against per-lane SLA, not a global rule.
Phase 2 — Map and validate
- Codify the anomaly rules and hand-offs in Agent Script and validate the classification against a labelled set of historical shipments.
- Connect ResolveShipmentIssue-process-api and biz-crm-pier-bridge-int in test, and prove the resolve and hand-off paths end to end.
Phase 3 — Production
- Enable automated resolution for the unambiguous anomaly classes first, keeping hand-off for the rest, and widen as confidence grows.
- Move classification review and threshold tuning into logistics and quality operations with defined ownership of the Agent Script rules.
Success metrics
- Anomalies detected in transit rather than at receipt or by complaint, as a share of total anomalies.
- Sample loss per thousand shipments trending down after the broker goes live.
- Mean time from anomaly to first resolution action, measured at the 95th percentile.
- Share of anomalies resolved automatically versus handed off, and the false-positive rate on the automated ones.
- Patient and provider satisfaction on shipments the broker touched, versus the pre-broker baseline.
Troubleshooting
- Broker acts on a shipment a person is already working — Likely cause: problem-case state not gating the agent, so both own the shipment at once. Fix: Gate the agent on biz-crm-problemcase-consumer — stand down on problemcase.opened, resume on close.
- Anomalies fire on transient carrier noise — Likely cause: acting on a single stale scan rather than a sustained deviation. Fix: Debounce against the lane SLA and require sustained dwell or a confirmed excursion before the agent acts.
- Patient outreach at the wrong time — Likely cause: agent assumed contact eligibility instead of checking consent and quiet hours. Fix: Query the contact API through biz-crm-pier-bridge-int before any outreach and defer when not permitted.
- Agent retries a failing resolution indefinitely — Likely cause: no escalation path on tool exhaustion in the Agent Script rules. Fix: Bound retries and hand off to operations when a resolution API keeps failing.
Deliverable: An Agent Fabric broker, written in Agent Script, that monitors tracking for all outbound and inbound test kits, classifies anomalies against codified rules with LLM reasoning on the open cases, and drives resolution through the governed Action Layer APIs — resolving the unambiguous cases automatically and handing the rest to a person, with the two kept in sync.