Fulfillment Agent
Automated order processing, shipping, and delivery tracking.
Overview
The Fulfillment Agent handles everything that happens after a purchase: order processing, carrier selection, label generation, tracking updates, and return handling. It integrates with ShipStation, EasyPost, or Shippo for carrier connectivity.
The Fulfillment Agent operates on events from the Negotiator Agent. When an order is completed, it automatically kicks off the fulfillment process.
Capabilities
FULFILLMENT AGENT CAPABILITIES ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ EVENT HANDLERS: order.completed Process new orders order.cancelled Handle cancellations shipment.created Track shipment creation shipment.delivered Handle delivery confirmation return.requested Process return requests FEATURES: ✓ Carrier selection Rate shopping across providers ✓ Label generation Automatic shipping labels ✓ Tracking updates Real-time shipment tracking ✓ Inventory updates Sync inventory on ship/receive ✓ Return processing Handle returns and refunds ✓ Split shipments Multiple packages per order INTEGRATIONS: • ShipStation / EasyPost / Shippo • Cloud Spanner (inventory) • Firestore (order state) • Pub/Sub (event coordination)
Deployment
Deploy the Fulfillment Agent:
bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# Deploy reference fulfillment agent$ hyperfold agent deploy --type=fulfillment --name="fulfillment-01" > [Build] Using reference implementation...> [Config] Loading shipping rules...> [Deploy] Creating Cloud Run service...> [Events] Subscribing to order events... ✓ Fulfillment agent deployed! Name: fulfillment-01 Subscriptions: order.completed, shipment.*, return.* Carriers: USPS, FedEx, UPS (via ShipStation) # Deploy with custom configuration$ hyperfold agent deploy --type=fulfillment \ --name="fulfillment-premium" \ --config=./agents/fulfillment-config.yamlOrder Flow
How orders flow through the Fulfillment Agent:
ORDER FULFILLMENT FLOW
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Negotiator Agent Fulfillment Agent ShipStation
│ │ │
│ order.completed │ │
│─────────────────────────▶│ │
│ │ [load order details] │
│ │ [check inventory] │
│ │ [select carrier] │
│ │ │
│ │ Create Shipment │
│ │─────────────────────────▶│
│ │ │
│ │ Label + Tracking │
│ │◀─────────────────────────│
│ │ │
│ │ [update inventory] │
│ │ [send tracking email] │
│ │ │
│ shipment.created │ │
│◀─────────────────────────│ │
│ │ │
[MONITORING]
│ │ │
│ │ Status: Delivered │
│ │◀─────────────────────────│
│ │ │
│ │ [confirm delivery] │
│ │ [update order status] │
│ │ │
│ order.delivered │ │
│◀─────────────────────────│ │Shipping Logic
The agent's shipping decision logic:
typescript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Fulfillment agent shipping logic @OnEvent('order.completed')async handleOrderCompleted(order: Order) { // 1. Validate order can be fulfilled const inventory = await this.checkInventory(order.items); if (!inventory.canFulfill) { await this.handleBackorder(order, inventory); return; } // 2. Determine best shipping method const shippingOptions = await this.getRates({ from: this.selectWarehouse(order), to: order.shipping_address, items: order.items, weight: order.total_weight, }); // 3. Apply shipping rules const selectedRate = this.applyShippingRules(order, shippingOptions); // 4. Create shipment const shipment = await this.createShipment({ order_id: order.id, carrier: selectedRate.carrier, service: selectedRate.service, items: order.items, }); // 5. Generate label const label = await this.generateLabel(shipment); // 6. Update inventory await this.decrementInventory(order.items); // 7. Send tracking notification await this.sendTrackingEmail(order.customer, { order_id: order.id, tracking_number: shipment.tracking_number, carrier: shipment.carrier, estimated_delivery: shipment.estimated_delivery, }); // 8. Publish event await this.events.publish('shipment.created', { order, shipment });} // Carrier selection logicselectCarrier(order: Order, rates: ShippingRate[]): ShippingRate { // Premium customers get expedited shipping if (order.customer.tier === 'platinum') { return rates.find(r => r.service.includes('Express')) || rates[0]; } // High-value orders get insured shipping if (order.total > 200) { return rates.find(r => r.insurance_included) || rates[0]; } // Default to cheapest option that meets SLA return rates .filter(r => r.estimated_days <= order.shipping_sla) .sort((a, b) => a.cost - b.cost)[0];}Configuration
Configure warehouses, carriers, and shipping rules:
yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# fulfillment-config.yamlname: fulfillment-agenttype: fulfillmentversion: "1.0" # Shipping providershipping_provider: shipstationshipstation: api_key: $SHIPSTATION_API_KEY api_secret: $SHIPSTATION_API_SECRET # Warehouse configurationwarehouses: - id: warehouse_west name: "West Coast DC" address: city: Los Angeles state: CA zip: "90001" carriers: [usps, fedex, ups] priority: 1 # Primary warehouse - id: warehouse_east name: "East Coast DC" address: city: Newark state: NJ zip: "07102" carriers: [usps, fedex, ups] priority: 2 # Shipping rulesshipping_rules: # Free shipping threshold - name: free_shipping condition: "order.subtotal >= 100" action: free_shipping: true method: "standard" # Premium customer expedited - name: premium_expedited condition: "customer.tier in ['gold', 'platinum']" action: upgrade_to: "express" cost_to_customer: 0 # Heavy items - name: heavy_freight condition: "order.total_weight > 70" action: carrier: "freight" method: "ltl" # Regional optimization - name: west_coast_usps condition: "shipping.state in ['CA', 'OR', 'WA', 'NV', 'AZ']" action: preferred_carrier: "usps" warehouse: "warehouse_west" # Notification settingsnotifications: send_tracking: true send_delivery: true send_delay_alert: true delay_threshold_hours: 24 # Return policyreturns: window_days: 30 free_return_shipping: true restocking_fee_percent: 0 auto_approve_under: 100See Recommender Agent for post-purchase recommendations.