Get startedGet started for free

Let the Agent Do the Math: Expense Insights

You've been manually tracking your monthly expenses in a spreadsheet, but analyzing spending patterns takes forever.

Your friend recommended trying smolagents to automate the analysis. Your weekly expense data for the past month is given in the following expense_data dictionary:

expense_data = {
    "groceries": [120, 95, 110, 140],
    "utilities": [85, 92, 78, 88],
    "entertainment": [45, 0, 75, 30],
    "transportation": [60, 55, 70, 65]
}

Let's run an agent that can help you understand your spending habits and create a budget plan.

Note: The agent and expense_data dictionary have been already initialized for you.

This exercise is part of the course

AI Agents with Hugging Face smolagents

View Course

Exercise instructions

  • Run the provided code to see smolagents analyze your expense data.
  • Observe the output and how the agent writes Python code to find spending patterns.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Task for the agent
task = f"""Analyze my monthly expense data by category. Calculate total spending per category, find my highest expense area, and suggest a realistic budget for next month. Use simple text format in your final answer. Here is my weekly expense data for the past four weeks:

{expense_data}
"""

# Execute the financial analysis
result = agent.run(task)

print("Personal finance analysis:\n")
print(result)
Edit and Run Code