Smarty is SmartEat AIβs intelligent nutritional assistant, powered by LangChain and LangGraph. Smarty helps users manage their meal plans, swap recipes, and get personalized dietary advice through natural conversation.
Smarty uses Ollama with the Llama 3.1 model for local, private AI inference without external API dependencies.
# Configuration for 8GB VRAMMAX_CONTEXT_TOKENS = 10000TOOL_RESULT_MAX_LENGTH = 10000class ConversationMemory: @staticmethod def compress_tool_results(messages: List[BaseMessage]): # Truncate long tool results for msg in messages: if hasattr(msg, 'type') and msg.type == 'tool': if len(content) > TOOL_RESULT_MAX_LENGTH: truncated = content[:TOOL_RESULT_MAX_LENGTH - 100] + "\n\n[...truncated...]\n\n" + content[-100:] @staticmethod def extract_essential_context(messages, max_tokens): # Keep last 6 messages (3 conversation turns) essential = messages[-6:] # Add older messages if space allows return essential
File: backend/app/services/agent/prompts.pySystem prompt with user context:
def get_nutritionist_prompt(profile: ProfileResponse) -> str: return f""" You are Smarty, an expert Nutritionist Assistant. You only answer in English. ## FUNDAMENTAL RULES 1. ALWAYS use a tool to respond (except greetings) 2. NEVER ask the user for IDs 3. Carefully read each tool's description ## USER CONTEXT - Daily meals: {profile.meals_per_day} - Distribution: {meal_context} ## BEHAVIOR - Be concise but clear - Number alternatives clearly (1, 2, 3) - Remember context when suggesting swaps """
Returns 3 nutritionally similar but lower-calorie options.
3
Present Options
Smarty shows:
Here are 3 lighter lunch alternatives for Wednesday:1. Grilled Chicken Salad (320 cal)2. Quinoa Buddha Bowl (350 cal)3. Turkey Wrap (280 cal)Which would you like?
4
User Chooses
User replies: βOption 2β
5
Call replace_meal_in_plan
replace_meal_in_plan( user_id=123, day_of_week=3, meal_type="lunch", new_recipe_name="Quinoa Buddha Bowl")
User: Hi!Smarty: Hello! I'm Smarty, your nutritional assistant. I can help you:- Generate personalized meal plans- Swap meals in your plan- Search for recipes- Update your dietary preferencesWhat would you like to do today?
User: I don't like the breakfast for tomorrowSmarty: [calls get_current_plan_summary] [calls suggest_recipe_alternatives] Your current breakfast for Thursday is "Oatmeal with Berries". Here are 3 alternatives: 1. Greek Yogurt Parfait (250 cal) 2. Avocado Toast (320 cal) 3. Smoothie Bowl (280 cal) Which one would you prefer?User: Number 3Smarty: [calls replace_meal_in_plan] β Done! I've updated your Thursday breakfast to "Smoothie Bowl". Enjoy!