from smolagents import CodeAgent, tool, ApiModel # --- Tool --- @tool def suggest_activity(mood: str) -> str: """ Suggest an activity based on the user's mood. Args: mood (str): The detected mood of the user. Returns: str: A helpful activity suggestion. """ mood = mood.lower() if mood == "bored": return "Try a quick 5-minute coding challenge." elif mood == "sad": return "Go for a short walk or listen to music." elif mood == "stressed": return "Take a 5-minute break and breathe deeply." elif mood == "happy": return "Use this energy to work on something exciting!" else: return "Try something small and productive." # --- Model --- llm = ApiModel("meta-llama/Llama-3-8b-Instruct") # --- Agent --- agent = CodeAgent( tools=[suggest_activity], model=llm ) # --- Mood detection --- def detect_mood(text): text = text.lower() if "sad" in text: return "sad" elif "bored" in text: return "bored" elif "stress" in text or "tired" in text: return "stressed" elif "happy" in text: return "happy" else: return "neutral" # --- Response --- def respond(message, personality): mood = detect_mood(message) prompt = f""" Personality: {personality} Mood: {mood} User: {message} Give a short helpful response and suggest one activity. """ return agent.run(prompt)