An e-commerce returns processing pipeline that handles inbound return requests end-to-end: validates against order data and return policy, inspects product condition, decides disposition, processes refunds, updates inventory, and analyzes return patterns for product quality improvement.
- Multi-agent pipeline — 6 specialized agents with distinct roles
- Decision contracts — Structured disposition decisions with condition grade and fraud score
- Fraud detection — Weighted signal scoring with configurable escalation threshold
- Idempotent inventory — Safe to re-run; duplicate returns are skipped automatically
- Scheduled batch processing — Daily batch runs + weekly quality analytics
- Model variety — Haiku for fast I/O tasks, Sonnet for analysis, Opus for high-stakes decisions
# 1. Start the AO daemon
ao daemon start --autonomous
# 2. Process a single return request
ao queue enqueue \
--title "Process Return RET-2026-0001" \
--description "Process return request RET-2026-0001 from data/return-requests/" \
--workflow-ref process-return
# 3. Watch it run
ao daemon stream --pretty
# 4. Check results
ls output/refunds/
ls output/inventory-adjustments/
ls output/reports/Processes a single return request end-to-end.
validate-return-request (script)
→ intake-assessment (intake-validator)
→ inspect-condition (condition-inspector)
→ decide-disposition (disposition-decider) ──rework──→ inspect-condition
│ ──fail───→ escalate-to-human
↓ advance
→ calculate-refund (refund-calculator)
→ update-inventory (script)
→ generate-return-report (pattern-analyst)
Scans all pending returns, validates in batch, processes dispositions, generates daily KPIs. Runs daily at 06:00 UTC.
Aggregates weekly return data, analyzes patterns, generates quality improvement report. Runs every Monday at 07:00 UTC.
| Agent | Model | Role |
|---|---|---|
| intake-validator | claude-haiku-4-5 | Validates requests against orders and return policy |
| condition-inspector | claude-sonnet-4-6 | Grades product condition A–F using sequential reasoning |
| disposition-decider | claude-opus-4-6 | Final disposition + fraud detection with signal scoring |
| refund-calculator | claude-haiku-4-5 | Exact refund calculation per policy rules |
| inventory-updater | claude-haiku-4-5 | Idempotent inventory adjustments by disposition |
| pattern-analyst | claude-sonnet-4-6 | Return pattern analysis and quality recommendations |
returns-processor/
├── config/
│ ├── return-policy.yaml # Return windows, restocking fees, condition grades
│ ├── refund-rules.yaml # Refund types (full/partial/store_credit/deny)
│ ├── fraud-signals.yaml # Fraud signal weights and escalation threshold
│ └── product-categories.yaml # Category-specific rules by SKU prefix
├── data/
│ ├── orders/ # Order records for validation
│ ├── return-requests/ # Pending return request JSONs
│ ├── inventory/ # Current inventory state
│ ├── inspection-notes/ # Agent-written intake and condition assessments
│ └── processed/ # Completed return records
├── output/
│ ├── refunds/ # Refund records with exact amounts
│ ├── inventory-adjustments/ # Per-return inventory change records
│ ├── reports/ # Daily KPI and weekly quality reports
│ ├── escalations/ # Fraud/ambiguous cases for human review
│ └── quality-feedback/ # Product improvement recommendations
└── scripts/
├── validate-return-request.sh
├── update-inventory.sh
└── scan-pending-returns.sh
| Grade | Meaning | Disposition |
|---|---|---|
| A | Like new, unopened | Restock (available) |
| B | Opened, fully functional, minor wear | Restock (open-box) |
| C | Functional, visible wear or missing accessories | Refurbish |
| D | Partially functional, significant damage | Dispose |
| F | Non-functional or major damage | Dispose |
The disposition-decider scores each return against weighted fraud signals:
| Signal | Weight | Trigger |
|---|---|---|
| High frequency | 0.30 | >5 returns in 90 days |
| High value | 0.25 | >$500 in returns in 90 days |
| Empty box | 0.50 | Wrong or missing item inspected |
| Condition mismatch | 0.35 | Claimed defective but functional |
| Pattern match | 0.40 | Buy-use-return on high-value electronics |
| Address mismatch | 0.15 | Return address ≠ shipping address |
Returns with a combined fraud score > 0.7 are escalated to human review.
This example uses only:
@modelcontextprotocol/server-filesystem— local file access@modelcontextprotocol/server-sequential-thinking— structured reasoning
No external API keys needed.
- Decision contracts with structured required fields (
disposition,condition_grade,fraud_score) - Phase routing with
reworkloops (re-inspect on ambiguous condition) andfailpaths (fraud escalation) - Command phases for shell-based validation, inventory updates, and batch scanning
- Scheduled workflows via cron (daily batch + weekly analytics)
- Model selection — right-sizing: Haiku for deterministic tasks, Sonnet for analysis, Opus for high-stakes judgment
- Sequential-thinking MCP for fraud signal reasoning in the disposition phase