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.
Questo esercizio fa parte del corso
AI Agents with Hugging Face smolagents
Istruzioni dell'esercizio
- Import the
CodeAgentclass from thesmolagentslibrary. - 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.
Esercizio pratico interattivo
Prova a risolvere questo esercizio completando il codice di esempio.
# 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)