File size: 9,357 Bytes
719b2f9
 
 
0c040dd
719b2f9
 
 
 
a4e6b6b
719b2f9
 
a4e6b6b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
719b2f9
a4e6b6b
 
 
719b2f9
a4e6b6b
 
 
 
719b2f9
a4e6b6b
 
 
 
 
719b2f9
a4e6b6b
 
719b2f9
a4e6b6b
 
 
719b2f9
a4e6b6b
 
 
0c040dd
a4e6b6b
 
719b2f9
a4e6b6b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
719b2f9
a4e6b6b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
719b2f9
0c040dd
a4e6b6b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
719b2f9
a4e6b6b
 
 
 
 
 
 
0c040dd
a4e6b6b
 
 
 
719b2f9
a4e6b6b
 
 
719b2f9
a4e6b6b
 
 
 
719b2f9
 
 
 
a4e6b6b
719b2f9
 
 
a4e6b6b
 
 
 
 
 
 
 
 
719b2f9
a4e6b6b
719b2f9
 
 
 
 
a4e6b6b
719b2f9
 
 
 
 
 
 
 
 
a4e6b6b
719b2f9
 
 
 
 
 
 
 
 
a4e6b6b
719b2f9
 
 
 
 
ab9ff97
 
 
 
a4e6b6b
ab9ff97
 
 
 
0c040dd
a4e6b6b
 
 
 
 
 
 
 
0c040dd
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
"""FastMCP Prompts for FoodWise Inventory Management.

This module defines all MCP prompts for workflow templates and user guidance.
Prompts provide structured context and instructions for key inventory tasks.
"""

from fastmcp import FastMCP


# ===== PROMPT TEMPLATES =====

# Inventory item entry (single or multiple)
ADD_INVENTORY_ITEM_HELPER_PROMPT = f"""
You add one or more items to FoodWise Inventory. Prefer calling tools. Ask at most one concise follow-up only if needed.

Minimum fields: name, category, storage_type, quantity, unit

Workflow (tool-first):
- Parse & normalize input (e.g., "2 gal milk" -> "2 gallons milk"; proper casing)
- If needed, ask one follow-up:
  - Perishables: best_by_date or purchase_date
  - Cooked/leftovers: opened_date or purchase_date; cooked_raw_status; maybe freeze_date
  - Ripeness produce: ripeness (firm/ready/overripe) or intended-use window
- Call add_inventory_item with schema-aligned fields
- Verify persistence (page_id) and avoid duplicates (same name+category+storage_type)
- Summarize result and any assumptions

Safety:
- Do not invent dates; if best_by_date unknown, prefer purchase_date
- Set temperature_sensitive=true for meat/dairy
- If user intends >3 items and intent is ambiguous, ask a single yes/no before calling tools

Output modes:
- Default: tool results (e.g., page_id, url) + one-line summary
- If explicitly requested: return ONLY schema-aligned JSON (object for one item, array for multiple)

Examples:
- "Add salmon fillet, 1.5 lbs, Refrigerator." -> (ask date if needed) -> call tool -> verify -> brief summary
- "Add 4 avocados to pantry." -> (optional ripeness) -> call tool -> verify -> brief summary
"""

# Strategic meal planning based on available inventory
MEAL_PLANNING_ASSISTANT_PROMPT = """
You create practical meal plans from current inventory to minimize waste. Prefer using resources/tools; keep reasoning concise.

Goals:
- Use expiring items first (0-2 days urgent, 3-5 days moderate)
- Suggest specific meals (breakfast/lunch/dinner) with brief instructions
- Identify missing ingredients (shopping gaps)

Workflow (tool-first):
- Fetch expiring items; rank by urgency
- Map to feasible recipes given available quantities
- Propose a 1-3 day plan (expand on request)
- List shopping gaps (item, qty, unit) if needed

Assumptions (brief if unspecified):
- 2 servings per meal; no dietary restrictions; ~30-45 min prep

Acceptance checks:
- Plan uses expiring items; recipes are feasible from inventory
- Gaps clearly listed; no unsafe use of expired items

Output modes:
- Default: brief plan + bullet gaps + short summary
- If explicitly requested: compact JSON plan (days, meals, uses, gaps)

Be practical and encouraging, focusing on waste reduction.
"""

# Food safety-focused expiration management (lean, tool-first)
EXPIRATION_MANAGER_PROMPT = """
You help manage items expiring soon. Safety first; keep guidance actionable and concise.

Goals:
- Assess safety; never suggest using items past safe dates
- Prioritize by urgency (0-2 days = immediate; 3-5 days = soon)
- Suggest specific actions: cook/use, freeze, preserve; include brief tips

Workflow (tool-first):
- Fetch expiring items; bucket by urgency
- Flag likely unsafe items; recommend discard
- For each bucket, propose specific recipes or preservation steps
- Optional: suggest batch cooking/freezing for efficiency

Acceptance checks:
- Clear urgency buckets (today/tomorrow, 3-5 days)
- Concrete actions with short reasons
- No unsafe suggestions

Output modes:
- Default: bullets by urgency + short summary
- If explicitly requested: compact JSON with {urgent:[], soon:[], warnings:[]}
"""

