Skip to main content

Budget Refinement System

The budget system detects, infers, and adjusts budgets through multiple methods with transparent user communication.

Budget Detection Hierarchy​

Budget Calculation Methods​

1. Explicit Budget (Direct)​

User: "Raamatuid kuni 25 euro"

Pattern Match: /kuni\s+(\d+)\s+euro/i → 25
Result: budget.max = 25

2. Range Budget​

User: "Kingitus 15-35 euro vahemikus"

Pattern Match: /(\d+)\s*[-–]\s*(\d+)\s+euro/i → [15, 35]
Result: budget.min = 15, budget.max = 35

3. Implicit Budget (Cheaper Request)​

Previous Products:
- Book A: €30
- Book B: €35
- Book C: €28

User: "odavamaid" (cheaper ones)

Calculation:
avgPrice = (30 + 35 + 28) / 3 = 31
implicitBudget = Math.floor(31 * 0.7) = 21

Result: budget.max = 21

Implementation:

if (giftContext.intent === 'cheaper_alternatives' && 
!giftContext.budget?.max &&
storedProducts.length > 0) {

const prices = storedProducts
.map(p => p.price)
.filter((price): price is number => typeof price === 'number' && price > 0);

if (prices.length > 0) {
const avgPrice = prices.reduce((sum, p) => sum + p, 0) / prices.length;

giftContext.budget = {
max: Math.floor(avgPrice * 0.7), // 30% reduction
hint: 'odavam kui eelmised'
};

console.log(' IMPLICIT BUDGET CALCULATED:', {
previousPrices: prices,
avgPrice,
implicitBudget: giftContext.budget.max
});
}
}

4. Occasion-Based Inference​

User: "Isadepäeva kingitus"

Occasion Detection: "Isadepäev" (Father's Day)
Inferred Budget: { min: 20, max: 60 }

Estonian Occasion Budgets:

OccasionEstonianBudget (€)Use Case
Father's DayIsadepäev20-60Parent gift
Mother's DayEmadepäev20-60Parent gift
BirthdaySünnipäev20-50General
ChristmasJõulud25-80Holiday gift
MidsummerJaanipäev15-40Casual gift

Budget Adjustment​

Cheaper refinement:

// User requests cheaper alternatives
if (signals.cheaperRequested && giftContext.budget?.max) {
const originalMax = giftContext.budget.max;
giftContext.budget.max = Math.floor(giftContext.budget.max * 0.7);

console.log(' BUDGET REDUCED:', {
originalMax,
newMax: giftContext.budget.max,
reductionPercent: 30
});
}

Example:

Turn 1: "Raamatuid kuni 50 euro"
budget.max = 50

Turn 2: "Midagi odavamat" (something cheaper)
budget.max = 50 * 0.7 = 35

Budget Chain Example​

Turn 1: "Raamatuid sünnipäevaks"
Context: { productType: "Raamat", occasion: "sünnipäev" }
Inferred Budget: {min: 20, max: 50}
Response: [Book A (€45), Book B (€38), Book C (€42)]

Turn 2: "Kuni 30 euro"
Detected: budget.max = 30
Preserved: productType, occasion
Response: [Book D (€28), Book E (€25), Book F (€29)]

Turn 3: "Veelgi odavamaid"
Detected: cheaperRequested = true
Calculated: 30 * 0.7 = 21
Response: [Book G (€18), Book H (€15), Book I (€20)]

Turn 4: "Vahemikus 15-25 euro"
Detected: budget = {min: 15, max: 25}
Preserved: productType, occasion
Response: [Book H (€15), Book I (€20), Book J (€23)]