Pricing Tools
Calculate dynamic prices, apply discounts, and build bundles.
Overview
Pricing tools implement dynamic pricing logic that considers inventory, competition, customer loyalty, and policy constraints. They ensure your agents never price below floor while maximizing margin.
calculateDynamicPrice
Calculate optimal pricing with all context factors:
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
import { calculateDynamicPrice, getProduct } from '@hyperfold/actions-sdk'; const product = await getProduct('prod_aero_x2'); // Calculate dynamic price with full contextconst pricing = await calculateDynamicPrice(product, { // Buyer context buyerTier: 'gold', buyerHistory: { totalOrders: 12, totalSpent: 2450, avgOrderValue: 204, }, // Cart context cartValue: 180, cartItems: 1, // Inventory context inventoryLevel: 847, inventoryStatus: 'normal', // Competition competitorPrice: 165, // Time factors dayOfWeek: 'tuesday', timeOfDay: 'afternoon',}); // Returns:{ // Recommended prices floor: 92.00, // Absolute minimum (cost + min_margin) target: 162.00, // Ideal price for good margin suggested: 155.00, // What to counter-offer list: 180.00, // Original list price // Applied adjustments adjustments: [ { type: 'loyalty', description: 'Gold tier discount', amount: -18.00 }, { type: 'competitor', description: 'Beat Amazon by $10', amount: -7.00 }, ], // Metadata totalDiscount: 25.00, discountPercent: 13.9, margin: 46.4, marginDollars: 63.00, // Human-readable explanation explanation: "As a Gold member, you qualify for 10% off. " + "This price also beats Amazon by $10.",}getCompetitorPrice
Fetch competitor pricing for competitive positioning:
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
import { getCompetitorPrice } from '@hyperfold/actions-sdk'; // Get competitor price for a productconst competitorData = await getCompetitorPrice('prod_aero_x2'); // Returns:{ product_id: 'prod_aero_x2', competitors: [ { name: 'Amazon', price: 165.00, url: 'https://amazon.com/...', last_updated: '2025-12-19T14:00:00Z', in_stock: true, }, { name: 'Walmart', price: 172.00, url: 'https://walmart.com/...', last_updated: '2025-12-19T13:45:00Z', in_stock: true, }, { name: 'Target', price: 179.99, url: 'https://target.com/...', last_updated: '2025-12-19T12:30:00Z', in_stock: false, }, ], lowest_price: 165.00, lowest_competitor: 'Amazon', avg_price: 172.33,} // Get specific competitorconst amazonPrice = await getCompetitorPrice('prod_aero_x2', { competitor: 'amazon',}); // Refresh competitor prices (cache bypass)const freshPrices = await getCompetitorPrice('prod_aero_x2', { refresh: true,});Competitor prices are cached in Redis with 15-minute TTL. Use
refresh: true for real-time data when needed.applyDiscount
Apply discounts with policy validation:
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
import { applyDiscount } from '@hyperfold/actions-sdk'; // Apply percentage discountconst discounted = await applyDiscount({ product_id: 'prod_aero_x2', original_price: 180.00, discount_type: 'percentage', discount_value: 10, reason: 'Gold member discount',}); // Returns:{ original_price: 180.00, discount_amount: 18.00, final_price: 162.00, discount_percent: 10, within_policy: true, // Under max discount limit above_floor: true, // Above floor price} // Apply fixed amount discountconst fixedDiscount = await applyDiscount({ product_id: 'prod_aero_x2', original_price: 180.00, discount_type: 'fixed', discount_value: 25, reason: 'Price match request',}); // Apply with validationconst validated = await applyDiscount({ product_id: 'prod_aero_x2', original_price: 180.00, discount_type: 'percentage', discount_value: 50, // 50% off reason: 'Customer request',}); // Returns with warning:{ original_price: 180.00, discount_amount: 88.00, // Capped at floor final_price: 92.00, // Floor price discount_percent: 48.9, within_policy: false, // Exceeds max 30% above_floor: true, warning: 'Discount capped at floor price ($92.00)', requires_approval: true, // Above approval threshold}Discounts that exceed policy limits or approach floor price will be flagged. Discounts above the approval threshold require human approval.
calculateBundlePrice
Calculate pricing for product bundles:
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
import { calculateBundlePrice } from '@hyperfold/actions-sdk'; // Calculate bundle price for multiple productsconst bundle = await calculateBundlePrice({ products: [ { product_id: 'prod_aero_x2', quantity: 1 }, { product_id: 'prod_socks_wp', quantity: 2 }, { product_id: 'prod_insoles_pro', quantity: 1 }, ], buyer_tier: 'gold',}); // Returns:{ items: [ { product_id: 'prod_aero_x2', name: 'AeroRun X2 Marathon Shoe', unit_price: 180.00, quantity: 1, subtotal: 180.00, }, { product_id: 'prod_socks_wp', name: 'Waterproof Running Socks', unit_price: 18.00, quantity: 2, subtotal: 36.00, }, { product_id: 'prod_insoles_pro', name: 'Pro Performance Insoles', unit_price: 35.00, quantity: 1, subtotal: 35.00, }, ], pricing: { subtotal: 251.00, // Sum of items bundle_discount: 25.10, // 10% bundle discount loyalty_discount: 22.59, // Gold tier 10% total: 203.31, // Final price you_save: 47.69, // Total savings savings_percent: 19.0, }, margins: { combined_margin: 42.5, above_floor: true, },} // Suggest optimal bundleconst suggestions = await calculateBundlePrice({ base_product: 'prod_aero_x2', suggest_additions: true, max_suggestions: 3, target_bundle_value: 250,}); // Returns bundle suggestions based on co-purchase dataUsage in Agent
Complete example using pricing tools:
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
import { HyperfoldAgent, OnACPEvent, calculateDynamicPrice, getCompetitorPrice, applyDiscount, getProduct,} from '@hyperfold/actions-sdk'; @HyperfoldAgent({ name: 'pricing-agent', type: 'negotiator' })export class PricingAgent { @OnACPEvent('quote') async handleQuote(productId: string, offer: number, context: BuyerContext) { const product = await getProduct(productId); // Get competitor pricing for context const competitors = await getCompetitorPrice(productId); // Calculate dynamic price with all factors const pricing = await calculateDynamicPrice(product, { buyerTier: context.loyalty_tier, buyerHistory: context.purchase_history, cartValue: context.cart_value, competitorPrice: competitors.lowest_price, }); // Evaluate the buyer's offer if (offer === null) { // No offer - return our suggested price return { status: 'quote', list_price: pricing.list, offered_price: pricing.suggested, reasoning: pricing.explanation, }; } if (offer >= pricing.target) { // Great offer - accept return { status: 'accept', price: offer }; } if (offer >= pricing.floor) { // Acceptable but not ideal - counter const counter = Math.max(offer + 10, pricing.suggested); return { status: 'counter_offer', counter_price: counter, reasoning: `I can do $${counter} - that's ${pricing.discountPercent.toFixed(0)}% off and beats ${competitors.lowest_competitor}.`, }; } // Below floor - reject return { status: 'reject', reason: 'Below minimum price', hint: `Our best price is around $${Math.ceil(pricing.floor / 5) * 5}`, }; }}See CRM Tools for customer data access.