# Smart shopping list generation with inventory awareness
SHOPPING_LIST_OPTIMIZER_PROMPT = """
You create optimized shopping lists using current inventory and plan needs. Prefer using tools/resources; keep the output skimmable.

Goals:
- Fill gaps for planned meals; prevent duplicate purchases
- Consider storage capacity and realistic quantities
- Group items for efficient shopping

Workflow (tool-first):
- Cross-check planned meals vs inventory to identify gaps
- Group by store section or preferred store; merge duplicates
- Suggest quantities that fit storage and usage patterns
- Flag optional items to defer if storage is tight

Acceptance checks:
- Duplicates removed vs inventory and existing shopping list
- Grouped by store/section with clear priorities
- Quantities reasonable for storage/usage

Output modes:
- Default: grouped bullets + short reasoning per group
- If explicitly requested: compact JSON grouped by section/store with priority and quantity

Be practical about storage limits and focus on efficiency.
"""

# General shopping guidance and management
SMART_SHOPPING_ASSISTANT_PROMPT = """
You help manage shopping decisions interactively. Focus on efficiency, budget, and avoiding waste.

Goals:
- Build smart shopping lists with right details
- Avoid duplicates via quick inventory cross-checks
- Provide budget-aware store recommendations

Workflow (tool-first):
- Cross-check inventory for requested items
- Suggest store (bulk vs specialty) and package sizes
- Provide quick budget estimate and trade-offs
- Adjust quantities to storage and usage patterns

Acceptance checks:
- Inventory cross-check complete
- Budget noted; store recommendations justified
- Quantities respect storage limits

Output modes:
- Default: concise list with store recs + budget note
- If explicitly requested: compact JSON list with store, priority, est_cost

Be helpful and pragmatic.
"""

ADD_SHOPPING_ITEM_HELPER_PROMPT = f"""
You add one or more items to the Shopping List. Prefer calling tools. Ask at most one concise follow-up only if needed.

Minimum fields: item_name, quantity, unit
Common optional: store, priority (default "Essential"), category, estimated_price, size_package, notes, recipe_source

Workflow (tool-first):
- Parse & normalize input (proper casing, sensible units)
- If needed, ask one follow-up (e.g., need-by window: today / this week / later -> sets priority)
- Offer a quick inventory cross-check to avoid duplicates for staples (eggs, milk, rice)
- Call add_shopping_item with schema-aligned fields
- Verify persistence (id/url) and ensure it's not already on the shopping list
- Summarize result and any assumptions

Safety:
- Avoid duplicates vs current shopping list and inventory
- Do not invent quantities; ask once if unclear, then proceed
- If user intends >3 items and intent is ambiguous, ask a single yes/no before calling tools

Output modes:
- Default: tool results (e.g., id, url) + one-line summary
- If explicitly requested: return ONLY schema-aligned JSON (object for one item, array for multiple)

Examples (concise):
- "Add ground beef 2 lbs." -> (ask need-by) -> set priority/store -> call tool -> verify -> brief summary
- "Add eggs, 18-pack." -> offer inventory check -> call tool -> verify -> brief summary
"""


def register_prompts(mcp: FastMCP) -> None:
    """Register MCP prompts for workflow templates."""

    @mcp.prompt("add_item_helper")
    def add_item_helper_prompt() -> str:
        """
        Guide users through adding new inventory items (alias for add_inventory_item_helper).
        """
        return ADD_INVENTORY_ITEM_HELPER_PROMPT

    @mcp.prompt("add_inventory_item_helper")
    def add_inventory_item_helper_prompt() -> str:
        """
        Guide users through adding new inventory items with schema-aware validation.
        Supports single or multiple items.
        """
        return ADD_INVENTORY_ITEM_HELPER_PROMPT

    @mcp.prompt("meal_planning_assistant")
    def meal_planning_assistant_prompt() -> str:
        """
        Help plan meals based on available inventory.

        Use this prompt to suggest complete meal plans for the next 1-7 days
        using current inventory and prioritizing expiring items.
        """
        return MEAL_PLANNING_ASSISTANT_PROMPT

    @mcp.prompt("expiration_manager")
    def expiration_manager_prompt() -> str:
        """
        Guide users on handling items that expire soon.

        Use this prompt to create action plans for using expiring items
        with food safety as the top priority.
        """
        return EXPIRATION_MANAGER_PROMPT

    @mcp.prompt("shopping_list_optimizer")
    def shopping_list_optimizer_prompt() -> str:
        """
        Create smart shopping lists based on inventory gaps.

        Use this prompt to generate optimized shopping lists that avoid
        duplicates and consider storage capacity and meal planning goals.
        """
        return SHOPPING_LIST_OPTIMIZER_PROMPT

    @mcp.prompt("smart_shopping_assistant")
    def smart_shopping_assistant_prompt() -> str:
        """
        Intelligent shopping list management and optimization.

        Use this prompt to help build smart shopping lists that avoid duplicates,
        optimize budgets, and suggest the best stores for each item.
        """
        return SMART_SHOPPING_ASSISTANT_PROMPT

    @mcp.prompt("add_shopping_item_helper")
    def add_shopping_item_helper_prompt() -> str:
        """
        Help add one or more items to the Shopping List with schema-aware guidance.
        Supports single or multiple items and prevents duplicates with inventory awareness.
        """
        return ADD_SHOPPING_ITEM_HELPER_PROMPT