Get startedGet started for free

Writing Code Through Prompts: Compound Interest

You're setting aside a fixed amount of money each month into a savings account that earns interest.

Rather than calculating compound interest manually or in a spreadsheet, you decide to use an agent to write the code for you and answer your queries.

Note: For all exercises in this course, a model variable has already been initialized for you. It provides access to an OpenAI model behind the scenes. No setup or API keys required.

This exercise is part of the course

AI Agents with Hugging Face smolagents

View Course

Exercise instructions

  • Import the CodeAgent class from the smolagents library.
  • Create an instance of CodeAgent, passing it an empty list for tools.
  • Call the .run() method on your agent and pass in your task string.

Hands-on interactive exercise

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

# Import the CodeAgent class
from smolagents import ____

# Create a basic agent without tools
agent = CodeAgent(tools=____, model=model)

task = "I deposit $100 every month into an account that pays 5% annual interest, compounded monthly. Calculate the total balance after 10 years."

# Run the agent
result = agent.____(task)
print(result)
Edit and Run Code